Open
Description
(Compiles correctly, no security ramifications, so prioritize accordingly. May be an easy fix, though.)
In clang 18.1 and later (but not in 17.0.1 or earlier), compiling the following :
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
int main( const int argc, const char **argv)
{
char buff[9];
assert( argc == 2);
snprintf( buff, sizeof( buff), "%8.2f", atof( argv[1]));
printf( "'%s'\n", buff);
snprintf( buff, sizeof( buff), "%+8.2f", atof( argv[1]));
printf( "'%s'\n", buff);
return( 0);
}
gets me the following warning for the second snprintf()
. I think this is due to an assumption that the '+' will be added in, resulting in a nine-byte (plus \0
terminator) output. Tested via the godbolt.org Compiler Explorer.
<source>:12:4: warning: 'snprintf' will always be truncated; specified size is 9, but format string expands to at least 10 [-Wformat-truncation]
12 | snprintf( buff, sizeof( buff), "%+8.2f", atof( argv[1]));
| ^
Thank you. I'm quite impressed with this compiler!