Skip to content

Instantly share code, notes, and snippets.

@acdha
Last active September 8, 2015 15:41
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 acdha/c466e550e3edd5aa94b4 to your computer and use it in GitHub Desktop.
Save acdha/c466e550e3edd5aa94b4 to your computer and use it in GitHub Desktop.
Proof that https://twitter.com/MarcosBL/status/641110424193232897 will segfault in a program which passes “clang -Werror -Weverything -pedantic”
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <float.h>
static int isNegative(float arg) {
char *p = (char*) malloc(20);
sprintf(p, "%f", arg);
return p[0] == '-';
}
int main () {
float f = FLT_MAX;
printf("%f: %d", f, isNegative(f));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment