ce426f
commit 7da6d9ed266105e0ebefd01a4b6bf08bf56257c3
ce426f
Author: Siddhesh Poyarekar <siddhesh@redhat.com>
ce426f
Date:   Tue Feb 26 14:24:40 2013 +0530
ce426f
ce426f
    Fix FPE in memusagestat when malloc utilization is zero
ce426f
    
ce426f
    [BZ #15160]
ce426f
    
ce426f
    Draw graphs for heap and stack only if MAXSIZE_HEAP and MAXSIZE_STACK
ce426f
    are non-zero.
ce426f
ce426f
diff --git glibc-2.17-c758a686/malloc/memusagestat.c glibc-2.17-c758a686/malloc/memusagestat.c
ce426f
index f561e0d..7bbd009 100644
ce426f
--- glibc-2.17-c758a686/malloc/memusagestat.c
ce426f
+++ glibc-2.17-c758a686/malloc/memusagestat.c
ce426f
@@ -319,17 +319,26 @@ main (int argc, char *argv[])
ce426f
 
ce426f
   for (line = 1; line <= 3; ++line)
ce426f
     {
ce426f
-      cnt = ((ysize - 40) * (maxsize_heap / 4 * line / heap_scale)) /
ce426f
-	(maxsize_heap / heap_scale);
ce426f
-      gdImageDashedLine (im_out, 40, ysize - 20 - cnt, xsize - 40,
ce426f
-			 ysize - 20 - cnt, red);
ce426f
-      snprintf (buf, sizeof (buf), heap_format, maxsize_heap / 4 * line /
ce426f
-		heap_scale);
ce426f
-      gdImageString (im_out, gdFontSmall, 39 - strlen (buf) * 6,
ce426f
-		     ysize - 26 - cnt, (unsigned char *) buf, red);
ce426f
-
ce426f
-      cnt2 = ((ysize - 40) * (maxsize_stack / 4 * line / stack_scale)) /
ce426f
-	(maxsize_stack / stack_scale);
ce426f
+      if (maxsize_heap > 0)
ce426f
+	{
ce426f
+	  cnt = (((ysize - 40) * (maxsize_heap / 4 * line / heap_scale))
ce426f
+		 / (maxsize_heap / heap_scale));
ce426f
+	  gdImageDashedLine (im_out, 40, ysize - 20 - cnt, xsize - 40,
ce426f
+			     ysize - 20 - cnt, red);
ce426f
+	  snprintf (buf, sizeof (buf), heap_format,
ce426f
+		    maxsize_heap / 4 * line / heap_scale);
ce426f
+	  gdImageString (im_out, gdFontSmall, 39 - strlen (buf) * 6,
ce426f
+			 ysize - 26 - cnt, (unsigned char *) buf, red);
ce426f
+	}
ce426f
+      else
ce426f
+	cnt = 0;
ce426f
+
ce426f
+      if (maxsize_stack > 0)
ce426f
+	cnt2 = (((ysize - 40) * (maxsize_stack / 4 * line / stack_scale))
ce426f
+		/ (maxsize_stack / stack_scale));
ce426f
+      else
ce426f
+	cnt2 = 0;
ce426f
+
ce426f
       if (cnt != cnt2)
ce426f
 	gdImageDashedLine (im_out, 40, ysize - 20 - cnt2, xsize - 40,
ce426f
 			   ysize - 20 - cnt2, green);
ce426f
@@ -372,7 +381,7 @@ main (int argc, char *argv[])
ce426f
 				    ysize - 14, yellow);
ce426f
 	  previously = now;
ce426f
 
ce426f
-	  if (also_total)
ce426f
+	  if (also_total && maxsize_heap > 0)
ce426f
 	    {
ce426f
 	      size_t new3;
ce426f
 
ce426f
@@ -386,21 +395,27 @@ main (int argc, char *argv[])
ce426f
 	      last_total = new3;
ce426f
 	    }
ce426f
 
ce426f
-	  // assert (entry.heap <= maxsize_heap);
ce426f
-	  new[0] = (ysize - 20) - ((((unsigned long long int) (ysize - 40))
ce426f
-				    * entry.heap) / maxsize_heap);
ce426f
-	  gdImageLine (im_out, 40 + ((xsize - 80) * (cnt - 1)) / total,
ce426f
-		       last_heap, 40 + ((xsize - 80) * cnt) / total, new[0],
ce426f
-		       red);
ce426f
-	  last_heap = new[0];
ce426f
-
ce426f
-	  // assert (entry.stack <= maxsize_stack);
ce426f
-	  new[1] = (ysize - 20) - ((((unsigned long long int) (ysize - 40))
ce426f
-				    * entry.stack) / maxsize_stack);
ce426f
-	  gdImageLine (im_out, 40 + ((xsize - 80) * (cnt - 1)) / total,
ce426f
-		       last_stack, 40 + ((xsize - 80) * cnt) / total, new[1],
ce426f
-		       green);
ce426f
-	  last_stack = new[1];
ce426f
+	  if (maxsize_heap > 0)
ce426f
+	    {
ce426f
+	      new[0] = ((ysize - 20)
ce426f
+			- ((((unsigned long long int) (ysize - 40))
ce426f
+			    * entry.heap) / maxsize_heap));
ce426f
+	      gdImageLine (im_out, 40 + ((xsize - 80) * (cnt - 1)) / total,
ce426f
+			   last_heap, 40 + ((xsize - 80) * cnt) / total,
ce426f
+			   new[0], red);
ce426f
+	      last_heap = new[0];
ce426f
+	    }
ce426f
+
ce426f
+	  if (maxsize_stack > 0)
ce426f
+	    {
ce426f
+	      new[1] = ((ysize - 20)
ce426f
+			- ((((unsigned long long int) (ysize - 40))
ce426f
+			    * entry.stack) / maxsize_stack));
ce426f
+	      gdImageLine (im_out, 40 + ((xsize - 80) * (cnt - 1)) / total,
ce426f
+			   last_stack, 40 + ((xsize - 80) * cnt) / total,
ce426f
+			   new[1], green);
ce426f
+	      last_stack = new[1];
ce426f
+	    }
ce426f
 	}
ce426f
 
ce426f
       cnt = 0;
ce426f
@@ -448,7 +463,7 @@ main (int argc, char *argv[])
ce426f
 	      next_tick += MAX (1, total / 20);
ce426f
 	    }
ce426f
 
ce426f
-	  if (also_total)
ce426f
+	  if (also_total && maxsize_heap > 0)
ce426f
 	    {
ce426f
 	      size_t new3;
ce426f
 
ce426f
@@ -459,16 +474,24 @@ main (int argc, char *argv[])
ce426f
 	      last_total = new3;
ce426f
 	    }
ce426f
 
ce426f
-	  new[0] = (ysize - 20) - ((((unsigned long long int) (ysize - 40))
ce426f
-				    * entry.heap) / maxsize_heap);
ce426f
-	  gdImageLine (im_out, last_xpos, last_heap, xpos, new[0], red);
ce426f
-	  last_heap = new[0];
ce426f
+	  if (maxsize_heap > 0)
ce426f
+	    {
ce426f
+	      new[0] = ((ysize - 20)
ce426f
+			- ((((unsigned long long int) (ysize - 40))
ce426f
+			    * entry.heap) / maxsize_heap));
ce426f
+	      gdImageLine (im_out, last_xpos, last_heap, xpos, new[0], red);
ce426f
+	      last_heap = new[0];
ce426f
+	    }
ce426f
 
ce426f
-	  // assert (entry.stack <= maxsize_stack);
ce426f
-	  new[1] = (ysize - 20) - ((((unsigned long long int) (ysize - 40))
ce426f
-				    * entry.stack) / maxsize_stack);
ce426f
-	  gdImageLine (im_out, last_xpos, last_stack, xpos, new[1], green);
ce426f
-	  last_stack = new[1];
ce426f
+	  if (maxsize_stack > 0)
ce426f
+	    {
ce426f
+	      new[1] = ((ysize - 20)
ce426f
+			- ((((unsigned long long int) (ysize - 40))
ce426f
+			    * entry.stack) / maxsize_stack));
ce426f
+	      gdImageLine (im_out, last_xpos, last_stack, xpos, new[1],
ce426f
+			   green);
ce426f
+	      last_stack = new[1];
ce426f
+	    }
ce426f
 
ce426f
 	  last_xpos = xpos;
ce426f
 	}