GCC and pointer overflows
Posted Apr 17, 2008 22:03 UTC (Thu) by
im14u2c (subscriber, #5246)
In reply to:
GCC and pointer overflows by wahern
Parent article:
GCC and pointer overflows
Of course, it fails for dynamically allocated and grown buffers since sizeof() can't tell you the length.
Also, you failed to account for element size. The following should work, though, for arrays of static size:
if (len > (sizeof(buf) / sizeof(buf[0]))
die_in_a_fire();
I don't understand why you have the bitwise negation operator in there. Also, len is a length, not a pointer type, so pointer format doesn't matter.
(
Log in to post comments)