Skip to content

Commit

Permalink
Remove redundant null terminate (#1151)
Browse files Browse the repository at this point in the history
* Remove redundant null terminate

* Null terminate with size check
  • Loading branch information
FabrizioSandri authored Dec 13, 2021
1 parent f5f4a33 commit 0471c3d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
6 changes: 4 additions & 2 deletions Fw/Comp/ActiveComponentBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ namespace Fw {

#if FW_OBJECT_TO_STRING == 1 && FW_OBJECT_NAMES == 1
void ActiveComponentBase::toString(char* buffer, NATIVE_INT_TYPE size) {
(void)snprintf(buffer, size, "ActComp: %s", this->m_objName);
buffer[size-1] = 0;
FW_ASSERT(size > 0);
if (snprintf(buffer, size, "ActComp: %s", this->m_objName) < 0) {
buffer[0] = 0;
}
}
#endif

Expand Down
7 changes: 4 additions & 3 deletions Fw/Comp/PassiveComponentBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ namespace Fw {
#if FW_OBJECT_TO_STRING == 1 && FW_OBJECT_NAMES == 1
void PassiveComponentBase::toString(char* buffer, NATIVE_INT_TYPE size) {
FW_ASSERT(buffer);
(void)snprintf(buffer, size, "Comp: %s", this->m_objName);
// null terminate
buffer[size-1] = 0;
FW_ASSERT(size > 0);
if (snprintf(buffer, size, "Comp: %s", this->m_objName) < 0) {
buffer[0] = 0;
}
}
#endif

Expand Down
6 changes: 4 additions & 2 deletions Fw/Comp/QueuedComponentBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ namespace Fw {

#if FW_OBJECT_TO_STRING == 1 && FW_OBJECT_NAMES == 1
void QueuedComponentBase::toString(char* buffer, NATIVE_INT_TYPE size) {
(void)snprintf(buffer, size,"QueueComp: %s", this->m_objName);
buffer[size-1] = 0;
FW_ASSERT(size > 0);
if (snprintf(buffer, size,"QueueComp: %s", this->m_objName) < 0) {
buffer[0] = 0;
}
}
#endif

Expand Down

0 comments on commit 0471c3d

Please sign in to comment.