<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/143951>143951</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Incorrect warning message
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Bill-Gray
</td>
</tr>
</table>
<pre>
(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 :
```c
#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](https://godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(filename:'1',fontScale:14,fontUsePx:'0',j:1,lang:c%2B%2B,selection:(endColumn:2,endLineNumber:15,positionColumn:1,positionLineNumber:1,selectionStartColumn:2,selectionStartLineNumber:15,startColumn:1,startLineNumber:1),source:'%23include+%3Cstdio.h%3E%0A%23include+%3Cstdlib.h%3E%0A%23include+%3Cassert.h%3E%0A%0Aint+main(+const+int+argc,+const+char+**argv)%0A%7B%0A+++char+buff%5B9%5D%3B%0A%0A+++assert(+argc+%3D%3D+2)%3B%0A+++snprintf(+buff,+sizeof(+buff),+%22%258.2f%22,+atof(+argv%5B1%5D))%3B%0A+++printf(+%22!'%25s!'%5Cn%22,+buff)%3B%0A+++snprintf(+buff,+sizeof(+buff),+%22%25%2B8.2f%22,+atof(+argv%5B1%5D))%3B%0A+++printf(+%22!'%25s!'%5Cn%22,+buff)%3B%0A+++return(+0)%3B%0A%7D%0A'),l:'5',n:'0',o:'C%2B%2B+source+%231',t:'0')),k:33.333333333333336,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:clang1810,filters:(b:'0',binary:'1',binaryObject:'1',commentOnly:'0',debugCalls:'1',demangle:'0',directives:'0',execute:'1',intel:'0',libraryCode:'0',trim:'1',verboseDemangling:'0'),flagsViewOpen:'1',fontScale:14,fontUsePx:'0',j:1,lang:c%2B%2B,libs:!(),options:'',overrides:!(),selection:(endColumn:37,endLineNumber:6,positionColumn:37,positionLineNumber:6,selectionStartColumn:37,selectionStartLineNumber:6,startColumn:37,startLineNumber:6),source:1),l:'5',n:'0',o:'+x86-64+clang+18.1.0+(Editor+%231)',t:'0')),k:33.333333333333336,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:output,i:(compilerName:'x86-64+clang+17.0.1+(assertions)',editorid:1,fontScale:14,fontUsePx:'0',j:1,wrap:'1'),l:'5',n:'0',o:'Output+of+x86-64+clang+18.1.0+(Compiler+%231)',t:'0')),k:33.33333333333333,l:'4',n:'0',o:'',s:0,t:'0')),l:'2',n:'0',o:'',t:'0')),version:4).
```
<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!
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzMWF-P4jgS_zTmpdQocQiBBx5I6D6NdLdz0u7dPTtJAd5xbM526GY__ansdCAM27d9mpO21YKkXH9t16-qEM7Jg0bcsLxk-W4men80dlNKpZ7-YsVlVpv2smF8VZnuJBU6aIy12Hh1YbwC0AYcNr2V_gJWdHIvG-Gl0S6sOgMnK42VXv6GIJrG2Fbqg7rMAf4mLlAjCA0o3AX28o1E_NH0h-Oc8TVLtizZftHQKKEPkK7mKQjdghIeLTC-qnsP2niQGtJinsxTMBZQWCXRkjyvoAlO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