This is the mail archive of the gcc@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]

Re: contributing & bound-checks


rv <potam@sympatico.ca> writes:

> foreword: Hi, newbie-to-mailing-lists here so my apologies in advance if 
> there's some netiquette I'm missing.
> 
> I've looked to bound-checking projects/patches for gcc but couldnt find 
> anything satisfactory for C++

It doesn't bounds check pointers or arrays, but you could try
    configuring with --enable-libstdcxx-debug and compiling with
    -D_GLIBCXX_DEBUG . This does bounds checking for standard C++
    library containers;

Running this program:

    #include<vector>

    using namespace std;

    int main()
      {
        vector<int> v1(10);
        v1[11]= 2;
      }

Results in this runtime error (when built with -D_GLIBCXX_DEBUG):

    ./a.out
    /usr/local/gcc-3.4/lib/gcc/i386-unknown-freebsd5.2/3.4.0/include/c++/debug/vector:192:
        error: attempt to subscript container with out-of-bounds index 11,
    but
        container only holds 10 elements.

    Objects involved in the operation:
    sequence "this" @ 0x0xbfbfe8d8 {
      type = N15__gnu_debug_def6vectorIiSaIiEEE;
    }
    Abort (core dumped)

It also checks for (mis)uses of invalid and past-the-end iterators.


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