Open
Description
We use printf
compatible formatting in error logging, where the formatting statements are rarely executed and so errors can hide.
Something in our implementation means compilers don't do the error checking they are able to do for printf
.
For example, this compiles without warning:
GFXRECON_LOG_DEBUG("Attempt to reset current file to itself: %p.", 0.3784747f);
By contrast, this generates a warning that is upgraded to an error:
printf("Attempt to reset current file to itself: %p.", 0.3784747f);
OutPut:
warning C4477: 'printf' : format string '%p' requires an argument of type 'void *', but variadic argument 1 has type 'double'
(interestingly the float is reported as a double)
- We should enable the checking that compilers can do for printf with our own logging on at least one of the platforms/compilers used by our github runners. (e,g, https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-format-function-attribute)
- We should move to a safe formatting approach such as one of these (maybe a follow-up issue):
- Stream-style safe C++ formatting in logging.
- Modern C++ 20 formatting https://en.cppreference.com/w/cpp/utility/format