Last active
September 8, 2015 15:41
-
-
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”
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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