Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Fw::ObjectName to hold Fw::ObjBase name #2497

Merged
merged 11 commits into from
Mar 5, 2024

Conversation

thomas-bc
Copy link
Collaborator

Related Issue(s) #2493
Has Unit Tests (y/n) y
Documentation Included (y/n) n

Change Description

Implements Fw::ObjectName to hold names of ObjBase objects instead of raw char arrays.

I tried to keep the changes to a minimum, so I'm using .toChar() in most places.
Let me know if there's other patterns you think I should add here, or any other desired changes.

Associated PR to FPP: nasa/fpp#385

Rationale

See #2493

Fw/Types/ObjectName.hpp Fixed Show resolved Hide resolved
Fw/Types/ObjectName.hpp Fixed Show resolved Hide resolved
Copy link
Collaborator

@LeStarch LeStarch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few very minor style guidelines.

Fw/Types/ObjectName.hpp Outdated Show resolved Hide resolved
Fw/Types/ObjectName.hpp Fixed Show resolved Hide resolved
Fw/Types/ObjectName.hpp Fixed Show resolved Hide resolved
Fw/Types/ObjectName.hpp Outdated Show resolved Hide resolved
@bocchino
Copy link
Collaborator

bocchino commented Jan 23, 2024

This looks great! I suggest we do the following:

@thomas-bc
Copy link
Collaborator Author

Added the recommended changes.

I wanted to apply them to the other Fw::*String types to resolve the same warnings in those classes, but that broke some implicit conversions in, at least, some UTs (e.g. LoggerMain.cpp)
Didn't want to go out of scope for this PR or risk some downstream breakages so I didn't touch anything, but might be worth fixing in the future.

@bocchino
Copy link
Collaborator

I am working on integrating this PR with FPP. It's looking good so far. Here is one issue I see: FW_OBJECT_NAME_MAX_SIZE is technically not a correct name. It should be FW_OBJECT_NAME_BUFFER_SIZE or something like that. The max string length is the buffer size minus one, because of the terminating zero. Compare FW_OBJ_TO_STRING_BUFFER_SIZE, which gets this right.

@thomas-bc
Copy link
Collaborator Author

thomas-bc commented Feb 26, 2024

@bocchino this also applies to FW_QUEUE_NAME_MAX_SIZE, FW_TASK_NAME_MAX_SIZE, and probably others. Do you want me to change these in this PR, or should we capture this in a new issue and get back to it in a different PR?

@thomas-bc
Copy link
Collaborator Author

Since this is a breaking change for projects that define their own config/ folder, I would suggest we do the name changes all at once in a different PR, and keep the scope of this PR as is

@bocchino
Copy link
Collaborator

I agree, let's defer this to a separate issue.

Fw/Obj/ObjBase.cpp Dismissed Show resolved Hide resolved
Fw/Types/ObjectName.cpp Fixed Show resolved Hide resolved
Fw/Types/ObjectName.cpp Fixed Show fixed Hide fixed
Fw/Types/ObjectName.cpp Fixed Show fixed Hide fixed
Fw/Types/ObjectName.cpp Fixed Show fixed Hide fixed
Fw/Types/ObjectName.cpp Fixed Show fixed Hide fixed
Fw/Comp/PassiveComponentBase.cpp Fixed Show resolved Hide resolved
Fw/Comp/ActiveComponentBase.cpp Fixed Show resolved Hide resolved
Fw/Comp/QueuedComponentBase.cpp Fixed Show resolved Hide resolved
Fw/Obj/ObjBase.cpp Fixed Show resolved Hide resolved
Fw/Types/ObjectName.cpp Dismissed Show dismissed Hide dismissed
Fw/Types/ObjectName.hpp Dismissed Show dismissed Hide dismissed
Fw/Types/ObjectName.cpp Dismissed Show dismissed Hide dismissed
Fw/Types/ObjectName.cpp Fixed Show fixed Hide fixed
Fw/Types/ObjectName.cpp Fixed Show fixed Hide fixed
Copy link
Collaborator

@LeStarch LeStarch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the CI warnings that we shouldn't fix. You should address the rest.

With the "side effect in boolean" we should fix that by assigning to a const variable and then checking.

The others I think are mostly checking return of string_copy. It should check and null terminate if possible.

Finally nullptr checks on CHAR* pointers

Fw/Comp/ActiveComponentBase.cpp Fixed Show resolved Hide resolved
Fw/Comp/PassiveComponentBase.cpp Fixed Show resolved Hide resolved
Fw/Comp/QueuedComponentBase.cpp Fixed Show resolved Hide resolved
Fw/Obj/ObjBase.cpp Dismissed Show resolved Hide resolved
Fw/Obj/ObjBase.cpp Fixed Show resolved Hide resolved
Fw/Port/InputPortBase.cpp Outdated Show resolved Hide resolved
Fw/Types/ObjectName.cpp Outdated Show resolved Hide resolved
Fw/Types/ObjectName.cpp Outdated Show resolved Hide resolved
Fw/Comp/QueuedComponentBase.cpp Fixed Show fixed Hide fixed
Fw/Comp/ActiveComponentBase.cpp Fixed Show fixed Hide fixed
Fw/Obj/ObjBase.cpp Fixed Show fixed Hide fixed
Fw/Port/InputPortBase.cpp Fixed Show fixed Hide fixed
@@ -13,7 +13,8 @@
void PassiveComponentBase::toString(char* buffer, NATIVE_INT_TYPE size) {
FW_ASSERT(buffer);
FW_ASSERT(size > 0);
if (snprintf(buffer, size, "Comp: %s", this->m_objName) < 0) {
PlatformIntType status = snprintf(buffer, size, "Comp: %s", this->m_objName.toChar());

Check notice

Code scanning / CodeQL

Use of basic integral type Note

status uses the basic integral type int rather than a typedef with size and signedness.
@@ -22,7 +22,8 @@
#if FW_OBJECT_TO_STRING == 1 && FW_OBJECT_NAMES == 1
void QueuedComponentBase::toString(char* buffer, NATIVE_INT_TYPE size) {
FW_ASSERT(size > 0);
if (snprintf(buffer, size,"QueueComp: %s", this->m_objName) < 0) {
PlatformIntType status = snprintf(buffer, size, "QueueComp: %s", this->m_objName.toChar());

Check notice

Code scanning / CodeQL

Use of basic integral type Note

status uses the basic integral type int rather than a typedef with size and signedness.
@@ -45,7 +45,8 @@
#if FW_OBJECT_TO_STRING == 1 && FW_OBJECT_NAMES == 1
void ActiveComponentBase::toString(char* buffer, NATIVE_INT_TYPE size) {
FW_ASSERT(size > 0);
if (snprintf(buffer, size, "ActComp: %s", this->m_objName) < 0) {
PlatformIntType status = snprintf(buffer, size, "ActComp: %s", this->m_objName.toChar());

Check notice

Code scanning / CodeQL

Use of basic integral type Note

status uses the basic integral type int rather than a typedef with size and signedness.
@@ -29,8 +29,9 @@
void InputPortBase::toString(char* buffer, NATIVE_INT_TYPE size) {
#if FW_OBJECT_NAMES == 1
FW_ASSERT(size > 0);
if (snprintf(buffer, size, "InputPort: %s->%s", this->m_objName,
this->isConnected() ? this->m_connObj->getObjName() : "None") < 0) {
PlatformIntType status = snprintf(buffer, size, "InputPort: %s->%s", this->m_objName.toChar(),

Check notice

Code scanning / CodeQL

Use of basic integral type Note

status uses the basic integral type int rather than a typedef with size and signedness.
}
#if FW_OBJECT_TO_STRING == 1
void ObjBase::toString(char* str, NATIVE_INT_TYPE size) {
FW_ASSERT(size > 0);
if (snprintf(str, size, "Obj: %s",this->m_objName) < 0) {
PlatformIntType status = snprintf(str, size, "Obj: %s", this->m_objName.toChar());

Check notice

Code scanning / CodeQL

Use of basic integral type Note

status uses the basic integral type int rather than a typedef with size and signedness.
Fw/Types/ObjectName.cpp Dismissed Show resolved Hide resolved
Fw/Types/ObjectName.cpp Dismissed Show dismissed Hide dismissed
Fw/Types/ObjectName.cpp Dismissed Show dismissed Hide dismissed
Fw/Types/ObjectName.cpp Dismissed Show dismissed Hide dismissed
Fw/Types/ObjectName.cpp Dismissed Show dismissed Hide dismissed
Fw/Types/ObjectName.cpp Dismissed Show dismissed Hide dismissed
@LeStarch LeStarch merged commit bdfe241 into nasa:devel Mar 5, 2024
44 checks passed
@thomas-bc thomas-bc added the Update Instructions Needed Need to add instructions in the release notes for updates. label Mar 13, 2024
@thomas-bc thomas-bc deleted the Fw-ObjectName branch June 25, 2024 18:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Update Instructions Needed Need to add instructions in the release notes for updates.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants