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


apps/speed.c:2637:1: start of procedure do_multi()
2635.       }
2636.   
2637. > static int do_multi(int multi)
2638.   	{
2639.   	int n;

apps/speed.c:2642:2: 
2640.   	int fd[2];
2641.   	int *fds;
2642. > 	static char sep[]=":";
2643.   
2644.   	fds=malloc(multi*sizeof *fds);

apps/speed.c:2644:2: 
2642.   	static char sep[]=":";
2643.   
2644. > 	fds=malloc(multi*sizeof *fds);
2645.   	for(n=0 ; n < multi ; ++n)
2646.   		{

apps/speed.c:2645:6: 
2643.   
2644.   	fds=malloc(multi*sizeof *fds);
2645. > 	for(n=0 ; n < multi ; ++n)
2646.   		{
2647.   		if (pipe(fd) == -1)

apps/speed.c:2645:12: Loop condition is true. Entering loop body
2643.   
2644.   	fds=malloc(multi*sizeof *fds);
2645.   	for(n=0 ; n < multi ; ++n)
                   ^
2646.   		{
2647.   		if (pipe(fd) == -1)

apps/speed.c:2647:7: Taking false branch
2645.   	for(n=0 ; n < multi ; ++n)
2646.   		{
2647.   		if (pipe(fd) == -1)
              ^
2648.   			{
2649.   			fprintf(stderr, "pipe failure\n");

apps/speed.c:2652:3: 
2650.   			exit(1);
2651.   			}
2652. > 		fflush(stdout);
2653.   		fflush(stderr);
2654.   		if(fork())

apps/speed.c:2653:3: 
2651.   			}
2652.   		fflush(stdout);
2653. > 		fflush(stderr);
2654.   		if(fork())
2655.   			{

apps/speed.c:2654:6: Taking true branch
2652.   		fflush(stdout);
2653.   		fflush(stderr);
2654.   		if(fork())
             ^
2655.   			{
2656.   			close(fd[1]);

apps/speed.c:2656:4: 
2654.   		if(fork())
2655.   			{
2656. > 			close(fd[1]);
2657.   			fds[n]=fd[0];
2658.   			}

apps/speed.c:2657:4: 
2655.   			{
2656.   			close(fd[1]);
2657. > 			fds[n]=fd[0];
2658.   			}
2659.   		else

apps/speed.c:2674:3: 
2672.   			return 0;
2673.   			}
2674. > 		printf("Forked child %d\n",n);
2675.   		}
2676.   

apps/speed.c:2645:24: 
2643.   
2644.   	fds=malloc(multi*sizeof *fds);
2645. > 	for(n=0 ; n < multi ; ++n)
2646.   		{
2647.   		if (pipe(fd) == -1)

apps/speed.c:2645:12: Loop condition is true. Entering loop body
2643.   
2644.   	fds=malloc(multi*sizeof *fds);
2645.   	for(n=0 ; n < multi ; ++n)
                   ^
2646.   		{
2647.   		if (pipe(fd) == -1)

apps/speed.c:2647:7: Taking false branch
2645.   	for(n=0 ; n < multi ; ++n)
2646.   		{
2647.   		if (pipe(fd) == -1)
              ^
2648.   			{
2649.   			fprintf(stderr, "pipe failure\n");

apps/speed.c:2652:3: 
2650.   			exit(1);
2651.   			}
2652. > 		fflush(stdout);
2653.   		fflush(stderr);
2654.   		if(fork())

apps/speed.c:2653:3: 
2651.   			}
2652.   		fflush(stdout);
2653. > 		fflush(stderr);
2654.   		if(fork())
2655.   			{

apps/speed.c:2654:6: Taking true branch
2652.   		fflush(stdout);
2653.   		fflush(stderr);
2654.   		if(fork())
             ^
2655.   			{
2656.   			close(fd[1]);

apps/speed.c:2656:4: 
2654.   		if(fork())
2655.   			{
2656. > 			close(fd[1]);
2657.   			fds[n]=fd[0];
2658.   			}

apps/speed.c:2657:4: 
2655.   			{
2656.   			close(fd[1]);
2657. > 			fds[n]=fd[0];
2658.   			}
2659.   		else

apps/speed.c:2674:3: 
2672.   			return 0;
2673.   			}
2674. > 		printf("Forked child %d\n",n);
2675.   		}
2676.   

apps/speed.c:2645:24: 
2643.   
2644.   	fds=malloc(multi*sizeof *fds);
2645. > 	for(n=0 ; n < multi ; ++n)
2646.   		{
2647.   		if (pipe(fd) == -1)

apps/speed.c:2645:12: Loop condition is true. Entering loop body
2643.   
2644.   	fds=malloc(multi*sizeof *fds);
2645.   	for(n=0 ; n < multi ; ++n)
                   ^
2646.   		{
2647.   		if (pipe(fd) == -1)

apps/speed.c:2647:7: Taking false branch
2645.   	for(n=0 ; n < multi ; ++n)
2646.   		{
2647.   		if (pipe(fd) == -1)
              ^
2648.   			{
2649.   			fprintf(stderr, "pipe failure\n");

apps/speed.c:2652:3: 
2650.   			exit(1);
2651.   			}
2652. > 		fflush(stdout);
2653.   		fflush(stderr);
2654.   		if(fork())

apps/speed.c:2653:3: 
2651.   			}
2652.   		fflush(stdout);
2653. > 		fflush(stderr);
2654.   		if(fork())
2655.   			{

apps/speed.c:2654:6: Taking true branch
2652.   		fflush(stdout);
2653.   		fflush(stderr);
2654.   		if(fork())
             ^
2655.   			{
2656.   			close(fd[1]);

apps/speed.c:2656:4: 
2654.   		if(fork())
2655.   			{
2656. > 			close(fd[1]);
2657.   			fds[n]=fd[0];
2658.   			}

apps/speed.c:2657:4: 
2655.   			{
2656.   			close(fd[1]);
2657. > 			fds[n]=fd[0];
2658.   			}
2659.   		else

apps/speed.c:2674:3: 
2672.   			return 0;
2673.   			}
2674. > 		printf("Forked child %d\n",n);
2675.   		}
2676.   

apps/speed.c:2645:24: 
2643.   
2644.   	fds=malloc(multi*sizeof *fds);
2645. > 	for(n=0 ; n < multi ; ++n)
2646.   		{
2647.   		if (pipe(fd) == -1)

apps/speed.c:2645:12: Loop condition is false. Leaving loop
2643.   
2644.   	fds=malloc(multi*sizeof *fds);
2645.   	for(n=0 ; n < multi ; ++n)
                   ^
2646.   		{
2647.   		if (pipe(fd) == -1)

apps/speed.c:2678:6: 
2676.   
2677.   	/* for now, assume the pipe is long enough to take all the output */
2678. > 	for(n=0 ; n < multi ; ++n)
2679.   		{
2680.   		FILE *f;

apps/speed.c:2678:12: Loop condition is true. Entering loop body
2676.   
2677.   	/* for now, assume the pipe is long enough to take all the output */
2678.   	for(n=0 ; n < multi ; ++n)
                   ^
2679.   		{
2680.   		FILE *f;

apps/speed.c:2684:3: 
2682.   		char *p;
2683.   
2684. > 		f=fdopen(fds[n],"r");
2685.   		while(fgets(buf,sizeof buf,f))
2686.   			{

apps/speed.c:2685:9: 
2683.   
2684.   		f=fdopen(fds[n],"r");
2685. > 		while(fgets(buf,sizeof buf,f))
2686.   			{
2687.   			p=strchr(buf,'\n');

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\t{\n\tint n;\n\tint fd[2];\n\tint *fds;\n\tstatic char sep[]=":";\n\tfds=malloc(multi*sizeof *fds);\n\tfor(n=0 ; n < multi ; ++n)\n\t\t{\n\t\tif (pipe(fd) == -1)\n\t\t\t{\n\t\t\tfprintf(stderr, "pipe failure\\n");\n\t\t\texit(1);\n\t\t\t}\n\t\tfflush(stdout);\n\t\tfflush(stderr);\n\t\tif(fork())\n\t\t\t{\n\t\t\tclose(fd[1]);\n\t\t\tfds[n]=fd[0];\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tclose(fd[0]);\n\t\t\tclose(1);\n\t\t\tif (dup(fd[1]) == -1)\n\t\t\t\t{\n\t\t\t\tfprintf(stderr, "dup failed\\n");\n\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\tclose(fd[1]);\n\t\t\tmr=1;\n\t\t\tusertime=0;\n\t\t\tfree(fds);\n\t\t\treturn 0;\n\t\t\t}\n\t\tprintf("Forked child %d\\n",n);\n\t\t}\n\tfor(n=0 ; n < multi ; ++n)\n\t\t{\n\t\tFILE *f;\n\t\tchar buf[1024];\n\t\tchar *p;\n\t\tf=fdopen(fds[n],"r");\n\t\twhile(fgets(buf,sizeof buf,f))\n\t\t\t{\n\t\t\tp=strchr(buf,\'\\n\');\n\t\t\tif(p)\n\t\t\t\t*p=\'\\0\';\n\t\t\tif(buf[0] != \'+\')\n\t\t\t\t{\n\t\t\t\tfprintf(stderr,"Don\'t understand line \'%s\' from child %d\\n",\n\t\t\t\t\t\tbuf,n);\n\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\tprintf("Got: %s from %d\\n",buf,n);\n\t\t\tif(!strncmp(buf,"+F:",3))\n\t\t\t\t{\n\t\t\t\tint alg;\n\t\t\t\tint j;\n\t\t\t\tp=buf+3;\n\t\t\t\talg=atoi(sstrsep(&p,sep));\n\t\t\t\tsstrsep(&p,sep);\n\t\t\t\tfor(j=0 ; j < SIZE_NUM ; ++j)\n\t\t\t\t\tresults[alg][j]+=atof(sstrsep(&p,sep));\n\t\t\t\t}\n\t\t\telse if(!strncmp(buf,"+F2:",4))\n\t\t\t\t{\n\t\t\t\tint k;\n\t\t\t\tdouble d;\n\t\t\t\tp=buf+4;\n\t\t\t\tk=atoi(sstrsep(&p,sep));\n\t\t\t\tsstrsep(&p,sep);\n\t\t\t\td=atof(sstrsep(&p,sep));\n\t\t\t\tif(n)\n\t\t\t\t\trsa_results[k][0]=1/(1/rsa_results[k][0]+1/d);\n\t\t\t\telse\n\t\t\t\t\trsa_results[k][0]=d;\n\t\t\t\td=atof(sstrsep(&p,sep));\n\t\t\t\tif(n)\n\t\t\t\t\trsa_results[k][1]=1/(1/rsa_results[k][1]+1/d);\n\t\t\t\telse\n\t\t\t\t\trsa_results[k][1]=d;\n\t\t\t\t}\n\t\t\telse if(!strncmp(buf,"+F2:",4))\n\t\t\t\t{\n\t\t\t\tint k;\n\t\t\t\tdouble d;\n\t\t\t\tp=buf+4;\n\t\t\t\tk=atoi(sstrsep(&p,sep));\n\t\t\t\tsstrsep(&p,sep);\n\t\t\t\td=atof(sstrsep(&p,sep));\n\t\t\t\tif(n)\n\t\t\t\t\trsa_results[k][0]=1/(1/rsa_results[k][0]+1/d);\n\t\t\t\telse\n\t\t\t\t\trsa_results[k][0]=d;\n\t\t\t\td=atof(sstrsep(&p,sep));\n\t\t\t\tif(n)\n\t\t\t\t\trsa_results[k][1]=1/(1/rsa_results[k][1]+1/d);\n\t\t\t\telse\n\t\t\t\t\trsa_results[k][1]=d;\n\t\t\t\t}\n#ifndef OPENSSL_NO_DSA\n\t\t\telse if(!strncmp(buf,"+F3:",4))\n\t\t\t\t{\n\t\t\t\tint k;\n\t\t\t\tdouble d;\n\t\t\t\tp=buf+4;\n\t\t\t\tk=atoi(sstrsep(&p,sep));\n\t\t\t\tsstrsep(&p,sep);\n\t\t\t\td=atof(sstrsep(&p,sep));\n\t\t\t\tif(n)\n\t\t\t\t\tdsa_results[k][0]=1/(1/dsa_results[k][0]+1/d);\n\t\t\t\telse\n\t\t\t\t\tdsa_results[k][0]=d;\n\t\t\t\td=atof(sstrsep(&p,sep));\n\t\t\t\tif(n)\n\t\t\t\t\tdsa_results[k][1]=1/(1/dsa_results[k][1]+1/d);\n\t\t\t\telse\n\t\t\t\t\tdsa_results[k][1]=d;\n\t\t\t\t}\n#endif\n#ifndef OPENSSL_NO_ECDSA\n\t\t\telse if(!strncmp(buf,"+F4:",4))\n\t\t\t\t{\n\t\t\t\tint k;\n\t\t\t\tdouble d;\n\t\t\t\tp=buf+4;\n\t\t\t\tk=atoi(sstrsep(&p,sep));\n\t\t\t\tsstrsep(&p,sep);\n\t\t\t\td=atof(sstrsep(&p,sep));\n\t\t\t\tif(n)\n\t\t\t\t\tecdsa_results[k][0]=1/(1/ecdsa_results[k][0]+1/d);\n\t\t\t\telse\n\t\t\t\t\tecdsa_results[k][0]=d;\n\t\t\t\td=atof(sstrsep(&p,sep));\n\t\t\t\tif(n)\n\t\t\t\t\tecdsa_results[k][1]=1/(1/ecdsa_results[k][1]+1/d);\n\t\t\t\telse\n\t\t\t\t\tecdsa_results[k][1]=d;\n\t\t\t\t}\n#endif\n#ifndef OPENSSL_NO_ECDH\n\t\t\telse if(!strncmp(buf,"+F5:",4))\n\t\t\t\t{\n\t\t\t\tint k;\n\t\t\t\tdouble d;\n\t\t\t\tp=buf+4;\n\t\t\t\tk=atoi(sstrsep(&p,sep));\n\t\t\t\tsstrsep(&p,sep);\n\t\t\t\td=atof(sstrsep(&p,sep));\n\t\t\t\tif(n)\n\t\t\t\t\tecdh_results[k][0]=1/(1/ecdh_results[k][0]+1/d);\n\t\t\t\telse\n\t\t\t\t\tecdh_results[k][0]=d;\n\t\t\t\t}\n#endif\n\t\t\telse if(!strncmp(buf,"+H:",3))\n\t\t\t\t{\n\t\t\t\t}\n\t\t\telse\n\t\t\t\tfprintf(stderr,"Unknown type \'%s\' from child %d\\n",buf,n);\n\t\t\t}\n\t\tfclose(f);\n\t\t}\n\tfree(fds);\n\treturn 1;\n\t}']