Created
September 12, 2014 08:32
-
-
Save cvubrugier/e2b72080ab344b9f1a15 to your computer and use it in GitHub Desktop.
Snippet from iscsi-test-cu.c that triggers a segfault when built with gcc 4.9
This file contains 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 <assert.h> | |
#include <ctype.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <stdio.h> | |
#include <unistd.h> | |
static int | |
add_tests(const char *testname_re) | |
{ | |
if (!testname_re) | |
printf("OK\n"); | |
else | |
assert(testname_re == NULL); | |
return 0; | |
} | |
static void parse_and_add_tests(char *testname_re); | |
static void parse_and_add_test(char *test) | |
{ | |
if (access(test, F_OK) == 0) { | |
/* Not executed because access(NULL, F_OK) returns -1 */ | |
FILE *fh; | |
char t[256]; | |
if ((fh = fopen(test, "r")) == NULL) | |
exit(1); | |
while (fgets(t, sizeof(t), fh) != NULL) { | |
while (1) { | |
int len = strlen(t); | |
if (len == 0) { | |
break; | |
} | |
if (!isprint(t[--len])) { | |
t[len] = 0; | |
continue; | |
} | |
break; | |
} | |
/* Commenting out this instruction makes the program work */ | |
parse_and_add_tests(t); | |
} | |
fclose(fh); | |
return; | |
} | |
if (add_tests(test) != 0) | |
exit(1); | |
} | |
static void parse_and_add_tests(char *testname_re) | |
{ | |
parse_and_add_test(testname_re); | |
} | |
int main(void) | |
{ | |
parse_and_add_tests(NULL); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment