access off end of array
Posted Mar 24, 2013 0:46 UTC (Sun) by
pflugstad (subscriber, #224)
Parent article:
Regehr: GCC 4.8 Breaks Broken SPEC 2006 Benchmarks
Couldn't doing a read off the end of an array potentially cause a segfault? Depending on how the array was allocated? If so, seems to me like this is just buggy code, plain and simple.
I also think this code is confusing and poor coding style. Why even have dd? I think this code:
int d[16];
int SATD (void)
{
int satd = 0, k;
for ( k=0; k<16; k++ ) {
satd += (d[k] < 0 ? -d[k] : d[k]);
}
return satd;
}
is cleaner, easier to understand and maintain, and eliminates the bug. With any optimization at all, GCC should eliminate the repeated d[k] accesses so I would expect almost identical code and performance. Maybe I'm just missing something? Even if you leave dd in there, doing the assignment inside the block is cleaner and easier to understand than inside the for loop.
I also think that GCC using a undefined data access to essentially short circuit a for loop control variable is just busted - and it looks like they fixed this before the final GCC was actually released.
(
Log in to post comments)