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

Fix snprintf #1156

Merged
merged 6 commits into from
Dec 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Fw/Obj/ObjBase.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <FpConfig.hpp>
#include <Fw/Obj/ObjBase.hpp>
#include <Fw/Types/Assert.hpp>
#include <string.h>
#include <stdio.h>

Expand Down Expand Up @@ -46,8 +47,10 @@ namespace Fw {
}
#if FW_OBJECT_TO_STRING == 1
void ObjBase::toString(char* str, NATIVE_INT_TYPE size) {
(void)snprintf(str, size, "Obj: %s",this->m_objName);
str[size-1] = 0;
FW_ASSERT(size > 0);
if (snprintf(str, size, "Obj: %s",this->m_objName) < 0) {
str[0] = 0;
}
}
#endif
#endif
Expand Down
10 changes: 6 additions & 4 deletions Fw/Port/InputPortBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ namespace Fw {

#if FW_OBJECT_TO_STRING == 1
void InputPortBase::toString(char* buffer, NATIVE_INT_TYPE size) {
#if FW_OBJECT_NAMES == 1
(void)snprintf(buffer, size, "InputPort: %s->%s", this->m_objName,
this->isConnected() ? this->m_connObj->getObjName() : "None");
buffer[size-1] = 0;
#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) {
buffer[0] = 0;
}
#else
(void)snprintf(buffer,size,"%s","Unnamed Input port");
#endif
Expand Down
10 changes: 6 additions & 4 deletions Fw/Port/InputSerializePort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ namespace Fw {

#if FW_OBJECT_TO_STRING == 1
void InputSerializePort::toString(char* buffer, NATIVE_INT_TYPE size) {
#if FW_OBJECT_NAMES == 1
(void)snprintf(buffer, size, "Input Serial Port: %s %s->(%s)", this->m_objName, this->isConnected() ? "C" : "NC",
this->isConnected() ? this->m_connObj->getObjName() : "None");
buffer[size-1] = 0;
#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",
this->isConnected() ? this->m_connObj->getObjName() : "None") < 0) {
buffer[0] = 0;
}
#else
(void)snprintf(buffer,size,"%s","InputSerializePort");
#endif
Expand Down
10 changes: 6 additions & 4 deletions Fw/Port/OutputPortBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ namespace Fw {

#if FW_OBJECT_TO_STRING == 1
void OutputPortBase::toString(char* buffer, NATIVE_INT_TYPE size) {
#if FW_OBJECT_NAMES == 1
(void)snprintf(buffer, size, "OutputPort: %s %s->(%s)", this->m_objName, this->isConnected() ? "C" : "NC",
this->isConnected() ? this->m_connObj->getObjName() : "None");
buffer[size-1] = 0;
#if FW_OBJECT_NAMES == 1
FW_ASSERT(size > 0);
if (snprintf(buffer, size, "OutputPort: %s %s->(%s)", this->m_objName, this->isConnected() ? "C" : "NC",
this->isConnected() ? this->m_connObj->getObjName() : "None") < 0) {
buffer[0] = 0;
}
#else
(void)snprintf(buffer,size,"%s","OutputPort");
#endif
Expand Down
10 changes: 6 additions & 4 deletions Fw/Port/OutputSerializePort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ namespace Fw {

#if FW_OBJECT_TO_STRING == 1
void OutputSerializePort::toString(char* buffer, NATIVE_INT_TYPE size) {
#if FW_OBJECT_NAMES == 1
(void)snprintf(buffer, size, "Output Serial Port: %s %s->(%s)", this->m_objName, this->isConnected() ? "C" : "NC",
this->isConnected() ? this->m_connObj->getObjName() : "None");
buffer[size-1] = 0;
#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",
this->isConnected() ? this->m_connObj->getObjName() : "None") < 0) {
buffer[0] = 0;
}
#else
(void)snprintf(buffer,size,"%s","OutputSerializePort");
#endif
Expand Down
10 changes: 6 additions & 4 deletions Fw/Port/PortBase.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <Fw/Port/PortBase.hpp>
#include <Fw/Types/BasicTypes.hpp>
#include <Fw/Logger/Logger.hpp>
#include "Fw/Types/Assert.hpp"
#include <stdio.h>

#if FW_PORT_TRACING
Expand Down Expand Up @@ -77,10 +78,11 @@ namespace Fw {
#if FW_OBJECT_NAMES == 1
#if FW_OBJECT_TO_STRING == 1
void PortBase::toString(char* buffer, NATIVE_INT_TYPE size) {
(void)snprintf(buffer, size, "Port: %s %s->(%s)", this->m_objName, this->m_connObj ? "C" : "NC",
this->m_connObj ? this->m_connObj->getObjName() : "None");
// NULL terminate
buffer[size-1] = 0;
FW_ASSERT(size > 0);
if (snprintf(buffer, size, "Port: %s %s->(%s)", this->m_objName, this->m_connObj ? "C" : "NC",
this->m_connObj ? this->m_connObj->getObjName() : "None") < 0) {
buffer[0] = 0;
}
}
#endif // FW_OBJECT_TO_STRING
#endif // FW_OBJECT_NAMES
Expand Down