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


apps/speed.c:2579:1: start of procedure do_multi()
2577.   }
2578.   
2579. > static int do_multi(int multi)
2580.   {
2581.       int n;

apps/speed.c:2584:5: 
2582.       int fd[2];
2583.       int *fds;
2584. >     static char sep[] = ":";
2585.   
2586.       fds = malloc(multi * sizeof *fds);

apps/speed.c:2586:5: 
2584.       static char sep[] = ":";
2585.   
2586. >     fds = malloc(multi * sizeof *fds);
2587.       for (n = 0; n < multi; ++n) {
2588.           if (pipe(fd) == -1) {

apps/speed.c:2587:10: 
2585.   
2586.       fds = malloc(multi * sizeof *fds);
2587. >     for (n = 0; n < multi; ++n) {
2588.           if (pipe(fd) == -1) {
2589.               fprintf(stderr, "pipe failure\n");

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

apps/speed.c:2588:13: Taking false branch
2586.       fds = malloc(multi * sizeof *fds);
2587.       for (n = 0; n < multi; ++n) {
2588.           if (pipe(fd) == -1) {
                    ^
2589.               fprintf(stderr, "pipe failure\n");
2590.               exit(1);

apps/speed.c:2592:9: 
2590.               exit(1);
2591.           }
2592. >         fflush(stdout);
2593.           fflush(stderr);
2594.           if (fork()) {

apps/speed.c:2593:9: 
2591.           }
2592.           fflush(stdout);
2593. >         fflush(stderr);
2594.           if (fork()) {
2595.               close(fd[1]);

apps/speed.c:2594:13: Taking true branch
2592.           fflush(stdout);
2593.           fflush(stderr);
2594.           if (fork()) {
                    ^
2595.               close(fd[1]);
2596.               fds[n] = fd[0];

apps/speed.c:2595:13: 
2593.           fflush(stderr);
2594.           if (fork()) {
2595. >             close(fd[1]);
2596.               fds[n] = fd[0];
2597.           } else {

apps/speed.c:2596:13: 
2594.           if (fork()) {
2595.               close(fd[1]);
2596. >             fds[n] = fd[0];
2597.           } else {
2598.               close(fd[0]);

apps/speed.c:2610:9: 
2608.               return 0;
2609.           }
2610. >         printf("Forked child %d\n", n);
2611.       }
2612.   

apps/speed.c:2587:28: 
2585.   
2586.       fds = malloc(multi * sizeof *fds);
2587. >     for (n = 0; n < multi; ++n) {
2588.           if (pipe(fd) == -1) {
2589.               fprintf(stderr, "pipe failure\n");

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

apps/speed.c:2588:13: Taking false branch
2586.       fds = malloc(multi * sizeof *fds);
2587.       for (n = 0; n < multi; ++n) {
2588.           if (pipe(fd) == -1) {
                    ^
2589.               fprintf(stderr, "pipe failure\n");
2590.               exit(1);

apps/speed.c:2592:9: 
2590.               exit(1);
2591.           }
2592. >         fflush(stdout);
2593.           fflush(stderr);
2594.           if (fork()) {

apps/speed.c:2593:9: 
2591.           }
2592.           fflush(stdout);
2593. >         fflush(stderr);
2594.           if (fork()) {
2595.               close(fd[1]);

apps/speed.c:2594:13: Taking true branch
2592.           fflush(stdout);
2593.           fflush(stderr);
2594.           if (fork()) {
                    ^
2595.               close(fd[1]);
2596.               fds[n] = fd[0];

apps/speed.c:2595:13: 
2593.           fflush(stderr);
2594.           if (fork()) {
2595. >             close(fd[1]);
2596.               fds[n] = fd[0];
2597.           } else {

apps/speed.c:2596:13: 
2594.           if (fork()) {
2595.               close(fd[1]);
2596. >             fds[n] = fd[0];
2597.           } else {
2598.               close(fd[0]);

apps/speed.c:2610:9: 
2608.               return 0;
2609.           }
2610. >         printf("Forked child %d\n", n);
2611.       }
2612.   

apps/speed.c:2587:28: 
2585.   
2586.       fds = malloc(multi * sizeof *fds);
2587. >     for (n = 0; n < multi; ++n) {
2588.           if (pipe(fd) == -1) {
2589.               fprintf(stderr, "pipe failure\n");

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

apps/speed.c:2588:13: Taking false branch
2586.       fds = malloc(multi * sizeof *fds);
2587.       for (n = 0; n < multi; ++n) {
2588.           if (pipe(fd) == -1) {
                    ^
2589.               fprintf(stderr, "pipe failure\n");
2590.               exit(1);

apps/speed.c:2592:9: 
2590.               exit(1);
2591.           }
2592. >         fflush(stdout);
2593.           fflush(stderr);
2594.           if (fork()) {

apps/speed.c:2593:9: 
2591.           }
2592.           fflush(stdout);
2593. >         fflush(stderr);
2594.           if (fork()) {
2595.               close(fd[1]);

apps/speed.c:2594:13: Taking true branch
2592.           fflush(stdout);
2593.           fflush(stderr);
2594.           if (fork()) {
                    ^
2595.               close(fd[1]);
2596.               fds[n] = fd[0];

apps/speed.c:2595:13: 
2593.           fflush(stderr);
2594.           if (fork()) {
2595. >             close(fd[1]);
2596.               fds[n] = fd[0];
2597.           } else {

apps/speed.c:2596:13: 
2594.           if (fork()) {
2595.               close(fd[1]);
2596. >             fds[n] = fd[0];
2597.           } else {
2598.               close(fd[0]);

apps/speed.c:2610:9: 
2608.               return 0;
2609.           }
2610. >         printf("Forked child %d\n", n);
2611.       }
2612.   

apps/speed.c:2587:28: 
2585.   
2586.       fds = malloc(multi * sizeof *fds);
2587. >     for (n = 0; n < multi; ++n) {
2588.           if (pipe(fd) == -1) {
2589.               fprintf(stderr, "pipe failure\n");

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

apps/speed.c:2614:10: 
2612.   
2613.       /* for now, assume the pipe is long enough to take all the output */
2614. >     for (n = 0; n < multi; ++n) {
2615.           FILE *f;
2616.           char buf[1024];

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

apps/speed.c:2619:9: 
2617.           char *p;
2618.   
2619. >         f = fdopen(fds[n], "r");
2620.           while (fgets(buf, sizeof buf, f)) {
2621.               p = strchr(buf, '\n');

apps/speed.c:2620:16: 
2618.   
2619.           f = fdopen(fds[n], "r");
2620. >         while (fgets(buf, sizeof buf, f)) {
2621.               p = strchr(buf, '\n');
2622.               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_ECDSA
            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;
            }
# endif
# ifndef OPENSSL_NO_ECDH
            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_ECDSA\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# endif\n# ifndef OPENSSL_NO_ECDH\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}']