This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
[PATCH]: Prevent overflow in percentage computation
- From: Paul Hilfinger <hilfingr at gnat dot com>
- To: gdb-patches at sources dot redhat dot com
- Date: Sat, 20 Mar 2004 05:02:20 -0500 (EST)
- Subject: [PATCH]: Prevent overflow in percentage computation
The print_percentage function in bcache.c produces "interesting"
results when its first argument exceeds INT_MAX / 100. As a result,
'maint print stat' will report, shall we say, unduly pessimistic
results when memory savings exceed about 20MB. This patch performs
the percentage computation in floating point, avoiding the problem.
Committed as obvious.
Paul Hilfinger
ACT Inc.
2004-03-20 Paul Hilfinger <hilfingr@nile.gnat.com>
* bcache.c (print_percentage): Use floating point to avoid
incorrect results when portion*100 overflows.
Index: gdb/bcache.c
===================================================================
RCS file: /cvs/src/src/gdb/bcache.c,v
retrieving revision 1.14
diff -u -p -r1.14 bcache.c
--- gdb/bcache.c 9 Feb 2004 23:50:55 -0000 1.14
+++ gdb/bcache.c 20 Mar 2004 09:27:16 -0000
@@ -303,7 +303,7 @@ print_percentage (int portion, int total
if (total == 0)
printf_filtered ("(not applicable)\n");
else
- printf_filtered ("%3d%%\n", portion * 100 / total);
+ printf_filtered ("%3d%%\n", (int) (portion * 100.0 / total));
}