On 02/14/2018 02:28 PM, Indu Bhagat wrote:
In section "-Wformat-overflow=1", following is stated :
void f (int a, int b)
char buf ;
sprintf (buf, "a = %i, b = %i\n", a, b);
" Increasing the size of the buffer by a single byte is sufficient to avoid
[size of an unknown int for the purpose of this warning is = 1 (to
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
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
Alternatively, the size of buf can be bumped up to 13 in the sample code
in the patch below.
You're right, that's an off-by-one error/typo in the example.
Your patch seems like an obvious fix that can go in without
a formal approval, so I've committed it for you in r257680.