Menu

#1 format error in cprof output when using numeric mode -n

open
nobody
None
5
2011-03-18
2011-03-18
Bob Walkup
No

I have found the character-mode tool "cprof" to be very useful, but there is a bug in summary.cc that results in a formatting error when using the -n option. The code in question is listed here:

if (display_percent()) widthcounts = 3;
else {
widthcounts = 1;
while (maxcount/=10) widthcounts++;
}

The problem is that maxcount was declared as a double, and double-precision numbers can be divided by 10 a large number of times (about 320 for systems that use IEEE 64-bit format) before the result will be zero ... and so the code above results in a very large number for "widthcounts" and hence a huge number of spaces in the printed output. This could be corrected by using the integer part of maxcount/10 in the while test:

while (maxcount/=10) widthcounts++; => while(int(maxcount/10)) widthcounts++;

Discussion


Log in to post a comment.

MongoDB Logo MongoDB