In section "-Wformat-overflow=1", following is stated :
void f (int a, int b)
{
char buf [12];
sprintf (buf, "a = %i, b = %i\n", a, b);
}
" Increasing the size of the buffer by a single byte is sufficient to avoid
the warning,"
[size of an unknown int for the purpose of this warning is = 1 (to represent 0);
add 1 for newline, add 1 for null; add all the other chars in the format
string = 14]
The minimum increase however needs to be of 2 bytes. i.e., a buf of size 14 is
the minimum length for the warning in the example to go away.
So the correct statement should be -
" Increasing the size of the buffer by two bytes is sufficient to avoid the
warning,"
Alternatively, the size of buf can be bumped up to 13 in the sample code as done
in the patch below.
Thanks
--------------
gcc/ChangeLog:
* doc/invoke.texi: Correction in -Wformat-overflow code sample.
Index: gcc/doc/invoke.texi
===================================================================
--- gcc/doc/invoke.texi (revision 257646)
+++ gcc/doc/invoke.texi (working copy)
@@ -4184,7 +4184,7 @@
@smallexample
void f (int a, int b)
@{
- char buf [12];
+ char buf [13];
sprintf (buf, "a = %i, b = %i\n", a, b);
@}
@end smallexample