[PATCH] fix integer truncation in hp2ps output

Nicholas Nethercote njn25 at cam.ac.uk
Fri Apr 2 08:22:59 EST 2004


Hi,

The following patch fixes a bug in hp2ps that causes silly numbers like

  84,762,122,-646

to appear in the heading.  The problem was that 'n' is (can be) a 64-bit
type, and converting to an int before doing the modulo gives rounding
errors.

The fix is courtesy of Ralf Wildenhues (Ralf.Wildenhues at gmx.de).

N


Index: massif/hp2ps/Utilities.c
===================================================================
RCS file: /home/kde/valgrind/massif/hp2ps/Utilities.c,v
retrieving revision 1.2
diff -u -r1.2 Utilities.c
--- massif/hp2ps/Utilities.c    15 Feb 2004 15:38:08 -0000      1.2
+++ massif/hp2ps/Utilities.c    2 Apr 2004 12:24:45 -0000
 @ -77,7 +77,7  @
         fprintf(fp, "%d", (int)n);
     } else {
         CommaPrint(fp, n / ONETHOUSAND);
-        fprintf(fp, ",%03d", (int)n % ONETHOUSAND);
+        fprintf(fp, ",%03d", (int)(n % ONETHOUSAND));
     }
 }


More information about the Glasgow-haskell-bugs mailing list