What the hell GCC, again
-
Given
#include void swap(char foo[10][20], int i1, int i2)
{
if(i1 != i2)
{
char buff[20];
strcpy(buff, foo[i1]);
strcpy(foo[i1], foo[i2]);
strcpy(foo[i2], buff);
}
}when compiling with any optimization level above -O0, gcc complains about the second strcpy, saying
warning: ‘strcpy’ accessing 1 byte at offsets [-4611686018427387904, 4611686018427387903] and [-4611686018427387904, 4611686018427387903] overlaps 1 byte at offset [-4611686018427387904, 199] [-Wrestrict]
clang doesn't complain, even at -O3. I think what gcc is trying to tell me is that there is an issue when
i1 == i2
, even though there's a test to not swap ifi1 == i2
! If I replacei1, i2
with integer values (eg. 1, 2) the warning goes away! Weird. So far, the only way I've found to stop gcc from issuing a warning is to usememcpy
instead ofstrcpy
. Though both haverestrict
qualifiers to both arguments. Or maybe I'm missing something?"A little song, a little dance, a little seltzer down your pants" Chuckles the clown
-
Given
#include void swap(char foo[10][20], int i1, int i2)
{
if(i1 != i2)
{
char buff[20];
strcpy(buff, foo[i1]);
strcpy(foo[i1], foo[i2]);
strcpy(foo[i2], buff);
}
}when compiling with any optimization level above -O0, gcc complains about the second strcpy, saying
warning: ‘strcpy’ accessing 1 byte at offsets [-4611686018427387904, 4611686018427387903] and [-4611686018427387904, 4611686018427387903] overlaps 1 byte at offset [-4611686018427387904, 199] [-Wrestrict]
clang doesn't complain, even at -O3. I think what gcc is trying to tell me is that there is an issue when
i1 == i2
, even though there's a test to not swap ifi1 == i2
! If I replacei1, i2
with integer values (eg. 1, 2) the warning goes away! Weird. So far, the only way I've found to stop gcc from issuing a warning is to usememcpy
instead ofstrcpy
. Though both haverestrict
qualifiers to both arguments. Or maybe I'm missing something?"A little song, a little dance, a little seltzer down your pants" Chuckles the clown
GCC's warnings are often way too strict (and in some cases, outright wrong).
What do you get when you cross a joke with a rhetorical question? The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism. Do questions with multiple question marks annoy you???