apps/speed.c:2587: error: NULL_DEREFERENCE
  pointer `f` last assigned on line 2586 could be null and is dereferenced by call to `fgets()` at line 2587, column 16.
Showing all 36 steps of the trace


apps/speed.c:2546:1: start of procedure do_multi()
2544.   }
2545.   
2546. > static int do_multi(int multi)
2547.   {
2548.       int n;

apps/speed.c:2551:5: 
2549.       int fd[2];
2550.       int *fds;
2551. >     static char sep[] = ":";
2552.   
2553.       fds = malloc(multi * sizeof *fds);

apps/speed.c:2553:5: 
2551.       static char sep[] = ":";
2552.   
2553. >     fds = malloc(multi * sizeof *fds);
2554.       for (n = 0; n < multi; ++n) {
2555.           if (pipe(fd) == -1) {

apps/speed.c:2554:10: 
2552.   
2553.       fds = malloc(multi * sizeof *fds);
2554. >     for (n = 0; n < multi; ++n) {
2555.           if (pipe(fd) == -1) {
2556.               fprintf(stderr, "pipe failure\n");

apps/speed.c:2554:17: Loop condition is true. Entering loop body
2552.   
2553.       fds = malloc(multi * sizeof *fds);
2554.       for (n = 0; n < multi; ++n) {
                        ^
2555.           if (pipe(fd) == -1) {
2556.               fprintf(stderr, "pipe failure\n");

apps/speed.c:2555:13: Taking false branch
2553.       fds = malloc(multi * sizeof *fds);
2554.       for (n = 0; n < multi; ++n) {
2555.           if (pipe(fd) == -1) {
                    ^
2556.               fprintf(stderr, "pipe failure\n");
2557.               exit(1);

apps/speed.c:2559:9: 
2557.               exit(1);
2558.           }
2559. >         fflush(stdout);
2560.           fflush(stderr);
2561.           if (fork()) {

apps/speed.c:2560:9: 
2558.           }
2559.           fflush(stdout);
2560. >         fflush(stderr);
2561.           if (fork()) {
2562.               close(fd[1]);

apps/speed.c:2561:13: Taking true branch
2559.           fflush(stdout);
2560.           fflush(stderr);
2561.           if (fork()) {
                    ^
2562.               close(fd[1]);
2563.               fds[n] = fd[0];

apps/speed.c:2562:13: 
2560.           fflush(stderr);
2561.           if (fork()) {
2562. >             close(fd[1]);
2563.               fds[n] = fd[0];
2564.           } else {

apps/speed.c:2563:13: 
2561.           if (fork()) {
2562.               close(fd[1]);
2563. >             fds[n] = fd[0];
2564.           } else {
2565.               close(fd[0]);

apps/speed.c:2577:9: 
2575.               return 0;
2576.           }
2577. >         printf("Forked child %d\n", n);
2578.       }
2579.   

apps/speed.c:2554:28: 
2552.   
2553.       fds = malloc(multi * sizeof *fds);
2554. >     for (n = 0; n < multi; ++n) {
2555.           if (pipe(fd) == -1) {
2556.               fprintf(stderr, "pipe failure\n");

apps/speed.c:2554:17: Loop condition is true. Entering loop body
2552.   
2553.       fds = malloc(multi * sizeof *fds);
2554.       for (n = 0; n < multi; ++n) {
                        ^
2555.           if (pipe(fd) == -1) {
2556.               fprintf(stderr, "pipe failure\n");

apps/speed.c:2555:13: Taking false branch
2553.       fds = malloc(multi * sizeof *fds);
2554.       for (n = 0; n < multi; ++n) {
2555.           if (pipe(fd) == -1) {
                    ^
2556.               fprintf(stderr, "pipe failure\n");
2557.               exit(1);

apps/speed.c:2559:9: 
2557.               exit(1);
2558.           }
2559. >         fflush(stdout);
2560.           fflush(stderr);
2561.           if (fork()) {

apps/speed.c:2560:9: 
2558.           }
2559.           fflush(stdout);
2560. >         fflush(stderr);
2561.           if (fork()) {
2562.               close(fd[1]);

apps/speed.c:2561:13: Taking true branch
2559.           fflush(stdout);
2560.           fflush(stderr);
2561.           if (fork()) {
                    ^
2562.               close(fd[1]);
2563.               fds[n] = fd[0];

apps/speed.c:2562:13: 
2560.           fflush(stderr);
2561.           if (fork()) {
2562. >             close(fd[1]);
2563.               fds[n] = fd[0];
2564.           } else {

apps/speed.c:2563:13: 
2561.           if (fork()) {
2562.               close(fd[1]);
2563. >             fds[n] = fd[0];
2564.           } else {
2565.               close(fd[0]);

apps/speed.c:2577:9: 
2575.               return 0;
2576.           }
2577. >         printf("Forked child %d\n", n);
2578.       }
2579.   

apps/speed.c:2554:28: 
2552.   
2553.       fds = malloc(multi * sizeof *fds);
2554. >     for (n = 0; n < multi; ++n) {
2555.           if (pipe(fd) == -1) {
2556.               fprintf(stderr, "pipe failure\n");

apps/speed.c:2554:17: Loop condition is true. Entering loop body
2552.   
2553.       fds = malloc(multi * sizeof *fds);
2554.       for (n = 0; n < multi; ++n) {
                        ^
2555.           if (pipe(fd) == -1) {
2556.               fprintf(stderr, "pipe failure\n");

apps/speed.c:2555:13: Taking false branch
2553.       fds = malloc(multi * sizeof *fds);
2554.       for (n = 0; n < multi; ++n) {
2555.           if (pipe(fd) == -1) {
                    ^
2556.               fprintf(stderr, "pipe failure\n");
2557.               exit(1);

apps/speed.c:2559:9: 
2557.               exit(1);
2558.           }
2559. >         fflush(stdout);
2560.           fflush(stderr);
2561.           if (fork()) {

apps/speed.c:2560:9: 
2558.           }
2559.           fflush(stdout);
2560. >         fflush(stderr);
2561.           if (fork()) {
2562.               close(fd[1]);

apps/speed.c:2561:13: Taking true branch
2559.           fflush(stdout);
2560.           fflush(stderr);
2561.           if (fork()) {
                    ^
2562.               close(fd[1]);
2563.               fds[n] = fd[0];

apps/speed.c:2562:13: 
2560.           fflush(stderr);
2561.           if (fork()) {
2562. >             close(fd[1]);
2563.               fds[n] = fd[0];
2564.           } else {

apps/speed.c:2563:13: 
2561.           if (fork()) {
2562.               close(fd[1]);
2563. >             fds[n] = fd[0];
2564.           } else {
2565.               close(fd[0]);

apps/speed.c:2577:9: 
2575.               return 0;
2576.           }
2577. >         printf("Forked child %d\n", n);
2578.       }
2579.   

apps/speed.c:2554:28: 
2552.   
2553.       fds = malloc(multi * sizeof *fds);
2554. >     for (n = 0; n < multi; ++n) {
2555.           if (pipe(fd) == -1) {
2556.               fprintf(stderr, "pipe failure\n");

apps/speed.c:2554:17: Loop condition is false. Leaving loop
2552.   
2553.       fds = malloc(multi * sizeof *fds);
2554.       for (n = 0; n < multi; ++n) {
                        ^
2555.           if (pipe(fd) == -1) {
2556.               fprintf(stderr, "pipe failure\n");

apps/speed.c:2581:10: 
2579.   
2580.       /* for now, assume the pipe is long enough to take all the output */
2581. >     for (n = 0; n < multi; ++n) {
2582.           FILE *f;
2583.           char buf[1024];

apps/speed.c:2581:17: Loop condition is true. Entering loop body
2579.   
2580.       /* for now, assume the pipe is long enough to take all the output */
2581.       for (n = 0; n < multi; ++n) {
                        ^
2582.           FILE *f;
2583.           char buf[1024];

apps/speed.c:2586:9: 
2584.           char *p;
2585.   
2586. >         f = fdopen(fds[n], "r");
2587.           while (fgets(buf, sizeof buf, f)) {
2588.               p = strchr(buf, '\n');

apps/speed.c:2587:16: 
2585.   
2586.           f = fdopen(fds[n], "r");
2587. >         while (fgets(buf, sizeof buf, f)) {
2588.               p = strchr(buf, '\n');
2589.               if (p)

static int do_multi(int multi)
{
    int n;
    int fd[2];
    int *fds;
    static char sep[] = ":";
    fds = malloc(multi * sizeof *fds);
    for (n = 0; n < multi; ++n) {
        if (pipe(fd) == -1) {
            fprintf(stderr, "pipe failure\n");
            exit(1);
        }
        fflush(stdout);
        fflush(stderr);
        if (fork()) {
            close(fd[1]);
            fds[n] = fd[0];
        } else {
            close(fd[0]);
            close(1);
            if (dup(fd[1]) == -1) {
                fprintf(stderr, "dup failed\n");
                exit(1);
            }
            close(fd[1]);
            mr = 1;
            usertime = 0;
            free(fds);
            return 0;
        }
        printf("Forked child %d\n", n);
    }
    for (n = 0; n < multi; ++n) {
        FILE *f;
        char buf[1024];
        char *p;
        f = fdopen(fds[n], "r");
        while (fgets(buf, sizeof buf, f)) {
            p = strchr(buf, '\n');
            if (p)
                *p = '\0';
            if (buf[0] != '+') {
                fprintf(stderr, "Don't understand line '%s' from child %d\n",
                        buf, n);
                continue;
            }
            printf("Got: %s from %d\n", buf, n);
            if (!strncmp(buf, "+F:", 3)) {
                int alg;
                int j;
                p = buf + 3;
                alg = atoi(sstrsep(&p, sep));
                sstrsep(&p, sep);
                for (j = 0; j < SIZE_NUM; ++j)
                    results[alg][j] += atof(sstrsep(&p, sep));
            } else if (!strncmp(buf, "+F2:", 4)) {
                int k;
                double d;
                p = buf + 4;
                k = atoi(sstrsep(&p, sep));
                sstrsep(&p, sep);
                d = atof(sstrsep(&p, sep));
                if (n)
                    rsa_results[k][0] = 1 / (1 / rsa_results[k][0] + 1 / d);
                else
                    rsa_results[k][0] = d;
                d = atof(sstrsep(&p, sep));
                if (n)
                    rsa_results[k][1] = 1 / (1 / rsa_results[k][1] + 1 / d);
                else
                    rsa_results[k][1] = d;
            } else if (!strncmp(buf, "+F2:", 4)) {
                int k;
                double d;
                p = buf + 4;
                k = atoi(sstrsep(&p, sep));
                sstrsep(&p, sep);
                d = atof(sstrsep(&p, sep));
                if (n)
                    rsa_results[k][0] = 1 / (1 / rsa_results[k][0] + 1 / d);
                else
                    rsa_results[k][0] = d;
                d = atof(sstrsep(&p, sep));
                if (n)
                    rsa_results[k][1] = 1 / (1 / rsa_results[k][1] + 1 / d);
                else
                    rsa_results[k][1] = d;
            }
# ifndef OPENSSL_NO_DSA
            else if (!strncmp(buf, "+F3:", 4)) {
                int k;
                double d;
                p = buf + 4;
                k = atoi(sstrsep(&p, sep));
                sstrsep(&p, sep);
                d = atof(sstrsep(&p, sep));
                if (n)
                    dsa_results[k][0] = 1 / (1 / dsa_results[k][0] + 1 / d);
                else
                    dsa_results[k][0] = d;
                d = atof(sstrsep(&p, sep));
                if (n)
                    dsa_results[k][1] = 1 / (1 / dsa_results[k][1] + 1 / d);
                else
                    dsa_results[k][1] = d;
            }
# endif
# ifndef OPENSSL_NO_EC
            else if (!strncmp(buf, "+F4:", 4)) {
                int k;
                double d;
                p = buf + 4;
                k = atoi(sstrsep(&p, sep));
                sstrsep(&p, sep);
                d = atof(sstrsep(&p, sep));
                if (n)
                    ecdsa_results[k][0] =
                        1 / (1 / ecdsa_results[k][0] + 1 / d);
                else
                    ecdsa_results[k][0] = d;
                d = atof(sstrsep(&p, sep));
                if (n)
                    ecdsa_results[k][1] =
                        1 / (1 / ecdsa_results[k][1] + 1 / d);
                else
                    ecdsa_results[k][1] = d;
            }
            else if (!strncmp(buf, "+F5:", 4)) {
                int k;
                double d;
                p = buf + 4;
                k = atoi(sstrsep(&p, sep));
                sstrsep(&p, sep);
                d = atof(sstrsep(&p, sep));
                if (n)
                    ecdh_results[k][0] = 1 / (1 / ecdh_results[k][0] + 1 / d);
                else
                    ecdh_results[k][0] = d;
            }
# endif
            else if (!strncmp(buf, "+H:", 3)) {
            } else
                fprintf(stderr, "Unknown type '%s' from child %d\n", buf, n);
        }
        fclose(f);
    }
    free(fds);
    return 1;
}
['static int do_multi(int multi)\n{\n    int n;\n    int fd[2];\n    int *fds;\n    static char sep[] = ":";\n    fds = malloc(multi * sizeof *fds);\n    for (n = 0; n < multi; ++n) {\n        if (pipe(fd) == -1) {\n            fprintf(stderr, "pipe failure\\n");\n            exit(1);\n        }\n        fflush(stdout);\n        fflush(stderr);\n        if (fork()) {\n            close(fd[1]);\n            fds[n] = fd[0];\n        } else {\n            close(fd[0]);\n            close(1);\n            if (dup(fd[1]) == -1) {\n                fprintf(stderr, "dup failed\\n");\n                exit(1);\n            }\n            close(fd[1]);\n            mr = 1;\n            usertime = 0;\n            free(fds);\n            return 0;\n        }\n        printf("Forked child %d\\n", n);\n    }\n    for (n = 0; n < multi; ++n) {\n        FILE *f;\n        char buf[1024];\n        char *p;\n        f = fdopen(fds[n], "r");\n        while (fgets(buf, sizeof buf, f)) {\n            p = strchr(buf, \'\\n\');\n            if (p)\n                *p = \'\\0\';\n            if (buf[0] != \'+\') {\n                fprintf(stderr, "Don\'t understand line \'%s\' from child %d\\n",\n                        buf, n);\n                continue;\n            }\n            printf("Got: %s from %d\\n", buf, n);\n            if (!strncmp(buf, "+F:", 3)) {\n                int alg;\n                int j;\n                p = buf + 3;\n                alg = atoi(sstrsep(&p, sep));\n                sstrsep(&p, sep);\n                for (j = 0; j < SIZE_NUM; ++j)\n                    results[alg][j] += atof(sstrsep(&p, sep));\n            } else if (!strncmp(buf, "+F2:", 4)) {\n                int k;\n                double d;\n                p = buf + 4;\n                k = atoi(sstrsep(&p, sep));\n                sstrsep(&p, sep);\n                d = atof(sstrsep(&p, sep));\n                if (n)\n                    rsa_results[k][0] = 1 / (1 / rsa_results[k][0] + 1 / d);\n                else\n                    rsa_results[k][0] = d;\n                d = atof(sstrsep(&p, sep));\n                if (n)\n                    rsa_results[k][1] = 1 / (1 / rsa_results[k][1] + 1 / d);\n                else\n                    rsa_results[k][1] = d;\n            } else if (!strncmp(buf, "+F2:", 4)) {\n                int k;\n                double d;\n                p = buf + 4;\n                k = atoi(sstrsep(&p, sep));\n                sstrsep(&p, sep);\n                d = atof(sstrsep(&p, sep));\n                if (n)\n                    rsa_results[k][0] = 1 / (1 / rsa_results[k][0] + 1 / d);\n                else\n                    rsa_results[k][0] = d;\n                d = atof(sstrsep(&p, sep));\n                if (n)\n                    rsa_results[k][1] = 1 / (1 / rsa_results[k][1] + 1 / d);\n                else\n                    rsa_results[k][1] = d;\n            }\n# ifndef OPENSSL_NO_DSA\n            else if (!strncmp(buf, "+F3:", 4)) {\n                int k;\n                double d;\n                p = buf + 4;\n                k = atoi(sstrsep(&p, sep));\n                sstrsep(&p, sep);\n                d = atof(sstrsep(&p, sep));\n                if (n)\n                    dsa_results[k][0] = 1 / (1 / dsa_results[k][0] + 1 / d);\n                else\n                    dsa_results[k][0] = d;\n                d = atof(sstrsep(&p, sep));\n                if (n)\n                    dsa_results[k][1] = 1 / (1 / dsa_results[k][1] + 1 / d);\n                else\n                    dsa_results[k][1] = d;\n            }\n# endif\n# ifndef OPENSSL_NO_EC\n            else if (!strncmp(buf, "+F4:", 4)) {\n                int k;\n                double d;\n                p = buf + 4;\n                k = atoi(sstrsep(&p, sep));\n                sstrsep(&p, sep);\n                d = atof(sstrsep(&p, sep));\n                if (n)\n                    ecdsa_results[k][0] =\n                        1 / (1 / ecdsa_results[k][0] + 1 / d);\n                else\n                    ecdsa_results[k][0] = d;\n                d = atof(sstrsep(&p, sep));\n                if (n)\n                    ecdsa_results[k][1] =\n                        1 / (1 / ecdsa_results[k][1] + 1 / d);\n                else\n                    ecdsa_results[k][1] = d;\n            }\n            else if (!strncmp(buf, "+F5:", 4)) {\n                int k;\n                double d;\n                p = buf + 4;\n                k = atoi(sstrsep(&p, sep));\n                sstrsep(&p, sep);\n                d = atof(sstrsep(&p, sep));\n                if (n)\n                    ecdh_results[k][0] = 1 / (1 / ecdh_results[k][0] + 1 / d);\n                else\n                    ecdh_results[k][0] = d;\n            }\n# endif\n            else if (!strncmp(buf, "+H:", 3)) {\n            } else\n                fprintf(stderr, "Unknown type \'%s\' from child %d\\n", buf, n);\n        }\n        fclose(f);\n    }\n    free(fds);\n    return 1;\n}']