contributing & bound-checks
llewelly@xmission.com
llewelly@xmission.com
Mon Jun 28 03:58:00 GMT 2004
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.
More information about the Gcc
mailing list