afb210
The following issue has been found by Coverity static analysis tool.
afb210
afb210
Error: FORWARD_NULL (CWE-476): [#def5]
afb210
gd-2.0.35/gd_topal.c:1790: assign_zero: Assigning: "cquantize" = "NULL".
afb210
gd-2.0.35/gd_topal.c:1798: cond_false: Condition "cimP", taking false branch
afb210
gd-2.0.35/gd_topal.c:1804: else_branch: Reached else branch
afb210
gd-2.0.35/gd_topal.c:1807: cond_false: Condition "!oim->trueColor", taking false branch
afb210
gd-2.0.35/gd_topal.c:1815: if_end: End of if statement
afb210
gd-2.0.35/gd_topal.c:1819: cond_true: Condition "oim->transparent >= 0", taking true branch
afb210
gd-2.0.35/gd_topal.c:1823: cond_true: Condition "colorsWanted > maxColors", taking true branch
afb210
gd-2.0.35/gd_topal.c:1827: cond_true: Condition "!cimP", taking true branch
afb210
gd-2.0.35/gd_topal.c:1829: cond_false: Condition "!nim->pixels", taking false branch
afb210
gd-2.0.35/gd_topal.c:1833: if_end: End of if statement
afb210
gd-2.0.35/gd_topal.c:1834: cond_true: Condition "i < nim->sy", taking true branch
afb210
gd-2.0.35/gd_topal.c:1837: cond_true: Condition "!nim->pixels[i]", taking true branch
afb210
gd-2.0.35/gd_topal.c:1839: goto: Jumping to label "outOfMemory"
afb210
gd-2.0.35/gd_topal.c:2027: label: Reached label "outOfMemory"
afb210
gd-2.0.35/gd_topal.c:2028: cond_true: Condition "oim->trueColor", taking true branch
afb210
gd-2.0.35/gd_topal.c:2030: cond_true: Condition "!cimP", taking true branch
afb210
gd-2.0.35/gd_topal.c:2032: cond_true: Condition "i < nim->sy", taking true branch
afb210
gd-2.0.35/gd_topal.c:2034: cond_true: Condition "nim->pixels[i]", taking true branch
afb210
gd-2.0.35/gd_topal.c:2038: loop: Jumping back to the beginning of the loop
afb210
gd-2.0.35/gd_topal.c:2032: loop_begin: Jumped back to beginning of loop
afb210
gd-2.0.35/gd_topal.c:2032: cond_true: Condition "i < nim->sy", taking true branch
afb210
gd-2.0.35/gd_topal.c:2034: cond_true: Condition "nim->pixels[i]", taking true branch
afb210
gd-2.0.35/gd_topal.c:2038: loop: Jumping back to the beginning of the loop
afb210
gd-2.0.35/gd_topal.c:2032: loop_begin: Jumped back to beginning of loop
afb210
gd-2.0.35/gd_topal.c:2032: cond_false: Condition "i < nim->sy", taking false branch
afb210
gd-2.0.35/gd_topal.c:2038: loop_end: Reached end of loop
afb210
gd-2.0.35/gd_topal.c:2039: cond_true: Condition "nim->pixels", taking true branch
afb210
gd-2.0.35/gd_topal.c:2044: if_fallthrough: Falling through to end of if statement
afb210
gd-2.0.35/gd_topal.c:2047: if_end: End of if statement
afb210
gd-2.0.35/gd_topal.c:2050: cond_true: Condition "i < (32 /* 1 << 5 */)", taking true branch
afb210
gd-2.0.35/gd_topal.c:2052: var_deref_op: Dereferencing null pointer "cquantize".
afb210
afb210
Error: FORWARD_NULL (CWE-476): [#def6]
afb210
gd-2.0.35/gd_topal.c:1798: cond_true: Condition "cimP", taking true branch
afb210
gd-2.0.35/gd_topal.c:1801: cond_false: Condition "!nim", taking false branch
afb210
gd-2.0.35/gd_topal.c:1803: if_end: End of if statement
afb210
gd-2.0.35/gd_topal.c:1804: if_fallthrough: Falling through to end of if statement
afb210
gd-2.0.35/gd_topal.c:1806: if_end: End of if statement
afb210
gd-2.0.35/gd_topal.c:1807: cond_false: Condition "!oim->trueColor", taking false branch
afb210
gd-2.0.35/gd_topal.c:1815: if_end: End of if statement
afb210
gd-2.0.35/gd_topal.c:1819: cond_true: Condition "oim->transparent >= 0", taking true branch
afb210
gd-2.0.35/gd_topal.c:1823: cond_true: Condition "colorsWanted > maxColors", taking true branch
afb210
gd-2.0.35/gd_topal.c:1827: cond_false: Condition "!cimP", taking false branch
afb210
gd-2.0.35/gd_topal.c:1842: if_end: End of if statement
afb210
gd-2.0.35/gd_topal.c:1857: cond_true: Condition "!cquantize", taking true branch
afb210
gd-2.0.35/gd_topal.c:1857: var_compare_op: Comparing "cquantize" to null implies that "cquantize" might be null.
afb210
gd-2.0.35/gd_topal.c:1860: goto: Jumping to label "outOfMemory"
afb210
gd-2.0.35/gd_topal.c:2027: label: Reached label "outOfMemory"
afb210
gd-2.0.35/gd_topal.c:2028: cond_true: Condition "oim->trueColor", taking true branch
afb210
gd-2.0.35/gd_topal.c:2030: cond_false: Condition "!cimP", taking false branch
afb210
gd-2.0.35/gd_topal.c:2044: else_branch: Reached else branch
afb210
gd-2.0.35/gd_topal.c:2050: cond_true: Condition "i < (32 /* 1 << 5 */)", taking true branch
afb210
gd-2.0.35/gd_topal.c:2052: var_deref_op: Dereferencing null pointer "cquantize".
afb210
afb210
Error: FORWARD_NULL (CWE-476): [#def7]
afb210
gd-2.0.35/gd_topal.c:1798: cond_false: Condition "cimP", taking false branch
afb210
gd-2.0.35/gd_topal.c:1804: else_branch: Reached else branch
afb210
gd-2.0.35/gd_topal.c:1807: cond_false: Condition "!oim->trueColor", taking false branch
afb210
gd-2.0.35/gd_topal.c:1815: if_end: End of if statement
afb210
gd-2.0.35/gd_topal.c:1819: cond_true: Condition "oim->transparent >= 0", taking true branch
afb210
gd-2.0.35/gd_topal.c:1823: cond_true: Condition "colorsWanted > maxColors", taking true branch
afb210
gd-2.0.35/gd_topal.c:1827: cond_true: Condition "!cimP", taking true branch
afb210
gd-2.0.35/gd_topal.c:1829: cond_true: Condition "!nim->pixels", taking true branch
afb210
gd-2.0.35/gd_topal.c:1829: var_compare_op: Comparing "nim->pixels" to null implies that "nim->pixels" might be null.
afb210
gd-2.0.35/gd_topal.c:1832: goto: Jumping to label "outOfMemory"
afb210
gd-2.0.35/gd_topal.c:2027: label: Reached label "outOfMemory"
afb210
gd-2.0.35/gd_topal.c:2028: cond_true: Condition "oim->trueColor", taking true branch
afb210
gd-2.0.35/gd_topal.c:2030: cond_true: Condition "!cimP", taking true branch
afb210
gd-2.0.35/gd_topal.c:2032: cond_true: Condition "i < nim->sy", taking true branch
afb210
gd-2.0.35/gd_topal.c:2034: var_deref_op: Dereferencing null pointer "nim->pixels".
afb210
afb210
afb210
diff -up gd-2.0.35/gd_topal.c.sa4 gd-2.0.35/gd_topal.c
afb210
--- gd-2.0.35/gd_topal.c.sa4	2012-12-10 13:30:19.666363149 +0100
afb210
+++ gd-2.0.35/gd_topal.c	2012-12-10 13:37:50.550729535 +0100
afb210
@@ -2029,15 +2029,15 @@ outOfMemory:
afb210
     {
afb210
       if (!cimP) {
afb210
         /* On failure only */
afb210
-        for (i = 0; i < nim->sy; i++)
afb210
-  	{
afb210
-  	  if (nim->pixels[i])
afb210
-  	    {
afb210
-  	      gdFree (nim->pixels[i]);
afb210
-  	    }
afb210
-  	}
afb210
         if (nim->pixels)
afb210
   	{
afb210
+          for (i = 0; i < nim->sy; i++)
afb210
+  	  {
afb210
+  	    if (nim->pixels[i])
afb210
+  	      {
afb210
+  	        gdFree (nim->pixels[i]);
afb210
+  	      }
afb210
+  	  }
afb210
   	  gdFree (nim->pixels);
afb210
   	}
afb210
         nim->pixels = 0;
afb210
@@ -2047,27 +2047,27 @@ outOfMemory:
afb210
       }
afb210
     }
afb210
 success:
afb210
-  for (i = 0; i < HIST_C0_ELEMS; i++)
afb210
-    {
afb210
-      if (cquantize->histogram[i])
afb210
-	{
afb210
-	  gdFree (cquantize->histogram[i]);
afb210
-	}
afb210
-    }
afb210
-  if (cquantize->histogram)
afb210
-    {
afb210
-      gdFree (cquantize->histogram);
afb210
-    }
afb210
-  if (cquantize->fserrors)
afb210
-    {
afb210
-      gdFree (cquantize->fserrors);
afb210
-    }
afb210
-  if (cquantize->error_limiter_storage)
afb210
-    {
afb210
-      gdFree (cquantize->error_limiter_storage);
afb210
-    }
afb210
   if (cquantize)
afb210
     {
afb210
+      for (i = 0; i < HIST_C0_ELEMS; i++)
afb210
+        {
afb210
+          if (cquantize->histogram[i])
afb210
+	    {
afb210
+	      gdFree (cquantize->histogram[i]);
afb210
+	    }
afb210
+        }
afb210
+      if (cquantize->histogram)
afb210
+        {
afb210
+          gdFree (cquantize->histogram);
afb210
+        }
afb210
+      if (cquantize->fserrors)
afb210
+        {
afb210
+          gdFree (cquantize->fserrors);
afb210
+        }
afb210
+      if (cquantize->error_limiter_storage)
afb210
+        {
afb210
+          gdFree (cquantize->error_limiter_storage);
afb210
+        }
afb210
       gdFree (cquantize);
afb210
     }
afb210