Author: njn Date: 2007-10-11 07:51:47 +0100 (Thu, 11 Oct 2007) New Revision: 6978
Log: Fix an overflow bug in threshold testing. Add a test for it. Added: branches/MASSIF2/massif/tests/big-alloc.c branches/MASSIF2/massif/tests/big-alloc.post.exp branches/MASSIF2/massif/tests/big-alloc.stderr.exp branches/MASSIF2/massif/tests/big-alloc.vgtest Modified: branches/MASSIF2/massif/ms_main.c branches/MASSIF2/massif/tests/Makefile.am Modified: branches/MASSIF2/massif/ms_main.c =================================================================== --- branches/MASSIF2/massif/ms_main.c 2007-10-11 06:37:07 UTC (rev 6977) +++ branches/MASSIF2/massif/ms_main.c 2007-10-11 06:51:47 UTC (rev 6978) @@ -1698,7 +1698,8 @@ tl_assert(xpt->curr_szB <= curr_total_szB); return xpt == alloc_xpt || 0 == clo_threshold || (0 != curr_total_szB && - xpt->curr_szB * 10000 / curr_total_szB >= clo_threshold); + // Nb: 10000 is a ULong to avoid possible overflow problems. + xpt->curr_szB * 10000ULL / curr_total_szB >= clo_threshold); } static void pp_snapshot_XPt(Int fd, XPt* xpt, Int depth, Char* depth_str, Modified: branches/MASSIF2/massif/tests/Makefile.am =================================================================== --- branches/MASSIF2/massif/tests/Makefile.am 2007-10-11 06:37:07 UTC (rev 6977) +++ branches/MASSIF2/massif/tests/Makefile.am 2007-10-11 06:51:47 UTC (rev 6978) @@ -8,6 +8,7 @@ alloc-fns-A.post.exp alloc-fns-A.stderr.exp alloc-fns-A.vgtest \ alloc-fns-B.post.exp alloc-fns-B.stderr.exp alloc-fns-B.vgtest \ basic.post.exp basic.stderr.exp basic.vgtest \ + big-alloc.post.exp big-alloc.stderr.exp big-alloc.vgtest \ deep-A.post.exp deep-A.stderr.exp deep-A.vgtest \ deep-B.post.exp deep-B.stderr.exp deep-B.vgtest \ deep-C.post.exp deep-C.stderr.exp deep-C.vgtest \ @@ -43,6 +44,7 @@ check_PROGRAMS = \ alloc-fns \ basic \ + big-alloc \ culling1 culling2 \ custom_alloc \ deep \ Added: branches/MASSIF2/massif/tests/big-alloc.c =================================================================== --- branches/MASSIF2/massif/tests/big-alloc.c (rev 0) +++ branches/MASSIF2/massif/tests/big-alloc.c 2007-10-11 06:51:47 UTC (rev 6978) @@ -0,0 +1,17 @@ +#include <stdlib.h> + +// Do some big allocations. At one point, the threshold calculation was +// multiplying the szB by 10000 without using a Long, which was causing this +// was causing the threshold calculation to go wrong due to a 32-bit +// overflow. + +int main(void) +{ + // 100MB all up. + int i; + for (i = 0; i < 10; i++) { + malloc(10 * 1024 * 1024); + } + + return 0; +} Added: branches/MASSIF2/massif/tests/big-alloc.post.exp =================================================================== --- branches/MASSIF2/massif/tests/big-alloc.post.exp (rev 0) +++ branches/MASSIF2/massif/tests/big-alloc.post.exp 2007-10-11 06:51:47 UTC (rev 6978) @@ -0,0 +1,53 @@ +-------------------------------------------------------------------------------- +Command: ./big-alloc +Massif arguments: --stacks=no --time-unit=B +ms_print arguments: massif.out +-------------------------------------------------------------------------------- + + + MB +100.0^ : + | : + | @ : + | @ : + | : @ : + | : @ : + | : : @ : + | : : @ : + | : : : @ : + | : : : @ : + | : : : : @ : + | : : : : @ : + | : : : : : @ : + | : : : : : @ : + | : : : : : : @ : + | : : : : : : @ : + | : : : : : : : @ : + | : : : : : : : @ : + | : : : : : : : : @ : + | : : : : : : : : @ : + 0 [EMAIL PROTECTED]>MB + 0 100.0 + +Number of snapshots: 11 + Detailed snapshots: [9] +-------------------------------------------------------------------------------- + n time(B) total(B) useful-heap(B) admin-heap(B) stacks(B) +-------------------------------------------------------------------------------- + 0 0 0 0 0 0 + 1 10,485,768 10,485,768 10,485,760 8 0 + 2 20,971,536 20,971,536 20,971,520 16 0 + 3 31,457,304 31,457,304 31,457,280 24 0 + 4 41,943,072 41,943,072 41,943,040 32 0 + 5 52,428,840 52,428,840 52,428,800 40 0 + 6 62,914,608 62,914,608 62,914,560 48 0 + 7 73,400,376 73,400,376 73,400,320 56 0 + 8 83,886,144 83,886,144 83,886,080 64 0 + 9 94,371,912 94,371,912 94,371,840 72 0 +100.00% (94371840B) (heap allocation functions) malloc/new/new[], --alloc-fns, etc. +->100.00% (94371840B) 0x80483AD: main (big-alloc.c:13) + +-------------------------------------------------------------------------------- + n time(B) total(B) useful-heap(B) admin-heap(B) stacks(B) +-------------------------------------------------------------------------------- + 10 104,857,680 104,857,680 104,857,600 80 0 Added: branches/MASSIF2/massif/tests/big-alloc.stderr.exp =================================================================== --- branches/MASSIF2/massif/tests/big-alloc.stderr.exp (rev 0) +++ branches/MASSIF2/massif/tests/big-alloc.stderr.exp 2007-10-11 06:51:47 UTC (rev 6978) @@ -0,0 +1,2 @@ + + Added: branches/MASSIF2/massif/tests/big-alloc.vgtest =================================================================== --- branches/MASSIF2/massif/tests/big-alloc.vgtest (rev 0) +++ branches/MASSIF2/massif/tests/big-alloc.vgtest 2007-10-11 06:51:47 UTC (rev 6978) @@ -0,0 +1,4 @@ +prog: big-alloc +vgopts: --stacks=no --time-unit=B +post: perl ../../massif/ms_print massif.out +cleanup: rm massif.out ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/ _______________________________________________ Valgrind-developers mailing list Valgrind-developers@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/valgrind-developers