diff --git a/Fw/Types/Assert.cpp b/Fw/Types/Assert.cpp index ade5a118e2..f69cc86287 100644 --- a/Fw/Types/Assert.cpp +++ b/Fw/Types/Assert.cpp @@ -30,7 +30,8 @@ void defaultReportAssert(FILE_NAME_ARG file, FwAssertArgType arg6, CHAR* destBuffer, NATIVE_INT_TYPE buffSize) { - static_assert(std::numeric_limits::mac() >= std::numeric_limits(buffSize)); + static_assert(std::numeric_limits::max() >= std::numeric_limits::max(), + "NATIVE_INT_TYPE cannot fit into FwSizeType"); switch (numArgs) { case 0: (void)stringFormat(destBuffer, static_cast(buffSize), fileIdFs, file, lineNo); diff --git a/Fw/Types/format.hpp b/Fw/Types/format.hpp index 407227087e..0d6fb397d4 100644 --- a/Fw/Types/format.hpp +++ b/Fw/Types/format.hpp @@ -34,10 +34,30 @@ enum class FormatStatus { //! OTHER_ERROR: another error occurred in an underlying function call //! Otherwise SUCCESS is returned. destination may be modified even in the case of an error. //! -//! \param destination: destination to fill with the formatted string. +//! \param destination: destination to fill with the formatted string //! \param maximumSize: size of the buffer represented by destination //! \param formatString: format string to fill -//! \param args: variable arguments. +//! \param ...: variable arguments inputs +//! \return: SUCCESS on successful formatting, OVERFLOWED on overflow, and something else on any error + FormatStatus stringFormat(char* destination, const FwSizeType maximumSize, const char* formatString, ...); + +//! \brief format a c-string +//! +//! Format a string using printf family formatting semantics. Destination will be filled with the formatted string up to +//! maximumSize - 1. This function will always terminate the string with a \0. +//! +//! This function can return several error codes: +//! OVERFLOWED: the complete string did not fit in the buffer with an appended null-terminator +//! INVALID_FORMAT_STRING: the format string was null +//! OTHER_ERROR: another error occurred in an underlying function call +//! Otherwise SUCCESS is returned. destination may be modified even in the case of an error. +//! +//! This version take a variable argument list +//! +//! \param destination: destination to fill with the formatted string +//! \param maximumSize: size of the buffer represented by destination +//! \param formatString: format string to fill +//! \param args: variable arguments list //! \return: SUCCESS on successful formatting, OVERFLOWED on overflow, and something else on any error FormatStatus stringFormat(char* destination, const FwSizeType maximumSize, const char* formatString, va_list args); } diff --git a/Fw/Types/snprintf_format.cpp b/Fw/Types/snprintf_format.cpp index 33a994029a..a69355f0e6 100644 --- a/Fw/Types/snprintf_format.cpp +++ b/Fw/Types/snprintf_format.cpp @@ -7,6 +7,14 @@ #include #include +Fw::FormatStatus Fw::stringFormat(char* destination, const FwSizeType maximumSize, const char* formatString, ...) { + va_list args; + va_start(args, formatString); + FormatStatus status = Fw::stringFormat(destination, maximumSize, formatString, args); + va_end(args); + return status; +} + Fw::FormatStatus Fw::stringFormat(char* destination, const FwSizeType maximumSize, const char* formatString, va_list args) { Fw::FormatStatus formatStatus = Fw::FormatStatus::SUCCESS; // Force null termination in error cases