Skip to content

Instantly share code, notes, and snippets.

@cvubrugier
Created September 12, 2014 08:32
Show Gist options
  • Save cvubrugier/e2b72080ab344b9f1a15 to your computer and use it in GitHub Desktop.
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
#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