Blame SOURCES/gd-sa4.patch

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