Skip to content

Instantly share code, notes, and snippets.

@jerstlouis
Last active November 18, 2022 15:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jerstlouis/4a3c54e507a1f546b8d0830f642ff959 to your computer and use it in GitHub Desktop.
Save jerstlouis/4a3c54e507a1f546b8d0830f642ff959 to your computer and use it in GitHub Desktop.
// Compile with GCC 12.2.0 with -O2:
// warning: ‘strcpy’ offset 0 is out of the bounds [0, 0] [-Warray-bounds]
// no warning without -O2
extern char * strcpy(char * , const char * );
struct Inst { int bla; };
struct Class { int offset; };
static struct Class * classFoo; // No problem without static here
struct Foo
{
unsigned int a; // no problem if commented out
char bar[1024];
};
void setFoo(struct Inst * this, const char * value)
{
struct Foo * ptr = (struct Foo *)(this ? (((char *)this) + classFoo->offset) : 0);
strcpy(ptr->bar, value);
}
int main() { return 0; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment