From: Nicholas Nethercote Date: Tue, 3 Sep 2002 15:09:06 +0000 (+0000) Subject: Avoiding division by zero errors that were truncating results for OpenOffice X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6d111933a6ba3c0b4574700e917069476a68506c;p=thirdparty%2Fvalgrind.git Avoiding division by zero errors that were truncating results for OpenOffice with --trace-children=yes. git-svn-id: svn://svn.valgrind.org/valgrind/branches/VALGRIND_1_0_BRANCH@864 --- diff --git a/vg_cachesim.c b/vg_cachesim.c index ea9cbce05f..8cfab99656 100644 --- a/vg_cachesim.c +++ b/vg_cachesim.c @@ -78,7 +78,7 @@ static void file_err() "error: can't open cache simulation output file `%s'", OUT_FILE ); VG_(message)(Vg_UserMsg, - " ... so detailed simulation results will be missing."); + " ... so simulation results will be missing."); } /*------------------------------------------------------------*/ @@ -1634,6 +1634,7 @@ void percentify(Int n, Int pow, Int field_width, char buf[]) VG_(sprintf)(buf, "%d.%d%%", n / pow, n % pow); len = VG_(strlen)(buf); space = field_width - len; + if (space < 0) space = 0; /* Allow for v. small field_width */ i = len; /* Right justify in field */ @@ -1670,6 +1671,7 @@ void VG_(do_cachesim_results)(Int client_argc, Char** client_argv) p = 100; + if (0 == Ir_total.a) Ir_total.a = 1; percentify(Ir_total.m1 * 100 * p / Ir_total.a, p, l1+1, buf1); VG_(message)(Vg_UserMsg, "I1 miss rate: %s", buf1); @@ -1703,6 +1705,9 @@ void VG_(do_cachesim_results)(Int client_argc, Char** client_argv) p = 10; + if (0 == D_total.a) D_total.a = 1; + if (0 == Dr_total.a) Dr_total.a = 1; + if (0 == Dw_total.a) Dw_total.a = 1; percentify( D_total.m1 * 100 * p / D_total.a, p, l1+1, buf1); percentify(Dr_total.m1 * 100 * p / Dr_total.a, p, l2+1, buf2); percentify(Dw_total.m1 * 100 * p / Dw_total.a, p, l3+1, buf3);