]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Bug 515731 - Distinguish between realloc functions in realloc size 0 error messages
authorPaul Floyd <pjfloyd@wanadoo.fr>
Mon, 9 Feb 2026 06:22:52 +0000 (07:22 +0100)
committerPaul Floyd <pjfloyd@wanadoo.fr>
Thu, 12 Feb 2026 06:45:22 +0000 (07:45 +0100)
NEWS
coregrind/m_execontext.c
include/pub_tool_execontext.h
memcheck/mc_errors.c
memcheck/tests/amd64-freebsd/reallocarray.stderr.exp
memcheck/tests/amd64-freebsd/reallocf.stderr.exp
memcheck/tests/amd64-linux/reallocarray.stderr.exp
memcheck/tests/freebsd/static_allocs.stderr.exp
memcheck/tests/x86-freebsd/reallocarray.stderr.exp

diff --git a/NEWS b/NEWS
index 650a82e99beda86e95ba0a0d3f3973210c89d3bd..ca5c0c6a725b1761def39c7fd7cba24936398801 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -87,7 +87,7 @@ are not entered into bugzilla tend to get forgotten about or ignored.
         `valgrind --num-callers=1 ./hello_world`
 515265  Add SSE4.1 BLENDPS and PBLENDW instruction for x86 32 bit
 515612  Sanity check VG_(realpath) and VG_(readlink) return values
-
+515731  Distinguish between realloc functions in realloc size 0 error messages
 
 To see details of a given bug, visit
   https://bugs.kde.org/show_bug.cgi?id=XXXXXX
index cd4b870e23661d19362db54990d45d7cddde538a..dbe1988149aad2ab2c70eb27d55f4e5cebe3b5e7 100644 (file)
@@ -611,6 +611,17 @@ ExeContext* VG_(null_ExeContext) (void)
    return null_ExeContext;
 }
 
+const HChar* VG_(get_ExeContext_first_fnname)(ExeContext* ec)
+{
+   const HChar* fn_name;
+   vg_assert(ec->n_ips > 0);
+   Bool found_fn = VG_(get_fnname)(VG_(get_ExeContext_epoch)(ec), ec->ips[0], &fn_name);
+   if (found_fn) {
+      return fn_name;
+   }
+   return NULL;
+}
+
 /*--------------------------------------------------------------------*/
 /*--- end                                           m_execontext.c ---*/
 /*--------------------------------------------------------------------*/
index 4f5d04ff8b6496ea8f0557b002b75ccdea06e47c..bcb3ce51a1a592159c56b0fefc1e49763fe7955e 100644 (file)
@@ -121,6 +121,10 @@ static inline Bool VG_(is_plausible_ECU)( UInt ecu ) {
 // Make an ExeContext containing exactly the specified stack frames.
 ExeContext* VG_(make_ExeContext_from_StackTrace)( const Addr* ips, UInt n_ips );
 
+// Get the name of the topmost function from an ExeContext
+const HChar* VG_(get_ExeContext_first_fnname)(ExeContext* ec);
+
+
 // Returns the "null" exe context. The null execontext is an artificial
 // exe context, with a stack trace made of one Addr (the NULL address).
 extern 
index 8dbeb15abc0359470da9f67e7e746f4a1c137283..e9a8f3f02eb6615bd7871c2cecb15b5113dd91af 100644 (file)
@@ -754,20 +754,24 @@ void MC_(pp_Error) ( const Error* err )
          }
          break;
 
-      case Err_ReallocSizeZero:
+      case Err_ReallocSizeZero: {
+         const HChar* fn_name = VG_(get_ExeContext_first_fnname)(VG_(get_error_where)(err));
+         if (fn_name == NULL)
+            fn_name = "realloc"; // just in case
          if (xml) {
             emit( "  <kind>ReallocSizeZero</kind>\n" );
-            emit( "  <what>realloc() with size 0</what>\n" );
+            emit( "  <what>%s() with size 0</what>\n", fn_name );
             VG_(pp_ExeContext)( VG_(get_error_where)(err) );
             VG_(pp_addrinfo_mc)(VG_(get_error_address)(err),
                                 &extra->Err.ReallocSizeZero.ai, False);
          } else {
-            emit( "realloc() with size 0\n" );
+            emit( "%s() with size 0\n", fn_name );
             VG_(pp_ExeContext)( VG_(get_error_where)(err) );
             VG_(pp_addrinfo_mc)(VG_(get_error_address)(err),
                                 &extra->Err.ReallocSizeZero.ai, False);
          }
          break;
+      }
 
       case Err_BadAlign:
          if (extra->Err.BadAlign.size) {
index c5dac41c5dc7e1b02ca06a6d326f5dd6c82b042a..f82bb92adc7e32e5409141775598ec1f20266b65 100644 (file)
@@ -11,7 +11,7 @@ LEAK SUMMARY:
 Reachable blocks (those to which a pointer was found) are not shown.
 To see them, rerun with: --leak-check=full --show-leak-kinds=all
 
-realloc() with size 0
+reallocarray() with size 0
    at 0x........: reallocarray (vg_replace_malloc.c:...)
    by 0x........: main (reallocarray.c:19)
  Address 0x........ is 0 bytes inside a block of size 40 alloc'd
@@ -28,7 +28,7 @@ LEAK SUMMARY:
 Reachable blocks (those to which a pointer was found) are not shown.
 To see them, rerun with: --leak-check=full --show-leak-kinds=all
 
-realloc() with size 0
+reallocarray() with size 0
    at 0x........: reallocarray (vg_replace_malloc.c:...)
    by 0x........: main (reallocarray.c:23)
  Address 0x........ is 0 bytes inside a block of size 1 alloc'd
index 4ec2f2ef019369c4a26fc9b3bc0347e9fade9a3e..b240c7807e6793c9a8541c15f3e13a8b8a3845ab 100644 (file)
@@ -10,7 +10,7 @@ LEAK SUMMARY:
 Reachable blocks (those to which a pointer was found) are not shown.
 To see them, rerun with: --leak-check=full --show-leak-kinds=all
 
-realloc() with size 0
+reallocf() with size 0
    at 0x........: reallocf (vg_replace_malloc.c:...)
    by 0x........: main (reallocf.c:12)
  Address 0x........ is 0 bytes inside a block of size 40 alloc'd
index 934c095bee0f5740df462a3ff7a5f225dd7fe0b1..5805fc7a9291f713f1de38dc8fab4eb283988950 100644 (file)
@@ -11,7 +11,7 @@ LEAK SUMMARY:
 Reachable blocks (those to which a pointer was found) are not shown.
 To see them, rerun with: --leak-check=full --show-leak-kinds=all
 
-realloc() with size 0
+reallocarray() with size 0
    at 0x........: reallocarray (vg_replace_malloc.c:...)
    by 0x........: main (reallocarray.c:19)
  Address 0x........ is 0 bytes inside a block of size 40 alloc'd
@@ -21,7 +21,7 @@ realloc() with size 0
 Added leak check, expect all blocks freed
 All heap blocks were freed -- no leaks are possible
 
-realloc() with size 0
+reallocarray() with size 0
    at 0x........: reallocarray (vg_replace_malloc.c:...)
    by 0x........: main (reallocarray.c:25)
  Address 0x........ is 0 bytes inside a block of size 10 alloc'd
index b6e6d328d5f0e914213611a1e9dfc04c99239ee6..d42c22eec775ab06150e6f44f1303536a574b297 100644 (file)
@@ -1,4 +1,4 @@
-realloc() with size 0
+reallocf() with size 0
    at 0x........: reallocf (vg_replace_malloc.c:...)
    by 0x........: main (static_allocs.c:36)
  Address 0x........ is 0 bytes inside a block of size 160 alloc'd
index e40310ffb84bd45739b4b2bccb15f58c393010a0..d009abea1d2ab17c5eaf98d2150c15fb83a0a719 100644 (file)
@@ -10,7 +10,7 @@ LEAK SUMMARY:
 Reachable blocks (those to which a pointer was found) are not shown.
 To see them, rerun with: --leak-check=full --show-leak-kinds=all
 
-realloc() with size 0
+reallocarray() with size 0
    at 0x........: reallocarray (vg_replace_malloc.c:...)
    by 0x........: main (reallocarray.c:13)
  Address 0x........ is 0 bytes inside a block of size 40 alloc'd
@@ -26,7 +26,7 @@ LEAK SUMMARY:
 Reachable blocks (those to which a pointer was found) are not shown.
 To see them, rerun with: --leak-check=full --show-leak-kinds=all
 
-realloc() with size 0
+reallocarray() with size 0
    at 0x........: reallocarray (vg_replace_malloc.c:...)
    by 0x........: main (reallocarray.c:15)
  Address 0x........ is 0 bytes inside a block of size 1 alloc'd