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

bounds checking in STL containers

Hi All,

It appears that operator[] in STL containers (e.g. vector, deque) does not check bounds any more (g++ 4.7.2).

Two-three generations ago g++ was very cautious about consistency checking but not now.

I would appeal to developers to reconsider this pretty tough decision.

I have recently experienced a problem with operator[]. The vector instance had its capacity larger than the size.
Mistakenly addressing element beyond the true range did not cause immediate crash rather the output of a complex signal
processing application was "strange". This is a pretty common situation (when capacity > size), which is very hard to track,
especially if the elements beyond the valid range have accidentally the "reasonable" values.

I believe that a simple bounds checking in DEBUG mode (say, assert(first + n < last)) would rule out
most of potentially dangerous situations like aforementioned one. Otherwise we get back to C-style arrays.


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