From 345e3ec35b1184328f4671612d13a354da0c7e2b Mon Sep 17 00:00:00 2001 From: thomas-bc Date: Mon, 22 Jan 2024 12:53:13 -0800 Subject: [PATCH 01/10] Implement Fw::ObjectName --- Fw/Cfg/SerIds.hpp | 1 + Fw/Comp/ActiveComponentBase.cpp | 2 +- Fw/Comp/PassiveComponentBase.cpp | 2 +- Fw/Comp/QueuedComponentBase.cpp | 2 +- Fw/Obj/ObjBase.cpp | 7 ++- Fw/Obj/ObjBase.hpp | 3 +- Fw/Port/InputPortBase.cpp | 2 +- Fw/Port/InputSerializePort.cpp | 2 +- Fw/Port/OutputPortBase.cpp | 2 +- Fw/Port/OutputSerializePort.cpp | 2 +- Fw/Port/PortBase.cpp | 4 +- Fw/Types/CMakeLists.txt | 1 + Fw/Types/ObjectName.cpp | 56 +++++++++++++++++++++++ Fw/Types/ObjectName.hpp | 37 +++++++++++++++ Ref/RecvBuffApp/RecvBuffComponentImpl.cpp | 2 +- Ref/SendBuffApp/SendBuffComponentImpl.cpp | 2 +- 16 files changed, 111 insertions(+), 16 deletions(-) create mode 100644 Fw/Types/ObjectName.cpp create mode 100644 Fw/Types/ObjectName.hpp diff --git a/Fw/Cfg/SerIds.hpp b/Fw/Cfg/SerIds.hpp index de1474f696..9082db658e 100644 --- a/Fw/Cfg/SerIds.hpp +++ b/Fw/Cfg/SerIds.hpp @@ -57,6 +57,7 @@ namespace Fw { FW_TYPEID_EIGHTY_CHAR_STRING = 50, //!< 80 char string Buffer type id FW_TYPEID_INTERNAL_INTERFACE_STRING = 51, //!< interface string Buffer type id FW_TYPEID_FIXED_LENGTH_STRING = 52, //!< 256 char string Buffer type id + FW_TYPEID_OBJECT_NAME = 53, //!< ObjectName string Buffer type id }; } diff --git a/Fw/Comp/ActiveComponentBase.cpp b/Fw/Comp/ActiveComponentBase.cpp index abd7631aec..02c9e22675 100644 --- a/Fw/Comp/ActiveComponentBase.cpp +++ b/Fw/Comp/ActiveComponentBase.cpp @@ -45,7 +45,7 @@ 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) < 0) { + if (snprintf(buffer, size, "ActComp: %s", this->m_objName.toChar()) < 0) { buffer[0] = 0; } } diff --git a/Fw/Comp/PassiveComponentBase.cpp b/Fw/Comp/PassiveComponentBase.cpp index 185f29da9c..6c8f247483 100644 --- a/Fw/Comp/PassiveComponentBase.cpp +++ b/Fw/Comp/PassiveComponentBase.cpp @@ -13,7 +13,7 @@ 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) < 0) { + if (snprintf(buffer, size, "Comp: %s", this->m_objName.toChar()) < 0) { buffer[0] = 0; } } diff --git a/Fw/Comp/QueuedComponentBase.cpp b/Fw/Comp/QueuedComponentBase.cpp index 5e568c686b..5a37c39538 100644 --- a/Fw/Comp/QueuedComponentBase.cpp +++ b/Fw/Comp/QueuedComponentBase.cpp @@ -22,7 +22,7 @@ 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) < 0) { + if (snprintf(buffer, size,"QueueComp: %s", this->m_objName.toChar()) < 0) { buffer[0] = 0; } } diff --git a/Fw/Obj/ObjBase.cpp b/Fw/Obj/ObjBase.cpp index 1f89740fbb..1c52a4a93f 100644 --- a/Fw/Obj/ObjBase.cpp +++ b/Fw/Obj/ObjBase.cpp @@ -38,17 +38,16 @@ namespace Fw { #if FW_OBJECT_NAMES == 1 const char* ObjBase::getObjName() { - return this->m_objName; + return this->m_objName.toChar(); } void ObjBase::setObjName(const char* name) { - strncpy(this->m_objName, name, sizeof(this->m_objName)); - this->m_objName[sizeof(this->m_objName)-1] = 0; + this->m_objName = name; } #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) { + if (snprintf(str, size, "Obj: %s",this->m_objName.toChar()) < 0) { str[0] = 0; } } diff --git a/Fw/Obj/ObjBase.hpp b/Fw/Obj/ObjBase.hpp index ac06088d83..e4d55f7669 100644 --- a/Fw/Obj/ObjBase.hpp +++ b/Fw/Obj/ObjBase.hpp @@ -14,6 +14,7 @@ #define FW_OBJ_BASE_HPP #include +#include namespace Fw { @@ -79,7 +80,7 @@ namespace Fw { protected: #if FW_OBJECT_NAMES == 1 - char m_objName[FW_OBJ_NAME_MAX_SIZE]; //!< stores object name + Fw::ObjectName m_objName; //!< stores object name #endif //! \brief ObjBase constructor diff --git a/Fw/Port/InputPortBase.cpp b/Fw/Port/InputPortBase.cpp index b82aedcf94..efebc1c1dc 100644 --- a/Fw/Port/InputPortBase.cpp +++ b/Fw/Port/InputPortBase.cpp @@ -29,7 +29,7 @@ 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, + if (snprintf(buffer, size, "InputPort: %s->%s", this->m_objName.toChar(), this->isConnected() ? this->m_connObj->getObjName() : "None") < 0) { buffer[0] = 0; } diff --git a/Fw/Port/InputSerializePort.cpp b/Fw/Port/InputSerializePort.cpp index 6201fa3857..ca2f154675 100644 --- a/Fw/Port/InputSerializePort.cpp +++ b/Fw/Port/InputSerializePort.cpp @@ -40,7 +40,7 @@ namespace Fw { void InputSerializePort::toString(char* buffer, NATIVE_INT_TYPE size) { #if FW_OBJECT_NAMES == 1 FW_ASSERT(size > 0); - if (snprintf(buffer, size, "Input Serial Port: %s %s->(%s)", this->m_objName, this->isConnected() ? "C" : "NC", + if (snprintf(buffer, size, "Input Serial Port: %s %s->(%s)", this->m_objName.toChar(), this->isConnected() ? "C" : "NC", this->isConnected() ? this->m_connObj->getObjName() : "None") < 0) { buffer[0] = 0; } diff --git a/Fw/Port/OutputPortBase.cpp b/Fw/Port/OutputPortBase.cpp index 0ac06fd3ae..4018eb2d06 100644 --- a/Fw/Port/OutputPortBase.cpp +++ b/Fw/Port/OutputPortBase.cpp @@ -38,7 +38,7 @@ namespace Fw { void OutputPortBase::toString(char* buffer, NATIVE_INT_TYPE size) { #if FW_OBJECT_NAMES == 1 FW_ASSERT(size > 0); - if (snprintf(buffer, size, "OutputPort: %s %s->(%s)", this->m_objName, this->isConnected() ? "C" : "NC", + if (snprintf(buffer, size, "OutputPort: %s %s->(%s)", this->m_objName.toChar(), this->isConnected() ? "C" : "NC", this->isConnected() ? this->m_connObj->getObjName() : "None") < 0) { buffer[0] = 0; } diff --git a/Fw/Port/OutputSerializePort.cpp b/Fw/Port/OutputSerializePort.cpp index aa825af647..477784009c 100644 --- a/Fw/Port/OutputSerializePort.cpp +++ b/Fw/Port/OutputSerializePort.cpp @@ -22,7 +22,7 @@ namespace Fw { void OutputSerializePort::toString(char* buffer, NATIVE_INT_TYPE size) { #if FW_OBJECT_NAMES == 1 FW_ASSERT(size > 0); - if (snprintf(buffer, size, "Output Serial Port: %s %s->(%s)", this->m_objName, this->isConnected() ? "C" : "NC", + if (snprintf(buffer, size, "Output Serial Port: %s %s->(%s)", this->m_objName.toChar(), this->isConnected() ? "C" : "NC", this->isConnected() ? this->m_connObj->getObjName() : "None") < 0) { buffer[0] = 0; } diff --git a/Fw/Port/PortBase.cpp b/Fw/Port/PortBase.cpp index 34b51322a2..4a13b47bc2 100644 --- a/Fw/Port/PortBase.cpp +++ b/Fw/Port/PortBase.cpp @@ -57,7 +57,7 @@ namespace Fw { if (do_trace) { #if FW_OBJECT_NAMES == 1 - Fw::Logger::logMsg("Trace: %s\n", reinterpret_cast(this->m_objName), 0, 0, 0, 0, 0); + Fw::Logger::logMsg("Trace: %s\n", reinterpret_cast(this->m_objName.toChar()), 0, 0, 0, 0, 0); #else Fw::Logger::logMsg("Trace: %p\n", reinterpret_cast(this), 0, 0, 0, 0, 0); #endif @@ -79,7 +79,7 @@ namespace Fw { #if FW_OBJECT_TO_STRING == 1 void PortBase::toString(char* buffer, NATIVE_INT_TYPE size) { FW_ASSERT(size > 0); - if (snprintf(buffer, size, "Port: %s %s->(%s)", this->m_objName, this->m_connObj ? "C" : "NC", + if (snprintf(buffer, size, "Port: %s %s->(%s)", this->m_objName.toChar(), this->m_connObj ? "C" : "NC", this->m_connObj ? this->m_connObj->getObjName() : "None") < 0) { buffer[0] = 0; } diff --git a/Fw/Types/CMakeLists.txt b/Fw/Types/CMakeLists.txt index b9105f640c..7dc88339e8 100644 --- a/Fw/Types/CMakeLists.txt +++ b/Fw/Types/CMakeLists.txt @@ -13,6 +13,7 @@ set(SOURCE_FILES "${CMAKE_CURRENT_LIST_DIR}/Types.fpp" "${CMAKE_CURRENT_LIST_DIR}/InternalInterfaceString.cpp" "${CMAKE_CURRENT_LIST_DIR}/MallocAllocator.cpp" "${CMAKE_CURRENT_LIST_DIR}/MemAllocator.cpp" + "${CMAKE_CURRENT_LIST_DIR}/ObjectName.cpp" "${CMAKE_CURRENT_LIST_DIR}/PolyType.cpp" "${CMAKE_CURRENT_LIST_DIR}/SerialBuffer.cpp" "${CMAKE_CURRENT_LIST_DIR}/Serializable.cpp" diff --git a/Fw/Types/ObjectName.cpp b/Fw/Types/ObjectName.cpp new file mode 100644 index 0000000000..8bf8c539e5 --- /dev/null +++ b/Fw/Types/ObjectName.cpp @@ -0,0 +1,56 @@ +#include +#include + +namespace Fw { + + ObjectName::ObjectName(const char* src) : StringBase() { + Fw::StringUtils::string_copy(this->m_buf, src, sizeof(this->m_buf)); + } + + ObjectName::ObjectName(const StringBase& src) : StringBase() { + Fw::StringUtils::string_copy(this->m_buf, src.toChar(), sizeof(this->m_buf)); + } + + ObjectName::ObjectName(const ObjectName& src) : StringBase() { + Fw::StringUtils::string_copy(this->m_buf, src.toChar(), sizeof(this->m_buf)); + } + + ObjectName::ObjectName() : StringBase() { + this->m_buf[0] = 0; + } + + ObjectName& ObjectName::operator=(const ObjectName& other) { + if(this == &other) { + return *this; + } + + Fw::StringUtils::string_copy(this->m_buf, other.toChar(), sizeof(this->m_buf)); + return *this; + } + + ObjectName& ObjectName::operator=(const StringBase& other) { + if(this == &other) { + return *this; + } + + Fw::StringUtils::string_copy(this->m_buf, other.toChar(), sizeof(this->m_buf)); + return *this; + } + + ObjectName& ObjectName::operator=(const char* other) { + Fw::StringUtils::string_copy(this->m_buf, other, sizeof(this->m_buf)); + return *this; + } + + ObjectName::~ObjectName() { + } + + const char* ObjectName::toChar() const { + return this->m_buf; + } + + NATIVE_UINT_TYPE ObjectName::getCapacity() const { + return STRING_SIZE; + } + +} diff --git a/Fw/Types/ObjectName.hpp b/Fw/Types/ObjectName.hpp new file mode 100644 index 0000000000..9098d39abb --- /dev/null +++ b/Fw/Types/ObjectName.hpp @@ -0,0 +1,37 @@ +#ifndef FW_OBJECT_NAME_TYPE_HPP +#define FW_OBJECT_NAME_TYPE_HPP + +#include +#include +#include + +namespace Fw { + + class ObjectName : public Fw::StringBase { + public: + + enum { + SERIALIZED_TYPE_ID = FW_TYPEID_OBJECT_NAME, //!< typeid for string type + STRING_SIZE = FW_OBJ_NAME_MAX_SIZE, //!< Storage for string + SERIALIZED_SIZE = STRING_SIZE + sizeof(FwBuffSizeType) //!< Serialized size is size of buffer + size field + }; + + ObjectName(const char* src); //!< char* source constructor + ObjectName(const StringBase& src); //!< StringBase string constructor + ObjectName(const ObjectName& src); //!< ObjectName string constructor + ObjectName(); //!< default constructor + ObjectName& operator=(const ObjectName& other); //!< assignment operator + ObjectName& operator=(const StringBase& other); //!< StringBase string assignment operator + ObjectName& operator=(const char* other); //!< char* assignment operator + ~ObjectName(); //!< destructor + + const char* toChar() const; //!< gets char buffer + NATIVE_UINT_TYPE getCapacity() const; //!< return buffer size + + private: + + char m_buf[STRING_SIZE]; //!< storage for string data + }; +} + +#endif diff --git a/Ref/RecvBuffApp/RecvBuffComponentImpl.cpp b/Ref/RecvBuffApp/RecvBuffComponentImpl.cpp index 120960814e..3ac4ca37cd 100644 --- a/Ref/RecvBuffApp/RecvBuffComponentImpl.cpp +++ b/Ref/RecvBuffApp/RecvBuffComponentImpl.cpp @@ -79,7 +79,7 @@ namespace Ref { void RecvBuffImpl::toString(char* str, I32 buffer_size) { #if FW_OBJECT_NAMES == 1 - (void)snprintf(str, buffer_size, "RecvBuffImpl: %s: ATM recd count: %d", this->m_objName, + (void)snprintf(str, buffer_size, "RecvBuffImpl: %s: ATM recd count: %d", this->m_objName.toChar(), (int) this->m_buffsReceived); #else (void)snprintf(str, buffer_size, "RecvBuffImpl: ATM recd count: %d", diff --git a/Ref/SendBuffApp/SendBuffComponentImpl.cpp b/Ref/SendBuffApp/SendBuffComponentImpl.cpp index d8f5cb789e..6dc43b056f 100644 --- a/Ref/SendBuffApp/SendBuffComponentImpl.cpp +++ b/Ref/SendBuffApp/SendBuffComponentImpl.cpp @@ -93,7 +93,7 @@ namespace Ref { void SendBuffImpl::toString(char* str, I32 buffer_size) { #if FW_OBJECT_NAMES == 1 - (void) snprintf(str, buffer_size, "Send Buff Component: %s: count: %d Buffs: %d", this->m_objName, + (void) snprintf(str, buffer_size, "Send Buff Component: %s: count: %d Buffs: %d", this->m_objName.toChar(), (int) this->m_invocations, (int) this->m_buffsSent); str[buffer_size-1] = 0; #else From abc9cdf9c152f0b23827259891b2bc1bcbb83bac Mon Sep 17 00:00:00 2001 From: thomas-bc Date: Mon, 22 Jan 2024 17:23:47 -0800 Subject: [PATCH 02/10] format --- Fw/Types/ObjectName.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/Fw/Types/ObjectName.cpp b/Fw/Types/ObjectName.cpp index 8bf8c539e5..a3bcca796d 100644 --- a/Fw/Types/ObjectName.cpp +++ b/Fw/Types/ObjectName.cpp @@ -52,5 +52,4 @@ namespace Fw { NATIVE_UINT_TYPE ObjectName::getCapacity() const { return STRING_SIZE; } - } From 1b67fd964584b678cad6bf352dd5531a409598cc Mon Sep 17 00:00:00 2001 From: thomas-bc Date: Mon, 22 Jan 2024 17:46:03 -0800 Subject: [PATCH 03/10] Add test case --- Fw/Types/test/ut/TypesTest.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/Fw/Types/test/ut/TypesTest.cpp b/Fw/Types/test/ut/TypesTest.cpp index 7f329a3af9..931c3c1ba2 100644 --- a/Fw/Types/test/ut/TypesTest.cpp +++ b/Fw/Types/test/ut/TypesTest.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include // @@ -1194,6 +1195,38 @@ TEST(TypesTest,EightyCharTest) { } +TEST(TypesTest,ObjectNameTest) { + Fw::ObjectName str; + str = "foo"; + Fw::ObjectName str2; + str2 = "foo"; + ASSERT_EQ(str,str2); + ASSERT_EQ(str,"foo"); + str2 = "_bar"; + ASSERT_NE(str,str2); + + Fw::ObjectName str3 = str; + str3 += str2; + ASSERT_EQ(str3,"foo_bar"); + + str3 += "xyzz"; + ASSERT_EQ(str3,"foo_barxyzz"); + + + Fw::ObjectName copyStr("ASTRING"); + ASSERT_EQ(copyStr,"ASTRING"); + Fw::ObjectName copyStr2 = "ASTRING"; + ASSERT_EQ(copyStr2,"ASTRING"); + Fw::ObjectName copyStr3(copyStr2); + ASSERT_EQ(copyStr3,"ASTRING"); + + Fw::InternalInterfaceString ifstr("IfString"); + Fw::ObjectName if2(ifstr); + + ASSERT_EQ(ifstr,if2); + ASSERT_EQ(if2,"IfString"); +} + TEST(TypesTest,StringFormatTest) { Fw::String str; str.format("Int %d String %s",10,"foo"); From 42332a5ff398a825db36cc6f8c376b1fcc571809 Mon Sep 17 00:00:00 2001 From: thomas-bc Date: Mon, 22 Jan 2024 22:00:46 -0800 Subject: [PATCH 04/10] Fix PolyDb UT and spelling --- Fw/Types/test/ut/TypesTest.cpp | 4 ++-- Svc/PolyDb/test/ut/PolyDbComponentTestAc.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Fw/Types/test/ut/TypesTest.cpp b/Fw/Types/test/ut/TypesTest.cpp index 931c3c1ba2..6167b62089 100644 --- a/Fw/Types/test/ut/TypesTest.cpp +++ b/Fw/Types/test/ut/TypesTest.cpp @@ -1209,8 +1209,8 @@ TEST(TypesTest,ObjectNameTest) { str3 += str2; ASSERT_EQ(str3,"foo_bar"); - str3 += "xyzz"; - ASSERT_EQ(str3,"foo_barxyzz"); + str3 += "_foo"; + ASSERT_EQ(str3,"foo_bar_foo"); Fw::ObjectName copyStr("ASTRING"); diff --git a/Svc/PolyDb/test/ut/PolyDbComponentTestAc.cpp b/Svc/PolyDb/test/ut/PolyDbComponentTestAc.cpp index a1b2f2db29..0c349e832c 100644 --- a/Svc/PolyDb/test/ut/PolyDbComponentTestAc.cpp +++ b/Svc/PolyDb/test/ut/PolyDbComponentTestAc.cpp @@ -36,7 +36,7 @@ namespace Svc { this->m_getValue_OutputPort[port].init(); #if FW_OBJECT_NAMES == 1 char portName[120]; - snprintf(portName, sizeof(portName), "%s_getValue_OutputPort[%d]", this->m_objName, port); + snprintf(portName, sizeof(portName), "%s_getValue_OutputPort[%d]", this->m_objName.toChar(), port); this->m_getValue_OutputPort[port].setObjName(portName); #endif } @@ -45,7 +45,7 @@ namespace Svc { this->m_setValue_OutputPort[port].init(); #if FW_OBJECT_NAMES == 1 char portName[120]; - snprintf(portName, sizeof(portName), "%s_setValue_OutputPort[%d]", this->m_objName, port); + snprintf(portName, sizeof(portName), "%s_setValue_OutputPort[%d]", this->m_objName.toChar(), port); this->m_setValue_OutputPort[port].setObjName(portName); #endif } From 384d1d2fb01d4a6b6efba50833b36906baea4e61 Mon Sep 17 00:00:00 2001 From: thomas-bc Date: Tue, 23 Jan 2024 17:41:50 -0800 Subject: [PATCH 05/10] Explicit constructor and use CHAR --- Fw/Types/ObjectName.cpp | 6 +++--- Fw/Types/ObjectName.hpp | 10 +++++----- Fw/Types/test/ut/TypesTest.cpp | 4 +--- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/Fw/Types/ObjectName.cpp b/Fw/Types/ObjectName.cpp index a3bcca796d..6fafbeefc8 100644 --- a/Fw/Types/ObjectName.cpp +++ b/Fw/Types/ObjectName.cpp @@ -3,7 +3,7 @@ namespace Fw { - ObjectName::ObjectName(const char* src) : StringBase() { + ObjectName::ObjectName(const CHAR* src) : StringBase() { Fw::StringUtils::string_copy(this->m_buf, src, sizeof(this->m_buf)); } @@ -37,7 +37,7 @@ namespace Fw { return *this; } - ObjectName& ObjectName::operator=(const char* other) { + ObjectName& ObjectName::operator=(const CHAR* other) { Fw::StringUtils::string_copy(this->m_buf, other, sizeof(this->m_buf)); return *this; } @@ -45,7 +45,7 @@ namespace Fw { ObjectName::~ObjectName() { } - const char* ObjectName::toChar() const { + const CHAR* ObjectName::toChar() const { return this->m_buf; } diff --git a/Fw/Types/ObjectName.hpp b/Fw/Types/ObjectName.hpp index 9098d39abb..1fb770d4d1 100644 --- a/Fw/Types/ObjectName.hpp +++ b/Fw/Types/ObjectName.hpp @@ -16,21 +16,21 @@ namespace Fw { SERIALIZED_SIZE = STRING_SIZE + sizeof(FwBuffSizeType) //!< Serialized size is size of buffer + size field }; - ObjectName(const char* src); //!< char* source constructor - ObjectName(const StringBase& src); //!< StringBase string constructor + explicit ObjectName(const CHAR* src); //!< char* source constructor + explicit ObjectName(const StringBase& src); //!< StringBase string constructor ObjectName(const ObjectName& src); //!< ObjectName string constructor ObjectName(); //!< default constructor ObjectName& operator=(const ObjectName& other); //!< assignment operator ObjectName& operator=(const StringBase& other); //!< StringBase string assignment operator - ObjectName& operator=(const char* other); //!< char* assignment operator + ObjectName& operator=(const CHAR* other); //!< char* assignment operator ~ObjectName(); //!< destructor - const char* toChar() const; //!< gets char buffer + const CHAR* toChar() const; //!< gets char buffer NATIVE_UINT_TYPE getCapacity() const; //!< return buffer size private: - char m_buf[STRING_SIZE]; //!< storage for string data + CHAR m_buf[STRING_SIZE]; //!< storage for string data }; } diff --git a/Fw/Types/test/ut/TypesTest.cpp b/Fw/Types/test/ut/TypesTest.cpp index 6167b62089..339f357a8c 100644 --- a/Fw/Types/test/ut/TypesTest.cpp +++ b/Fw/Types/test/ut/TypesTest.cpp @@ -1215,10 +1215,8 @@ TEST(TypesTest,ObjectNameTest) { Fw::ObjectName copyStr("ASTRING"); ASSERT_EQ(copyStr,"ASTRING"); - Fw::ObjectName copyStr2 = "ASTRING"; + Fw::ObjectName copyStr2(copyStr); ASSERT_EQ(copyStr2,"ASTRING"); - Fw::ObjectName copyStr3(copyStr2); - ASSERT_EQ(copyStr3,"ASTRING"); Fw::InternalInterfaceString ifstr("IfString"); Fw::ObjectName if2(ifstr); From 02c9cb92f4b96c0d4e67540b1d53804d2b6a95aa Mon Sep 17 00:00:00 2001 From: "Robert L. Bocchino Jr" Date: Mon, 26 Feb 2024 09:27:22 -0800 Subject: [PATCH 06/10] Revise ObjBase.hpp Don't include ObjectName header unless object names are enabled --- Fw/Obj/ObjBase.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Fw/Obj/ObjBase.hpp b/Fw/Obj/ObjBase.hpp index e4d55f7669..b0b30d18ab 100644 --- a/Fw/Obj/ObjBase.hpp +++ b/Fw/Obj/ObjBase.hpp @@ -14,7 +14,9 @@ #define FW_OBJ_BASE_HPP #include +#if FW_OBJECT_NAMES == 1 #include +#endif namespace Fw { From 387b969a6cd9b18446f94f3aaddc03afae1e2c76 Mon Sep 17 00:00:00 2001 From: thomas-bc Date: Mon, 26 Feb 2024 16:21:38 -0800 Subject: [PATCH 07/10] Update requirements.txt for fpp==2.1.0a4 --- requirements.txt | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/requirements.txt b/requirements.txt index a82f537e91..7efca76fcd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -18,17 +18,17 @@ fprime-fpl-convert-xml==1.0.3 fprime-fpl-extract-xml==1.0.3 fprime-fpl-layout==1.0.3 fprime-fpl-write-pic==1.0.3 -fprime-fpp-check==2.1.0a3 -fprime-fpp-depend==2.1.0a3 -fprime-fpp-filenames==2.1.0a3 -fprime-fpp-format==2.1.0a3 -fprime-fpp-from-xml==2.1.0a3 -fprime-fpp-locate-defs==2.1.0a3 -fprime-fpp-locate-uses==2.1.0a3 -fprime-fpp-syntax==2.1.0a3 -fprime-fpp-to-cpp==2.1.0a3 -fprime-fpp-to-json==2.1.0a3 -fprime-fpp-to-xml==2.1.0a3 +fprime-fpp-check==2.1.0a4 +fprime-fpp-depend==2.1.0a4 +fprime-fpp-filenames==2.1.0a4 +fprime-fpp-format==2.1.0a4 +fprime-fpp-from-xml==2.1.0a4 +fprime-fpp-locate-defs==2.1.0a4 +fprime-fpp-locate-uses==2.1.0a4 +fprime-fpp-syntax==2.1.0a4 +fprime-fpp-to-cpp==2.1.0a4 +fprime-fpp-to-json==2.1.0a4 +fprime-fpp-to-xml==2.1.0a4 fprime-gds==3.4.3 fprime-tools==3.4.4 fprime-visual==1.0.2 From 75f3c04472897cda6d415276f23d29b158dd496b Mon Sep 17 00:00:00 2001 From: thomas-bc Date: Fri, 1 Mar 2024 10:20:03 -0800 Subject: [PATCH 08/10] 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; From ce61d97f23783ea3b49da03729f5445c0a438475 Mon Sep 17 00:00:00 2001 From: thomas-bc Date: Fri, 1 Mar 2024 10:58:56 -0800 Subject: [PATCH 09/10] cast string_copy return value to void --- Fw/Types/ObjectName.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Fw/Types/ObjectName.cpp b/Fw/Types/ObjectName.cpp index 6fafbeefc8..a3c2171e5d 100644 --- a/Fw/Types/ObjectName.cpp +++ b/Fw/Types/ObjectName.cpp @@ -4,15 +4,15 @@ namespace Fw { ObjectName::ObjectName(const CHAR* src) : StringBase() { - Fw::StringUtils::string_copy(this->m_buf, src, sizeof(this->m_buf)); + (void) Fw::StringUtils::string_copy(this->m_buf, src, sizeof(this->m_buf)); } ObjectName::ObjectName(const StringBase& src) : StringBase() { - Fw::StringUtils::string_copy(this->m_buf, src.toChar(), sizeof(this->m_buf)); + (void) Fw::StringUtils::string_copy(this->m_buf, src.toChar(), sizeof(this->m_buf)); } ObjectName::ObjectName(const ObjectName& src) : StringBase() { - Fw::StringUtils::string_copy(this->m_buf, src.toChar(), sizeof(this->m_buf)); + (void) Fw::StringUtils::string_copy(this->m_buf, src.toChar(), sizeof(this->m_buf)); } ObjectName::ObjectName() : StringBase() { @@ -24,7 +24,7 @@ namespace Fw { return *this; } - Fw::StringUtils::string_copy(this->m_buf, other.toChar(), sizeof(this->m_buf)); + (void) Fw::StringUtils::string_copy(this->m_buf, other.toChar(), sizeof(this->m_buf)); return *this; } @@ -33,12 +33,12 @@ namespace Fw { return *this; } - Fw::StringUtils::string_copy(this->m_buf, other.toChar(), sizeof(this->m_buf)); + (void) Fw::StringUtils::string_copy(this->m_buf, other.toChar(), sizeof(this->m_buf)); return *this; } ObjectName& ObjectName::operator=(const CHAR* other) { - Fw::StringUtils::string_copy(this->m_buf, other, sizeof(this->m_buf)); + (void) Fw::StringUtils::string_copy(this->m_buf, other, sizeof(this->m_buf)); return *this; } From 4d245d7f21dce76fe24f31d0e6c81731d47e6988 Mon Sep 17 00:00:00 2001 From: thomas-bc Date: Fri, 1 Mar 2024 18:39:11 -0800 Subject: [PATCH 10/10] Resolve unchecked argument --- Fw/Comp/ActiveComponentBase.cpp | 1 + Fw/Comp/PassiveComponentBase.cpp | 2 +- Fw/Comp/QueuedComponentBase.cpp | 1 + Fw/Obj/ObjBase.cpp | 1 + Fw/Port/InputPortBase.cpp | 1 + 5 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Fw/Comp/ActiveComponentBase.cpp b/Fw/Comp/ActiveComponentBase.cpp index 98a80e6f7d..0ec0a8bb41 100644 --- a/Fw/Comp/ActiveComponentBase.cpp +++ b/Fw/Comp/ActiveComponentBase.cpp @@ -45,6 +45,7 @@ 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); + FW_ASSERT(buffer != nullptr); 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 f453dfec1a..65cc3ca9ad 100644 --- a/Fw/Comp/PassiveComponentBase.cpp +++ b/Fw/Comp/PassiveComponentBase.cpp @@ -11,8 +11,8 @@ namespace Fw { #if FW_OBJECT_TO_STRING == 1 && FW_OBJECT_NAMES == 1 void PassiveComponentBase::toString(char* buffer, NATIVE_INT_TYPE size) { - FW_ASSERT(buffer); FW_ASSERT(size > 0); + FW_ASSERT(buffer != nullptr); 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 4e40c36928..da94dc6ef4 100644 --- a/Fw/Comp/QueuedComponentBase.cpp +++ b/Fw/Comp/QueuedComponentBase.cpp @@ -22,6 +22,7 @@ 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); + FW_ASSERT(buffer != nullptr); 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 956341b16c..494f225512 100644 --- a/Fw/Obj/ObjBase.cpp +++ b/Fw/Obj/ObjBase.cpp @@ -47,6 +47,7 @@ namespace Fw { #if FW_OBJECT_TO_STRING == 1 void ObjBase::toString(char* str, NATIVE_INT_TYPE size) { FW_ASSERT(size > 0); + FW_ASSERT(str != nullptr); 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 d4ef26e499..eb880b9017 100644 --- a/Fw/Port/InputPortBase.cpp +++ b/Fw/Port/InputPortBase.cpp @@ -29,6 +29,7 @@ namespace Fw { void InputPortBase::toString(char* buffer, NATIVE_INT_TYPE size) { #if FW_OBJECT_NAMES == 1 FW_ASSERT(size > 0); + FW_ASSERT(buffer != nullptr); PlatformIntType status = snprintf(buffer, size, "InputPort: %s->%s", this->m_objName.toChar(), this->isConnected() ? this->m_connObj->getObjName() : "None"); if (status < 0) {