[Bug c++/83779] New: Trivial bounds error not detected with -fbounds-check

w6ws at earthlink dot net gcc-bugzilla@gcc.gnu.org
Wed Jan 10 22:34:00 GMT 2018


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

            Bug ID: 83779
           Summary: Trivial bounds error not detected with -fbounds-check
           Product: gcc
           Version: 5.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: w6ws at earthlink dot net
  Target Milestone: ---

Does -fbounds-check do anything useful with C/C++ code?  The following trivial
code does not trigger any error at run time.  (Note: I added the static
attribute because otherwise this simple example does trigger a stack smash
detected message after the program completes.):

wws@w6ws-4:/tmp$ cat bck.c
#include <stdio.h>

int main () {

  static int array1[20];

  for (int i=0; i<25; i++)
    array1[i] = i;

  printf ("done!\n");
}
wws@w6ws-4:/tmp$ g++ --version
g++ (Ubuntu 5.4.0-6ubuntu1~16.04.5) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

wws@w6ws-4:/tmp$ g++ -g -fbounds-check bck.c
wws@w6ws-4:/tmp$ a.out
done!
wws@w6ws-4:/tmp$ gcc -g -fbounds-check bck.c
wws@w6ws-4:/tmp$ a.out
done!
wws@w6ws-4:/tmp$


More information about the Gcc-bugs mailing list