This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Patch] Minor GCC documentation correction for -Wformat-overflow


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.

Attachment: Wformatoverflow-doc-fix.txt
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]