[Bug c/55892] Bogus compiler warning

pinskia at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon Jan 7 07:35:00 GMT 2013


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55892

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> 2013-01-07 07:34:25 UTC ---
First off you also need -D_FORTIFY_SOURCE and a newish glibc headers.  Second I
think this warning is correct.
Take a line which is 16 characters long.
The first time at beginning of the loop, limit: 8; readlimit: 8.

The next time, limit:0 readlimit: 0.
The next time limit: (unsigned long)(-8) readlimit: INT32_MAX
Warn because readlimit > 1024.

The reason why the first call to fgetsl does not warn is because it does not
get inlined as it is not hot.
The second is also the same reason as the first but also the code for fgets
cannot figure out the size of the variable, buffer.
The last has the same issue as second minus the inline issue.

The trunk gives a very good warning message of the point of the inline function
happens too:
In file included from /usr/include/stdio.h:910:0,
                 from t67.c:2:
In function ‘fgets’,
    inlined from ‘fgetsl.constprop.0’ at t67.c:17:11,
    inlined from ‘main’ at t67.c:33:14:
/usr/include/bits/stdio2.h:253:2: warning: call to ‘__fgets_chk_warn’ declared
with attribute warning: fgets called with bigger size than length of
destination buffer [enabled by default]
  return __fgets_chk_warn (__s, __bos (__s), __n, __stream);
  ^



More information about the Gcc-bugs mailing list