]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Bug 509139 - Update BadSize error messages
authorPaul Floyd <pjfloyd@wanadoo.fr>
Sun, 7 Sep 2025 20:01:34 +0000 (22:01 +0200)
committerPaul Floyd <pjfloyd@wanadoo.fr>
Sun, 7 Sep 2025 20:01:34 +0000 (22:01 +0200)
16 files changed:
NEWS
coregrind/m_replacemalloc/vg_replace_malloc.c
memcheck/mc_errors.c
memcheck/mc_include.h
memcheck/mc_main.c
memcheck/tests/duplicate_align_size_errors.cpp
memcheck/tests/duplicate_align_size_errors.stderr.exp
memcheck/tests/duplicate_align_size_errors.stderr.exp-memalign
memcheck/tests/freebsd/aligned_allocs_supp.supp
memcheck/tests/freebsd/errno_aligned_allocs.stderr.exp
memcheck/tests/linux/memalign.stderr.exp
memcheck/tests/linux/memalign.stderr.exp-musl
memcheck/tests/posix_memalign.stderr.exp
memcheck/tests/posix_memalign_supp.supp
memcheck/tests/posix_memalign_xml.stderr.exp
memcheck/tests/solaris/memalign.stderr.exp

diff --git a/NEWS b/NEWS
index 7d087dfb646dbfb1f40bb61a089a1739660e2647..85b7a17b1f50149a7e9654523fe004a1e5c23df7 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -96,6 +96,7 @@ are not entered into bugzilla tend to get forgotten about or ignored.
 508958  FreeBSD: add getgroups and setgroups wrappers
 509103  Fix tests/arm64/bug484935.c build with "-O2 -flto -ffat-lto-objects"
 509107  memcheck/tests/duplicate_align_size_errors.cpp fails
+509139  Update BadSize error messages
 
 To see details of a given bug, visit
   https://bugs.kde.org/show_bug.cgi?id=XXXXXX
index d88f55f8bf29e0169fb7c83118419d2cc64a605e..0438fbdf0a222a62d67091635ddd9c6017918265 100644 (file)
@@ -1073,6 +1073,8 @@ extern int * __error(void) __attribute__((weak));
 
 
 #if defined(VGO_linux)
+ FREE_ALIGNED_SIZED(VG_Z_LIBC_SONAME,       free_aligned_sized,                 free, FreeAlignedSized );
+ FREE_ALIGNED_SIZED(SO_SYN_MALLOC,          free_aligned_sized,                 free, FreeAlignedSized );
 
 #elif defined(VGO_freebsd)
  FREE_ALIGNED_SIZED(VG_Z_LIBC_SONAME,       free_aligned_sized,                 free, FreeAlignedSized );
index a708b3f8521017100d66aefbf83327b4bcdc6ca3..657a112856a0ef9cd7fc543896abc999b1c9f9b8 100644 (file)
@@ -77,7 +77,7 @@ typedef
       Err_FishyValue,
       Err_ReallocSizeZero,
       Err_BadAlign,
-      Err_BadSize,
+      Err_UnsafeZeroSize,
       Err_SizeMismatch,
       Err_AlignMismatch,
    }
@@ -177,9 +177,7 @@ struct _MC_Error {
 
       struct {
          AddrInfo ai;
-         SizeT size;
-         const HChar *func;
-      } BadSize;
+      } UnsafeZeroSize;
 
       // Call to strcpy, memcpy, etc, with overlapping blocks.
       struct {
@@ -799,15 +797,13 @@ void MC_(pp_Error) ( const Error* err )
          }
          break;
 
-   case Err_BadSize:
+   case Err_UnsafeZeroSize:
       if (xml) {
          emit( "  <kind>InvalidSize</kind>\n" );
-         emit( "  <what>%s invalid size value: %lu</what>\n",
-               extra->Err.BadSize.func, extra->Err.BadSize.size );
+         emit( "  <what>Unsafe allocation with size of zero is implementation-defined</what>\n");
          VG_(pp_ExeContext)( VG_(get_error_where)(err) );
       } else {
-         emit( "%s invalid size value: %lu\n",
-               extra->Err.BadSize.func, extra->Err.BadSize.size  );
+         emit( "Unsafe allocation with size of zero is implementation-defined\n");
          VG_(pp_ExeContext)( VG_(get_error_where)(err) );
       }
       break;
@@ -1028,13 +1024,10 @@ void MC_(record_bad_alignment) ( ThreadId tid, SizeT align, SizeT size, const HC
    VG_(maybe_record_error)( tid, Err_BadAlign, /*addr*/0, /*s*/NULL, &extra );
 }
 
-void MC_(record_bad_size) ( ThreadId tid, SizeT size, const HChar *function )
+void MC_(record_unsafe_zero_size) ( ThreadId tid )
 {
-   MC_Error extra;
    tl_assert(VG_INVALID_THREADID != tid);
-   extra.Err.BadSize.size= size;
-   extra.Err.BadSize.func = function;
-   VG_(maybe_record_error)( tid, Err_BadSize, /*addr*/0, /*s*/NULL, &extra );
+   VG_(maybe_record_error)( tid, Err_UnsafeZeroSize, /*addr*/0, /*s*/NULL, /*extra*/NULL );
 }
 
 void MC_(record_illegal_mempool_error) ( ThreadId tid, Addr a ) 
@@ -1222,6 +1215,7 @@ Bool MC_(eq_Error) ( VgRes res, const Error* e1, const Error* e2 )
       case Err_Overlap:
       case Err_Cond:
       case Err_ReallocSizeZero:
+      case Err_UnsafeZeroSize:
          return True;
 
       case Err_FishyValue:
@@ -1253,11 +1247,6 @@ Bool MC_(eq_Error) ( VgRes res, const Error* e1, const Error* e2 )
                   extra2->Err.BadAlign.dealloc_align;
          }
 
-      case Err_BadSize:
-         // sized delete mismatch
-         return extra1->Err.BadSize.size ==
-               extra2->Err.BadSize.size;
-
       case Err_SizeMismatch:
          return extra1->Err.SizeMismatch.size ==
                extra2->Err.SizeMismatch.size;
@@ -1418,7 +1407,7 @@ UInt MC_(update_Error_extra)( const Error* err )
    // we make it consistent with the others.
    case Err_Leak:
    case Err_BadAlign:
-   case Err_BadSize:
+   case Err_UnsafeZeroSize:
    case Err_SizeMismatch:
    case Err_AlignMismatch:
       return sizeof(MC_Error);
@@ -1578,10 +1567,10 @@ typedef
       MempoolSupp,          // Memory pool suppression.
       FishyValueSupp,       // Fishy value suppression.
       ReallocSizeZeroSupp,  // realloc size 0 suppression
-      BadAlignSupp,     // Alignment not 2
-      BadSizeSupp,     // aligned alloc with size 0
-      SizeMismatch,  // Sized deallocation did not match allocation size
-      AlignMismatch, // Aligned deallocation did not match aligned allocation
+      BadAlignSupp,         // Alignment not 2
+      UnsafeZeroSizeSupp,   // aligned alloc with size 0
+      SizeMismatch,         // Sized deallocation did not match allocation size
+      AlignMismatch,        // Aligned deallocation did not match aligned allocation
    } 
    MC_SuppKind;
 
@@ -1614,7 +1603,7 @@ Bool MC_(is_recognised_suppression) ( const HChar* name, Supp* su )
    else if (VG_STREQ(name, "FishyValue")) skind = FishyValueSupp;
    else if (VG_STREQ(name, "ReallocZero")) skind = ReallocSizeZeroSupp;
    else if (VG_STREQ(name, "BadAlign")) skind = BadAlignSupp;
-   else if (VG_STREQ(name, "BadSize")) skind = BadSizeSupp;
+   else if (VG_STREQ(name, "UnsafeZeroSize")) skind = UnsafeZeroSizeSupp;
    else if (VG_STREQ(name, "SizeMismatch")) skind = SizeMismatch;
    else if (VG_STREQ(name, "AlignMismatch")) skind = AlignMismatch;
    else 
@@ -1800,8 +1789,8 @@ Bool MC_(error_matches_suppression) ( const Error* err, const Supp* su )
       case BadAlignSupp:
          return (ekind == Err_BadAlign);
 
-      case BadSizeSupp:
-         return (ekind == Err_BadSize);
+      case UnsafeZeroSizeSupp:
+         return (ekind == Err_UnsafeZeroSize);
 
       case SizeMismatch:
          return (ekind == Err_SizeMismatch);
@@ -1835,7 +1824,7 @@ const HChar* MC_(get_error_name) ( const Error* err )
    case Err_FishyValue:      return "FishyValue";
    case Err_ReallocSizeZero: return "ReallocZero";
    case Err_BadAlign:        return "BadAlign";
-   case Err_BadSize:         return "BadSize";
+   case Err_UnsafeZeroSize:  return "UnsafeZeroSize";
    case Err_SizeMismatch:    return "SizeMismatch";
    case Err_AlignMismatch:   return "AlignMismatch";
    case Err_Addr: {
index acc595a745e9800128d877f824afd5a5eacec634..7cc5febe07614e686efe5fea8b8b8a4ccc83d3d3 100644 (file)
@@ -559,7 +559,7 @@ void MC_(record_illegal_mempool_error) ( ThreadId tid, Addr a );
 void MC_(record_freemismatch_error)    ( ThreadId tid, MC_Chunk* mc );
 void MC_(record_realloc_size_zero)     ( ThreadId tid, Addr a );
 void MC_(record_bad_alignment)         ( ThreadId tid, SizeT align, SizeT size, const HChar *msg);
-void MC_(record_bad_size)              ( ThreadId tid, SizeT align, const HChar *function);
+void MC_(record_unsafe_zero_size)      ( ThreadId tid);
 
 void MC_(record_overlap_error)  ( ThreadId tid, const HChar* function,
                                   Addr src, Addr dst, SizeT szB );
index 626d481d2587f1b67cdbbe8d38a1e12a755a59f0..c7409156b7f0fbc054a53f1b642a290c9a770de9 100644 (file)
@@ -7231,7 +7231,7 @@ static Bool mc_handle_client_request ( ThreadId tid, UWord* arg, UWord* ret )
          }
          // size zero not allowed on all platforms (e.g. Illumos)
          if (aligned_alloc_info->size == 0) {
-            MC_(record_bad_size) ( tid, aligned_alloc_info->size, "memalign()" );
+            MC_(record_unsafe_zero_size) ( tid );
          }
          break;
       case AllocKindPosixMemalign:
@@ -7243,7 +7243,7 @@ static Bool mc_handle_client_request ( ThreadId tid, UWord* arg, UWord* ret )
             MC_(record_bad_alignment) ( tid, aligned_alloc_info->orig_alignment , 0U, " (should be non-zero, a power of 2 and a multiple of sizeof(void*))" );
          }
          if (aligned_alloc_info->size == 0) {
-            MC_(record_bad_size) ( tid, aligned_alloc_info->size, "posix_memalign()" );
+            MC_(record_unsafe_zero_size) ( tid);
          }
          break;
       case AllocKindAlignedAlloc:
@@ -7257,7 +7257,7 @@ static Bool mc_handle_client_request ( ThreadId tid, UWord* arg, UWord* ret )
             MC_(record_bad_alignment) ( tid, aligned_alloc_info->orig_alignment , aligned_alloc_info->size, " (size should be a multiple of alignment)" );
          }
          if (aligned_alloc_info->size == 0) {
-            MC_(record_bad_size) ( tid, aligned_alloc_info->size, "aligned_alloc()" );
+            MC_(record_unsafe_zero_size) ( tid );
          }
          break;
       case AllocKindDeleteSized:
@@ -7279,7 +7279,7 @@ static Bool mc_handle_client_request ( ThreadId tid, UWord* arg, UWord* ret )
          }
          break;
       case AllocKindFreeAlignedSized:
-         // same alignment checks as aligned_alloc
+         // same alignment checks as aligned_alloc, but allow a size of 0
          if ((aligned_alloc_info->orig_alignment & (aligned_alloc_info->orig_alignment - 1)) != 0) {
             MC_(record_bad_alignment) ( tid, aligned_alloc_info->orig_alignment , 0U, " (should be a power of 2)" );
          }
@@ -7287,9 +7287,6 @@ static Bool mc_handle_client_request ( ThreadId tid, UWord* arg, UWord* ret )
              aligned_alloc_info->size % aligned_alloc_info->orig_alignment != 0U) {
             MC_(record_bad_alignment) ( tid, aligned_alloc_info->orig_alignment , aligned_alloc_info->size, " (size should be a multiple of alignment)" );
          }
-         if (aligned_alloc_info->size == 0) {
-            MC_(record_bad_size) ( tid, aligned_alloc_info->size, "free_aligned_sized()" );
-         }
          mc = VG_(HT_lookup) ( MC_(malloc_list), (UWord)aligned_alloc_info->mem );
          if (mc && aligned_alloc_info->orig_alignment != mc->alignB) {
             MC_(record_align_mismatch_error) ( tid, mc, aligned_alloc_info->orig_alignment, False, "aligned_alloc/free_aligned_sized");
index 58f64a7cde923ca7e96a5a1235a7bd50b08d6eca..15c6759588a6f6031e533697983e6e8ce9b3f149 100644 (file)
@@ -29,7 +29,7 @@ int main()
           mem = nullptr;
        }
 
-       // Err.BadSize
+       // Err.UnsafeZeroSize
        mem  = aligned_alloc(64U, 0U);
        if (mem)
        {
index 4eb84f4339a32ec4f3a45d808420aacd6bc8a843..871c1c920086380338ec9d8c7f638a84dd5099af 100644 (file)
@@ -10,7 +10,7 @@ Invalid size value: 100 alignment value: 64 (size should be a multiple of alignm
    at 0x........: aligned_alloc (vg_replace_malloc.c:...)
    by 0x........: main (duplicate_align_size_errors.cpp:25)
 
-aligned_alloc() invalid size value: 0
+Unsafe allocation with size of zero is implementation-defined
    at 0x........: aligned_alloc (vg_replace_malloc.c:...)
    by 0x........: main (duplicate_align_size_errors.cpp:33)
 
index 250b0507050920ab22b1eb21d6a1bb205cf95770..16ecf7714bf13f2e48f4fba3f5e177e73b04f43b 100644 (file)
@@ -6,7 +6,7 @@ Invalid alignment value: 0 (should be non-zero and a power of 2)
    at 0x........: operator delete(void*, std::align_val_t, std::nothrow_t const&) (vg_replace_malloc.c:...)
    by 0x........: main (duplicate_align_size_errors.cpp:20)
 
-memalign() invalid size value: 0
+Unsafe allocation with size of zero is implementation-defined
    at 0x........: memalign (vg_replace_malloc.c:...)
    by 0x........: main (duplicate_align_size_errors.cpp:33)
 
index 56676481e7bf48f700bd13003800aea16a28d6de..122766f9c83ce7d5ca19da3cdfddac5e38adbbcb 100644 (file)
@@ -14,7 +14,7 @@
 
 {
    aligned_alloc bad size
-   Memcheck:BadSize
+   Memcheck:UnsafeZeroSize
    fun:aligned_alloc
    fun:main
 }
index c555d9bdd3e478539d363b669a8540bf91ed5c81..93c66c70bf0225333669a675249efb428dc64b6a 100644 (file)
@@ -11,7 +11,7 @@ Invalid alignment value: 40 (should be non-zero, a power of 2 and a multiple of
    at 0x........: posix_memalign (vg_replace_malloc.c:...)
    by 0x........: main (errno_aligned_allocs.c:20)
 
-aligned_alloc() invalid size value: 0
+Unsafe allocation with size of zero is implementation-defined
    at 0x........: aligned_alloc (vg_replace_malloc.c:...)
    by 0x........: main (errno_aligned_allocs.c:60)
 
index ae9dc6e3568d15940d115c1bc65624ff84372263..630af58f11f4b0f7ac66394cc419b40b0e103bc7 100644 (file)
@@ -34,7 +34,7 @@ Invalid alignment value: 4097 (should be power of 2)
    at 0x........: memalign (vg_replace_malloc.c:...)
    by 0x........: main (memalign.c:78)
 
-memalign() invalid size value: 0
+Unsafe allocation with size of zero is implementation-defined
    at 0x........: memalign (vg_replace_malloc.c:...)
    by 0x........: main (memalign.c:87)
 
index 6d3d3ac980f8983a96ad6043651b6982525949de..61e9177e82a5b5458f30595361396c7017f60af3 100644 (file)
@@ -34,7 +34,7 @@ Invalid alignment value: 4097 (should be power of 2)
    at 0x........: memalign (vg_replace_malloc.c:...)
    by 0x........: main (memalign.c:145)
 
-memalign() invalid size value: 0
+Unsafe allocation with size of zero is implementation-defined
    at 0x........: memalign (vg_replace_malloc.c:...)
    by 0x........: main (memalign.c:155)
 
index 3f8075f639e4a10d36976cad3e795c442cfd378c..1c4701370b03f2855e19c17e42af12a1e2c2184d 100644 (file)
@@ -1,4 +1,4 @@
-posix_memalign() invalid size value: 0
+Unsafe allocation with size of zero is implementation-defined
    at 0x........: posix_memalign (vg_replace_malloc.c:...)
    by 0x........: main (posix_memalign.c:32)
 
index a38ba23b0c524c56bd0c80e07178368fe738ebef..23572e40f1f1b0fc561e3a2d58dec06dea4384d3 100644 (file)
@@ -1,7 +1,7 @@
 
 {
    posix_memalign size
-   Memcheck:BadSize
+   Memcheck:UnsafeZeroSize
    fun:posix_memalign
    fun:main
 }
@@ -15,8 +15,8 @@
 
 # Darwin uses zones
 {
-   posix_memalign size
-   Memcheck:BadSize
+   posix_memalign zero size
+   Memcheck:UnsafeZeroSize
    fun:malloc_zone_memalign
    fun:posix_memalign
    fun:main
index ce9ded32066c7baf3d1ce9781aa7a1fafb96f7e8..9941ebc661e5e91556b36ca3c61bb08204142383 100644 (file)
@@ -32,7 +32,7 @@
   <unique>0x........</unique>
   <tid>...</tid>
   <kind>InvalidSize</kind>
-  <what>posix_memalign() invalid size value: 0</what>
+  <what>Unsafe allocation with size of zero is implementation-defined</what>
   <stack>
     <frame>
       <ip>0x........</ip>
index dd2441252383a2bf252587a0303ee65c93e1df4e..fa9e333a58d3851ae60f14b4af4cb21f8fc7d551 100644 (file)
@@ -1,4 +1,4 @@
-memalign() invalid size value: 0
+Unsafe allocation with size of zero is implementation-defined
    at 0x........: memalign (vg_replace_malloc.c:...)
    by 0x........: main (memalign.c:29)