about summary refs log tree commit diff
path: root/malloc
diff options
context:
space:
mode:
authorSiddhesh Poyarekar <siddhesh@redhat.com>2013-02-26 14:24:40 +0530
committerSiddhesh Poyarekar <siddhesh@redhat.com>2013-02-26 14:24:40 +0530
commit7da6d9ed266105e0ebefd01a4b6bf08bf56257c3 (patch)
tree8845c65642dfc75c0799d90503128d4b67d1ab17 /malloc
parentb7688c42e7cca0c24889f3a8f9b685783661fb24 (diff)
downloadglibc-7da6d9ed266105e0ebefd01a4b6bf08bf56257c3.tar.gz
glibc-7da6d9ed266105e0ebefd01a4b6bf08bf56257c3.tar.xz
glibc-7da6d9ed266105e0ebefd01a4b6bf08bf56257c3.zip
Fix FPE in memusagestat when malloc utilization is zero
[BZ #15160]

Draw graphs for heap and stack only if MAXSIZE_HEAP and MAXSIZE_STACK
are non-zero.
Diffstat (limited to 'malloc')
-rw-r--r--malloc/memusagestat.c97
1 files changed, 60 insertions, 37 deletions
diff --git a/malloc/memusagestat.c b/malloc/memusagestat.c
index f561e0dbbc..7bbd009967 100644
--- a/malloc/memusagestat.c
+++ b/malloc/memusagestat.c
@@ -319,17 +319,26 @@ main (int argc, char *argv[])
 
   for (line = 1; line <= 3; ++line)
     {
-      cnt = ((ysize - 40) * (maxsize_heap / 4 * line / heap_scale)) /
-	(maxsize_heap / heap_scale);
-      gdImageDashedLine (im_out, 40, ysize - 20 - cnt, xsize - 40,
-			 ysize - 20 - cnt, red);
-      snprintf (buf, sizeof (buf), heap_format, maxsize_heap / 4 * line /
-		heap_scale);
-      gdImageString (im_out, gdFontSmall, 39 - strlen (buf) * 6,
-		     ysize - 26 - cnt, (unsigned char *) buf, red);
-
-      cnt2 = ((ysize - 40) * (maxsize_stack / 4 * line / stack_scale)) /
-	(maxsize_stack / stack_scale);
+      if (maxsize_heap > 0)
+	{
+	  cnt = (((ysize - 40) * (maxsize_heap / 4 * line / heap_scale))
+		 / (maxsize_heap / heap_scale));
+	  gdImageDashedLine (im_out, 40, ysize - 20 - cnt, xsize - 40,
+			     ysize - 20 - cnt, red);
+	  snprintf (buf, sizeof (buf), heap_format,
+		    maxsize_heap / 4 * line / heap_scale);
+	  gdImageString (im_out, gdFontSmall, 39 - strlen (buf) * 6,
+			 ysize - 26 - cnt, (unsigned char *) buf, red);
+	}
+      else
+	cnt = 0;
+
+      if (maxsize_stack > 0)
+	cnt2 = (((ysize - 40) * (maxsize_stack / 4 * line / stack_scale))
+		/ (maxsize_stack / stack_scale));
+      else
+	cnt2 = 0;
+
       if (cnt != cnt2)
 	gdImageDashedLine (im_out, 40, ysize - 20 - cnt2, xsize - 40,
 			   ysize - 20 - cnt2, green);
@@ -372,7 +381,7 @@ main (int argc, char *argv[])
 				    ysize - 14, yellow);
 	  previously = now;
 
-	  if (also_total)
+	  if (also_total && maxsize_heap > 0)
 	    {
 	      size_t new3;
 
@@ -386,21 +395,27 @@ main (int argc, char *argv[])
 	      last_total = new3;
 	    }
 
-	  // assert (entry.heap <= maxsize_heap);
-	  new[0] = (ysize - 20) - ((((unsigned long long int) (ysize - 40))
-				    * entry.heap) / maxsize_heap);
-	  gdImageLine (im_out, 40 + ((xsize - 80) * (cnt - 1)) / total,
-		       last_heap, 40 + ((xsize - 80) * cnt) / total, new[0],
-		       red);
-	  last_heap = new[0];
-
-	  // assert (entry.stack <= maxsize_stack);
-	  new[1] = (ysize - 20) - ((((unsigned long long int) (ysize - 40))
-				    * entry.stack) / maxsize_stack);
-	  gdImageLine (im_out, 40 + ((xsize - 80) * (cnt - 1)) / total,
-		       last_stack, 40 + ((xsize - 80) * cnt) / total, new[1],
-		       green);
-	  last_stack = new[1];
+	  if (maxsize_heap > 0)
+	    {
+	      new[0] = ((ysize - 20)
+			- ((((unsigned long long int) (ysize - 40))
+			    * entry.heap) / maxsize_heap));
+	      gdImageLine (im_out, 40 + ((xsize - 80) * (cnt - 1)) / total,
+			   last_heap, 40 + ((xsize - 80) * cnt) / total,
+			   new[0], red);
+	      last_heap = new[0];
+	    }
+
+	  if (maxsize_stack > 0)
+	    {
+	      new[1] = ((ysize - 20)
+			- ((((unsigned long long int) (ysize - 40))
+			    * entry.stack) / maxsize_stack));
+	      gdImageLine (im_out, 40 + ((xsize - 80) * (cnt - 1)) / total,
+			   last_stack, 40 + ((xsize - 80) * cnt) / total,
+			   new[1], green);
+	      last_stack = new[1];
+	    }
 	}
 
       cnt = 0;
@@ -448,7 +463,7 @@ main (int argc, char *argv[])
 	      next_tick += MAX (1, total / 20);
 	    }
 
-	  if (also_total)
+	  if (also_total && maxsize_heap > 0)
 	    {
 	      size_t new3;
 
@@ -459,16 +474,24 @@ main (int argc, char *argv[])
 	      last_total = new3;
 	    }
 
-	  new[0] = (ysize - 20) - ((((unsigned long long int) (ysize - 40))
-				    * entry.heap) / maxsize_heap);
-	  gdImageLine (im_out, last_xpos, last_heap, xpos, new[0], red);
-	  last_heap = new[0];
+	  if (maxsize_heap > 0)
+	    {
+	      new[0] = ((ysize - 20)
+			- ((((unsigned long long int) (ysize - 40))
+			    * entry.heap) / maxsize_heap));
+	      gdImageLine (im_out, last_xpos, last_heap, xpos, new[0], red);
+	      last_heap = new[0];
+	    }
 
-	  // assert (entry.stack <= maxsize_stack);
-	  new[1] = (ysize - 20) - ((((unsigned long long int) (ysize - 40))
-				    * entry.stack) / maxsize_stack);
-	  gdImageLine (im_out, last_xpos, last_stack, xpos, new[1], green);
-	  last_stack = new[1];
+	  if (maxsize_stack > 0)
+	    {
+	      new[1] = ((ysize - 20)
+			- ((((unsigned long long int) (ysize - 40))
+			    * entry.stack) / maxsize_stack));
+	      gdImageLine (im_out, last_xpos, last_stack, xpos, new[1],
+			   green);
+	      last_stack = new[1];
+	    }
 
 	  last_xpos = xpos;
 	}