Your check is wrong because '(2 * len) + 1' will (just barely) overflow if len is on the upper end of the checked range. However, if it works incorrectly even when len is not, I'd call that a compiler bug. Note that newer versions of GCC seem to be fine.