tools/tiffmedian.c:636: error: Null Dereference
  pointer `ptr` last assigned on line 634 could be null and is dereferenced at line 636, column 2.

tools/tiffmedian.c:623:1: start of procedure create_colorcell()
621. }
622. 
623. static C_cell *
     ^
624. create_colorcell(int red, int green, int blue)
625. {

tools/tiffmedian.c:631:2: 
629. 	register int tmp, dist, n;
630. 
631. 	ir = red >> (COLOR_DEPTH-C_DEPTH);
      ^
632. 	ig = green >> (COLOR_DEPTH-C_DEPTH);
633. 	ib = blue >> (COLOR_DEPTH-C_DEPTH);

tools/tiffmedian.c:632:2: 
630. 
631. 	ir = red >> (COLOR_DEPTH-C_DEPTH);
632. 	ig = green >> (COLOR_DEPTH-C_DEPTH);
      ^
633. 	ib = blue >> (COLOR_DEPTH-C_DEPTH);
634. 	ptr = (C_cell *)_TIFFmalloc(sizeof (C_cell));

tools/tiffmedian.c:633:2: 
631. 	ir = red >> (COLOR_DEPTH-C_DEPTH);
632. 	ig = green >> (COLOR_DEPTH-C_DEPTH);
633. 	ib = blue >> (COLOR_DEPTH-C_DEPTH);
      ^
634. 	ptr = (C_cell *)_TIFFmalloc(sizeof (C_cell));
635. 	*(ColorCells + ir*C_LEN*C_LEN + ig*C_LEN + ib) = ptr;

tools/tiffmedian.c:634:2: 
632. 	ig = green >> (COLOR_DEPTH-C_DEPTH);
633. 	ib = blue >> (COLOR_DEPTH-C_DEPTH);
634. 	ptr = (C_cell *)_TIFFmalloc(sizeof (C_cell));
      ^
635. 	*(ColorCells + ir*C_LEN*C_LEN + ig*C_LEN + ib) = ptr;
636. 	ptr->num_ents = 0;

libtiff/tif_unix.c:257:1: start of procedure _TIFFmalloc()
  255. #endif
  256. 
  257. void*
       ^
  258. _TIFFmalloc(tmsize_t s)
  259. {

libtiff/tif_unix.c:260:13: Taking false branch
  258. _TIFFmalloc(tmsize_t s)
  259. {
  260.         if (s == 0)
                   ^
  261.                 return ((void *) NULL);
  262. 

libtiff/tif_unix.c:263:2: 
  261.                 return ((void *) NULL);
  262. 
  263. 	return (malloc((size_t) s));
        ^
  264. }
  265. 

libtiff/tif_unix.c:264:1: return from a call to _TIFFmalloc
  262. 
  263. 	return (malloc((size_t) s));
  264. }
       ^
  265. 
  266. void

tools/tiffmedian.c:635:2: 
633. 	ib = blue >> (COLOR_DEPTH-C_DEPTH);
634. 	ptr = (C_cell *)_TIFFmalloc(sizeof (C_cell));
635. 	*(ColorCells + ir*C_LEN*C_LEN + ig*C_LEN + ib) = ptr;
      ^
636. 	ptr->num_ents = 0;
637. 

tools/tiffmedian.c:636:2: 
634. 	ptr = (C_cell *)_TIFFmalloc(sizeof (C_cell));
635. 	*(ColorCells + ir*C_LEN*C_LEN + ig*C_LEN + ib) = ptr;
636. 	ptr->num_ents = 0;
      ^
637. 
638. 	/*

static C_cell *
create_colorcell(int red, int green, int blue)
{
	register int ir, ig, ib, i;
	register C_cell *ptr;
	int mindist, next_n;
	register int tmp, dist, n;
	ir = red >> (COLOR_DEPTH-C_DEPTH);
	ig = green >> (COLOR_DEPTH-C_DEPTH);
	ib = blue >> (COLOR_DEPTH-C_DEPTH);
	ptr = (C_cell *)_TIFFmalloc(sizeof (C_cell));
	*(ColorCells + ir*C_LEN*C_LEN + ig*C_LEN + ib) = ptr;
	ptr->num_ents = 0;
	mindist = 99999999;
	for (i = 0; i < num_colors; ++i) {
		if (rm[i]>>(COLOR_DEPTH-C_DEPTH) != ir  ||
		    gm[i]>>(COLOR_DEPTH-C_DEPTH) != ig  ||
		    bm[i]>>(COLOR_DEPTH-C_DEPTH) != ib)
			continue;
		ptr->entries[ptr->num_ents][0] = i;
		ptr->entries[ptr->num_ents][1] = 0;
		++ptr->num_ents;
	        tmp = rm[i] - red;
	        if (tmp < (MAX_COLOR/C_LEN/2))
			tmp = MAX_COLOR/C_LEN-1 - tmp;
	        dist = tmp*tmp;
	        tmp = gm[i] - green;
	        if (tmp < (MAX_COLOR/C_LEN/2))
			tmp = MAX_COLOR/C_LEN-1 - tmp;
	        dist += tmp*tmp;
	        tmp = bm[i] - blue;
	        if (tmp < (MAX_COLOR/C_LEN/2))
			tmp = MAX_COLOR/C_LEN-1 - tmp;
	        dist += tmp*tmp;
	        if (dist < mindist)
			mindist = dist;
	}
	for (i = 0; i < num_colors; ++i) {
		if (rm[i] >> (COLOR_DEPTH-C_DEPTH) == ir  &&
		    gm[i] >> (COLOR_DEPTH-C_DEPTH) == ig  &&
		    bm[i] >> (COLOR_DEPTH-C_DEPTH) == ib)
			continue;
		dist = 0;
	        if ((tmp = red - rm[i]) > 0 ||
		    (tmp = rm[i] - (red + MAX_COLOR/C_LEN-1)) > 0 )
			dist += tmp*tmp;
	        if ((tmp = green - gm[i]) > 0 ||
		    (tmp = gm[i] - (green + MAX_COLOR/C_LEN-1)) > 0 )
			dist += tmp*tmp;
	        if ((tmp = blue - bm[i]) > 0 ||
		    (tmp = bm[i] - (blue + MAX_COLOR/C_LEN-1)) > 0 )
			dist += tmp*tmp;
	        if (dist < mindist) {
			ptr->entries[ptr->num_ents][0] = i;
			ptr->entries[ptr->num_ents][1] = dist;
			++ptr->num_ents;
	        }
	}
	for (n = ptr->num_ents - 1; n > 0; n = next_n) {
		next_n = 0;
		for (i = 0; i < n; ++i)
			if (ptr->entries[i][1] > ptr->entries[i+1][1]) {
				tmp = ptr->entries[i][0];
				ptr->entries[i][0] = ptr->entries[i+1][0];
				ptr->entries[i+1][0] = tmp;
				tmp = ptr->entries[i][1];
				ptr->entries[i][1] = ptr->entries[i+1][1];
				ptr->entries[i+1][1] = tmp;
				next_n = i;
		        }
	}
	return (ptr);
}
['static C_cell *\ncreate_colorcell(int red, int green, int blue)\n{\n\tregister int ir, ig, ib, i;\n\tregister C_cell *ptr;\n\tint mindist, next_n;\n\tregister int tmp, dist, n;\n\tir = red >> (COLOR_DEPTH-C_DEPTH);\n\tig = green >> (COLOR_DEPTH-C_DEPTH);\n\tib = blue >> (COLOR_DEPTH-C_DEPTH);\n\tptr = (C_cell *)_TIFFmalloc(sizeof (C_cell));\n\t*(ColorCells + ir*C_LEN*C_LEN + ig*C_LEN + ib) = ptr;\n\tptr->num_ents = 0;\n\tmindist = 99999999;\n\tfor (i = 0; i < num_colors; ++i) {\n\t\tif (rm[i]>>(COLOR_DEPTH-C_DEPTH) != ir  ||\n\t\t    gm[i]>>(COLOR_DEPTH-C_DEPTH) != ig  ||\n\t\t    bm[i]>>(COLOR_DEPTH-C_DEPTH) != ib)\n\t\t\tcontinue;\n\t\tptr->entries[ptr->num_ents][0] = i;\n\t\tptr->entries[ptr->num_ents][1] = 0;\n\t\t++ptr->num_ents;\n\t        tmp = rm[i] - red;\n\t        if (tmp < (MAX_COLOR/C_LEN/2))\n\t\t\ttmp = MAX_COLOR/C_LEN-1 - tmp;\n\t        dist = tmp*tmp;\n\t        tmp = gm[i] - green;\n\t        if (tmp < (MAX_COLOR/C_LEN/2))\n\t\t\ttmp = MAX_COLOR/C_LEN-1 - tmp;\n\t        dist += tmp*tmp;\n\t        tmp = bm[i] - blue;\n\t        if (tmp < (MAX_COLOR/C_LEN/2))\n\t\t\ttmp = MAX_COLOR/C_LEN-1 - tmp;\n\t        dist += tmp*tmp;\n\t        if (dist < mindist)\n\t\t\tmindist = dist;\n\t}\n\tfor (i = 0; i < num_colors; ++i) {\n\t\tif (rm[i] >> (COLOR_DEPTH-C_DEPTH) == ir  &&\n\t\t    gm[i] >> (COLOR_DEPTH-C_DEPTH) == ig  &&\n\t\t    bm[i] >> (COLOR_DEPTH-C_DEPTH) == ib)\n\t\t\tcontinue;\n\t\tdist = 0;\n\t        if ((tmp = red - rm[i]) > 0 ||\n\t\t    (tmp = rm[i] - (red + MAX_COLOR/C_LEN-1)) > 0 )\n\t\t\tdist += tmp*tmp;\n\t        if ((tmp = green - gm[i]) > 0 ||\n\t\t    (tmp = gm[i] - (green + MAX_COLOR/C_LEN-1)) > 0 )\n\t\t\tdist += tmp*tmp;\n\t        if ((tmp = blue - bm[i]) > 0 ||\n\t\t    (tmp = bm[i] - (blue + MAX_COLOR/C_LEN-1)) > 0 )\n\t\t\tdist += tmp*tmp;\n\t        if (dist < mindist) {\n\t\t\tptr->entries[ptr->num_ents][0] = i;\n\t\t\tptr->entries[ptr->num_ents][1] = dist;\n\t\t\t++ptr->num_ents;\n\t        }\n\t}\n\tfor (n = ptr->num_ents - 1; n > 0; n = next_n) {\n\t\tnext_n = 0;\n\t\tfor (i = 0; i < n; ++i)\n\t\t\tif (ptr->entries[i][1] > ptr->entries[i+1][1]) {\n\t\t\t\ttmp = ptr->entries[i][0];\n\t\t\t\tptr->entries[i][0] = ptr->entries[i+1][0];\n\t\t\t\tptr->entries[i+1][0] = tmp;\n\t\t\t\ttmp = ptr->entries[i][1];\n\t\t\t\tptr->entries[i][1] = ptr->entries[i+1][1];\n\t\t\t\tptr->entries[i+1][1] = tmp;\n\t\t\t\tnext_n = i;\n\t\t        }\n\t}\n\treturn (ptr);\n}', 'void*\n_TIFFmalloc(tmsize_t s)\n{\n        if (s == 0)\n                return ((void *) NULL);\n\treturn (malloc((size_t) s));\n}']