lamarrr/STX

STX_INTERNAL_MAKE_REPORT_ warnings with -Wsign-conversion

nyanpasu64 opened this issue · 1 comments

Describe the bug
When I include STX master in a CMake project where I build my source files with -Wconversion -Wsign-conversion, then STX_INTERNAL_MAKE_REPORT_ raises a sign conversion warning when converting fmt_buffer_size to size_t.

STX/include/stx/report.h

Lines 334 to 343 in 9f8f97a

#define STX_INTERNAL_MAKE_REPORT_(STX_ARG_SIZE, STX_ARG_FORMAT, STX_ARG_VALUE) \
/* string size + terminating null character */ \
char fmt_buffer[STX_ARG_SIZE + 1]; \
int fmt_buffer_size = std::snprintf(fmt_buffer, STX_ARG_SIZE + 1, \
STX_ARG_FORMAT, STX_ARG_VALUE); \
if (fmt_buffer_size < 0 || fmt_buffer_size >= STX_ARG_SIZE + 1) { \
return FixedReport(kFormatError, kFormatErrorSize); \
} else { \
return FixedReport(fmt_buffer, fmt_buffer_size); \
}

Expected behavior
The code has two branches, returning a formatting error if fmt_buffer_size < 0. So fmt_buffer_size is only casted to size_t if non-negative. So perhaps insert an explicit cast (do you prefer static_cast over C-style casts?)?

Additional context
Is compiling warning-free with -Wsign-conversion in-scope?

seems this has been solved

return std::string_view{STX_ARG_BUFFER.data, \