diff options
author | Siddhesh Poyarekar <siddhesh@redhat.com> | 2013-02-26 14:24:40 +0530 |
---|---|---|
committer | Siddhesh Poyarekar <siddhesh@redhat.com> | 2013-02-26 14:24:40 +0530 |
commit | 7da6d9ed266105e0ebefd01a4b6bf08bf56257c3 (patch) | |
tree | 8845c65642dfc75c0799d90503128d4b67d1ab17 | |
parent | b7688c42e7cca0c24889f3a8f9b685783661fb24 (diff) | |
download | glibc-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.
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | NEWS | 2 | ||||
-rw-r--r-- | malloc/memusagestat.c | 97 |
3 files changed, 67 insertions, 38 deletions
diff --git a/ChangeLog b/ChangeLog index cbf4083f0d..ab829a5140 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2013-02-26 Siddhesh Poyarekar <siddhesh@redhat.com> + + [BZ #15160] + * malloc/memusagestat.c (main): Draw graphs for heap and stack + only if MAXSIZE_HEAP and MAXSIZE_STACK are non-zero. + 2013-02-26 Paul Eggert <eggert@cs.ucla.edu> * posix/regex_internal.h [__GNUC__ < 3 + (__GNUC_MINOR__ < 1]: diff --git a/NEWS b/NEWS index 783f957746..a4c5638e5b 100644 --- a/NEWS +++ b/NEWS @@ -11,7 +11,7 @@ Version 2.18 11561, 13951, 14142, 14200, 14317, 14327, 14496, 14920, 14964, 14981, 14982, 14985, 14994, 14996, 15003, 15006, 15020, 15023, 15036, 15054, - 15062, 15078. + 15062, 15078, 15160. * Add support for calling C++11 thread_local object destructors on thread and program exit. This needs compiler support for offloading C++11 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; } |