From: Nicholas Nethercote Date: Fri, 11 Mar 2005 04:44:10 +0000 (+0000) Subject: Fix VG_(calloc)() so it actually zeroes the entire memory area it allocates. X-Git-Tag: svn/VALGRIND_3_0_0~1044 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6498475675776b39e2c8e4f06bd297ef7f99bcdf;p=thirdparty%2Fvalgrind.git Fix VG_(calloc)() so it actually zeroes the entire memory area it allocates. Also rename the variables involve to lessen the chance of such confusion occurring again. MERGED FROM CVS HEAD git-svn-id: svn://svn.valgrind.org/valgrind/trunk@3274 --- diff --git a/coregrind/core.h b/coregrind/core.h index d4ef229c2f..59a509d3f6 100644 --- a/coregrind/core.h +++ b/coregrind/core.h @@ -438,7 +438,7 @@ typedef Int ArenaId; extern void* VG_(arena_malloc) ( ArenaId arena, SizeT nbytes ); extern void VG_(arena_free) ( ArenaId arena, void* ptr ); extern void* VG_(arena_calloc) ( ArenaId arena, SizeT alignment, - SizeT nmemb, SizeT nbytes ); + SizeT nmemb, SizeT bytes_per_memb ); extern void* VG_(arena_realloc) ( ArenaId arena, void* ptr, SizeT alignment, SizeT size ); extern void* VG_(arena_malloc_aligned) ( ArenaId aid, SizeT req_alignB, diff --git a/coregrind/vg_malloc2.c b/coregrind/vg_malloc2.c index 057e113add..3384a9a6eb 100644 --- a/coregrind/vg_malloc2.c +++ b/coregrind/vg_malloc2.c @@ -1277,24 +1277,25 @@ SizeT VG_(arena_payload_szB) ( ArenaId aid, void* ptr ) /*--- Services layered on top of malloc/free. ---*/ /*------------------------------------------------------------*/ -void* VG_(arena_calloc) ( ArenaId aid, SizeT alignB, SizeT nmemb, SizeT nbytes ) +void* VG_(arena_calloc) ( ArenaId aid, SizeT alignB, SizeT nmemb, + SizeT bytes_per_memb ) { SizeT size; UChar* p; VGP_PUSHCC(VgpMalloc); - size = nmemb * nbytes; - vg_assert(size >= nmemb && size >= nbytes); // check against overflow + size = nmemb * bytes_per_memb; + vg_assert(size >= nmemb && size >= bytes_per_memb);// check against overflow if (alignB == VG_MIN_MALLOC_SZB) p = VG_(arena_malloc) ( aid, size ); else p = VG_(arena_malloc_aligned) ( aid, alignB, size ); - VG_(memset)(p, 0, nbytes); + VG_(memset)(p, 0, size); - VALGRIND_MALLOCLIKE_BLOCK(p, nbytes, 0, True); + VALGRIND_MALLOCLIKE_BLOCK(p, size, 0, True); VGP_POPCC(VgpMalloc); @@ -1361,9 +1362,10 @@ void VG_(free) ( void* ptr ) VG_(arena_free) ( VG_AR_TOOL, ptr ); } -void* VG_(calloc) ( SizeT nmemb, SizeT nbytes ) +void* VG_(calloc) ( SizeT nmemb, SizeT bytes_per_memb ) { - return VG_(arena_calloc) ( VG_AR_TOOL, VG_MIN_MALLOC_SZB, nmemb, nbytes ); + return VG_(arena_calloc) ( VG_AR_TOOL, VG_MIN_MALLOC_SZB, nmemb, + bytes_per_memb ); } void* VG_(realloc) ( void* ptr, SizeT size ) diff --git a/include/tool.h.base b/include/tool.h.base index 0ec7327031..506afffe90 100644 --- a/include/tool.h.base +++ b/include/tool.h.base @@ -341,7 +341,7 @@ extern Int VG_(rename) ( Char* old_name, Char* new_name ); extern void* VG_(malloc) ( SizeT nbytes ); extern void VG_(free) ( void* p ); -extern void* VG_(calloc) ( SizeT n, SizeT nbytes ); +extern void* VG_(calloc) ( SizeT n, SizeT bytes_per_elem ); extern void* VG_(realloc) ( void* p, SizeT size ); extern void* VG_(malloc_aligned) ( SizeT align_bytes, SizeT nbytes );