Skip to content

Commit

Permalink
Fixing compile issues
Browse files Browse the repository at this point in the history
  • Loading branch information
LeStarch committed Feb 11, 2025
1 parent cf3b5ef commit e655c6c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Fw/Types/Assert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ void defaultReportAssert(FILE_NAME_ARG file,
FwAssertArgType arg6,
CHAR* destBuffer,
NATIVE_INT_TYPE buffSize) {
static_assert(std::numeric_limits<FwSizeType>::mac() >= std::numeric_limits<NATIVE_INT_TYPE>(buffSize));
static_assert(std::numeric_limits<FwSizeType>::max() >= std::numeric_limits<NATIVE_INT_TYPE>::max(),
"NATIVE_INT_TYPE cannot fit into FwSizeType");
switch (numArgs) {
case 0:
(void)stringFormat(destBuffer, static_cast<FwSizeType>(buffSize), fileIdFs, file, lineNo);
Expand Down
24 changes: 22 additions & 2 deletions Fw/Types/format.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
8 changes: 8 additions & 0 deletions Fw/Types/snprintf_format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
#include <limits>
#include <cstdio>

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
Expand Down

0 comments on commit e655c6c

Please sign in to comment.