This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: contributing & bound-checks
- From: llewelly at xmission dot com
- To: rv <potam at sympatico dot ca>
- Cc: gcc at gcc dot gnu dot org
- Date: 27 Jun 2004 21:56:33 -0600
- Subject: Re: contributing & bound-checks
- References: <200406231550.12493.potam@sympatico.ca>
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.