Skip to content

Instantly share code, notes, and snippets.

Created October 12, 2012 10:20
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 anonymous/3878566 to your computer and use it in GitHub Desktop.
Save anonymous/3878566 to your computer and use it in GitHub Desktop.
stdin
void *av_x_if_null(const void *x, const void *y)
{
return (void *) (x ? x : y);
}
int foo[1];
#define av_x_if_null_warn(x,y) \
( \
foo[sizeof(*x)!=sizeof(*y)] = 42, \
av_x_if_null(x, y) \
)
int main(void)
{
int *a = 0;
char *b = 0;
int *i = av_x_if_null_warn(a, a); // fine
short *c = av_x_if_null_warn(a, b);
// foo.c: In function ‘main’:
// foo.c:18:13: warning: array subscript is above array bounds [-Warray-bounds]
return c ? 1 : 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment