From 75f3c04472897cda6d415276f23d29b158dd496b Mon Sep 17 00:00:00 2001 From: thomas-bc Date: Fri, 1 Mar 2024 10:20:03 -0800 Subject: [PATCH] Fix static code analysis warnings --- Fw/Comp/ActiveComponentBase.cpp | 3 ++- Fw/Comp/PassiveComponentBase.cpp | 3 ++- Fw/Comp/QueuedComponentBase.cpp | 3 ++- Fw/Obj/ObjBase.cpp | 3 ++- Fw/Port/InputPortBase.cpp | 5 +++-- Fw/Types/StringUtils.cpp | 2 ++ 6 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Fw/Comp/ActiveComponentBase.cpp b/Fw/Comp/ActiveComponentBase.cpp index 02c9e22675..98a80e6f7d 100644 --- a/Fw/Comp/ActiveComponentBase.cpp +++ b/Fw/Comp/ActiveComponentBase.cpp @@ -45,7 +45,8 @@ namespace Fw { #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.toChar()) < 0) { + PlatformIntType status = snprintf(buffer, size, "ActComp: %s", this->m_objName.toChar()); + if (status < 0) { buffer[0] = 0; } } diff --git a/Fw/Comp/PassiveComponentBase.cpp b/Fw/Comp/PassiveComponentBase.cpp index 6c8f247483..f453dfec1a 100644 --- a/Fw/Comp/PassiveComponentBase.cpp +++ b/Fw/Comp/PassiveComponentBase.cpp @@ -13,7 +13,8 @@ namespace Fw { 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.toChar()) < 0) { + PlatformIntType status = snprintf(buffer, size, "Comp: %s", this->m_objName.toChar()); + if (status < 0) { buffer[0] = 0; } } diff --git a/Fw/Comp/QueuedComponentBase.cpp b/Fw/Comp/QueuedComponentBase.cpp index 5a37c39538..4e40c36928 100644 --- a/Fw/Comp/QueuedComponentBase.cpp +++ b/Fw/Comp/QueuedComponentBase.cpp @@ -22,7 +22,8 @@ namespace Fw { #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.toChar()) < 0) { + PlatformIntType status = snprintf(buffer, size, "QueueComp: %s", this->m_objName.toChar()); + if (status < 0) { buffer[0] = 0; } } diff --git a/Fw/Obj/ObjBase.cpp b/Fw/Obj/ObjBase.cpp index 1c52a4a93f..956341b16c 100644 --- a/Fw/Obj/ObjBase.cpp +++ b/Fw/Obj/ObjBase.cpp @@ -47,7 +47,8 @@ namespace Fw { #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.toChar()) < 0) { + PlatformIntType status = snprintf(str, size, "Obj: %s", this->m_objName.toChar()); + if (status < 0) { str[0] = 0; } } diff --git a/Fw/Port/InputPortBase.cpp b/Fw/Port/InputPortBase.cpp index efebc1c1dc..d4ef26e499 100644 --- a/Fw/Port/InputPortBase.cpp +++ b/Fw/Port/InputPortBase.cpp @@ -29,8 +29,9 @@ namespace Fw { 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.toChar(), - this->isConnected() ? this->m_connObj->getObjName() : "None") < 0) { + PlatformIntType status = snprintf(buffer, size, "InputPort: %s->%s", this->m_objName.toChar(), + this->isConnected() ? this->m_connObj->getObjName() : "None"); + if (status < 0) { buffer[0] = 0; } #else diff --git a/Fw/Types/StringUtils.cpp b/Fw/Types/StringUtils.cpp index e6de10de2c..069bce8655 100644 --- a/Fw/Types/StringUtils.cpp +++ b/Fw/Types/StringUtils.cpp @@ -7,6 +7,8 @@ char* Fw::StringUtils::string_copy(char* destination, const char* source, U32 nu if(destination == source || num == 0) { return destination; } + FW_ASSERT(source != nullptr); + FW_ASSERT(destination != nullptr); // Copying an overlapping range is undefined U32 source_len = string_length(source, num) + 1;