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 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/coregrind/core.h b/coregrind/core.h
index d4ef229..59a509d 100644
--- a/coregrind/core.h
+++ b/coregrind/core.h
@@ -438,7 +438,7 @@
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 057e113..3384a9a 100644
--- a/coregrind/vg_malloc2.c
+++ b/coregrind/vg_malloc2.c
@@ -1277,24 +1277,25 @@
/*--- 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 @@
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 0ec7327..506afff 100644
--- a/include/tool.h.base
+++ b/include/tool.h.base
@@ -341,7 +341,7 @@
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 );