https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85652

            Bug ID: 85652
           Summary: -Wformat-overflow warning silenced by -fpic/-fPIC
           Product: gcc
           Version: 8.1.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sirl at gcc dot gnu.org
  Target Milestone: ---
            Target: x86_64-linux

Created attachment 44070
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=44070&action=edit
testcase

The attached creduce'd testcase warns with -Wformat-overflow:

$ g++-8 -c -O2 -Wformat-overflow t7.cpp 
t7.cpp: In function 'void f()':
t7.cpp:15:16: warning: '%s' directive writing up to 55 bytes into a region of
size 12 [-Wformat-overflow=]
t7.cpp:9:10:
   return c[d];
          ~~~~   
t7.cpp:15:16:
     sprintf(e, "xxxxxxxxxxxx %s / %s", "", g);
                ^~~~~~~~~~~~~~~~~~~~~~
t7.cpp:15:12: note: 'sprintf' output between 17 and 72 bytes into a destination
of size 28
     sprintf(e, "xxxxxxxxxxxx %s / %s", "", g);
     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

But when -fpic or -fPIC is added, the warning vanishes. Current trunk@259927
shows the same behaviour.

Reply via email to