]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
free_aligned_sized: improve error message for alignment mismatch
authorPaul Floyd <pjfloyd@wanadoo.fr>
Sun, 17 May 2026 10:42:26 +0000 (12:42 +0200)
committerPaul Floyd <pjfloyd@wanadoo.fr>
Sun, 17 May 2026 11:14:16 +0000 (13:14 +0200)
Previously if the allocation used default alignment then
the error message used 0 for the allocation alignment.
Now it says "default-aligned".

memcheck/mc_errors.c
memcheck/tests/c23_free.stderr.exp
memcheck/tests/sized_aligned_new_delete_misaligned1.cpp
memcheck/tests/sized_aligned_new_delete_misaligned1.stderr.exp
memcheck/tests/sized_aligned_new_delete_misaligned1_supp.stderr.exp
memcheck/tests/sized_aligned_new_delete_misaligned1_xml.stderr.exp

index b8869733fd732985ca3b1768d465016e2c934318..fecf87fd961b1db8e7aec173a7a8cfe9a58ab94e 100644 (file)
@@ -829,31 +829,31 @@ void MC_(pp_Error) ( const Error* err )
          }
          break;
 
-      case Err_AlignMismatch:
+      case Err_AlignMismatch: {
+         HChar alloc_buf[32];
+         HChar dealloc_buf[32];
+         if (extra->Err.AlignMismatch.alloc_align == 0) {
+            VG_(sprintf)(alloc_buf, "%s", "default-aligned");
+         } else {
+            VG_(sprintf)(alloc_buf, "%lu", extra->Err.AlignMismatch.alloc_align);
+         }
+         if (extra->Err.AlignMismatch.default_delete) {
+            VG_(sprintf)(dealloc_buf, "%s", "default-aligned");
+         } else {
+            VG_(sprintf)(dealloc_buf, "%lu", extra->Err.AlignMismatch.dealloc_align);
+         }
          if (xml) {
             emit( "  <kind>MismatchedAllocateDeallocateAlignment</kind>\n" );
-            if (extra->Err.AlignMismatch.default_delete) {
-               emit( "  <what>Mismatched %s size alloc value: %lu dealloc value: default-aligned</what>\n",
-                    extra->Err.SizeMismatch.function_names, extra->Err.AlignMismatch.alloc_align );
-            } else {
-               emit( "  <what>Mismatched %s size alloc value: %lu dealloc value: %lu</what>\n",
-                     extra->Err.SizeMismatch.function_names, extra->Err.AlignMismatch.alloc_align, extra->Err.AlignMismatch.dealloc_align );
-            }
-            VG_(pp_ExeContext)( VG_(get_error_where)(err) );
-            VG_(pp_addrinfo_mc)(VG_(get_error_address)(err),
-                                &extra->Err.AlignMismatch.ai, False);
+            emit( "  <what>Mismatched %s alignment alloc value: %s dealloc value: %s</what>\n",
+                 extra->Err.AlignMismatch.function_names, alloc_buf, dealloc_buf );
          } else {
-            if (extra->Err.AlignMismatch.default_delete) {
-               emit( "Mismatched %s alignment alloc value: %lu dealloc value: default-aligned\n",
-                    extra->Err.AlignMismatch.function_names, extra->Err.AlignMismatch.alloc_align );
-            } else {
-               emit( "Mismatched %s alignment alloc value: %lu dealloc value: %lu\n",
-                     extra->Err.AlignMismatch.function_names, extra->Err.AlignMismatch.alloc_align, extra->Err.AlignMismatch.dealloc_align );
-            }
-            VG_(pp_ExeContext)( VG_(get_error_where)(err) );
-            VG_(pp_addrinfo_mc)(VG_(get_error_address)(err),
-                                &extra->Err.AlignMismatch.ai, False);
+            emit( "Mismatched %s alignment alloc value: %s dealloc value: %s\n",
+                  extra->Err.AlignMismatch.function_names, alloc_buf, dealloc_buf );
          }
+         VG_(pp_ExeContext)( VG_(get_error_where)(err) );
+         VG_(pp_addrinfo_mc)(VG_(get_error_address)(err),
+                             &extra->Err.AlignMismatch.ai, False);
+      }
          break;
 
       default: 
index 02cf4bcfe8ea4cd4aa70d94465b318f54eb4ac42..567b19bb0ed8821bc49eae68d3e5da961323460b 100644 (file)
@@ -20,7 +20,7 @@ Invalid alignment value: 1000 (should be a power of 2)
    at 0x........: free_aligned_sized (vg_replace_malloc.c:...)
    by 0x........: main (c23_free.c:42)
 
-Mismatched aligned_alloc/free_aligned_sized alignment alloc value: 0 dealloc value: 1000
+Mismatched aligned_alloc/free_aligned_sized alignment alloc value: default-aligned dealloc value: 1000
    at 0x........: free_aligned_sized (vg_replace_malloc.c:...)
    by 0x........: main (c23_free.c:42)
  Address 0x........ is 0 bytes inside a block of size 1,000 alloc'd
index f4383a47cfd8cc43d88f817b6a313b338dad519f..925da42f5d8f0dcbca6360f0eb775b1dbae0efe5 100644 (file)
@@ -50,9 +50,17 @@ int main() {
     
     mem = operator new[](size, align);
     operator delete[](mem, size, misalign);
+
+    // default size new, sized aligned delete
+    mem = operator new(size);
+    operator delete(mem, size, align);
+
+    // default size new array, sized aligned delete array
+    mem = operator new[](size);
+    operator delete[](mem, size, align);
     
     // initially this test had two throwing
     // versions called from fork()s
     // but that doesn't mix well with xml
-    // so they have split out int versions 2 and 3
+    // so they have split out into versions 2 and 3
 }
index 3b6c5a513218ff100027a3d3c9fbbf4b2f5599bf..980293539754b6d50fa5644cab5e70b94ca36453 100644 (file)
@@ -66,3 +66,17 @@ Invalid alignment value: 63 (should be non-zero and a power of 2)
    at 0x........: operator delete[](void*, unsigned long, std::align_val_t) (vg_replace_malloc.c:...)
    by 0x........: main (sized_aligned_new_delete_misaligned1.cpp:52)
 
+Mismatched new/delete alignment alloc value: default-aligned dealloc value: 64
+   at 0x........: operator delete(void*, unsigned long, std::align_val_t) (vg_replace_malloc.c:...)
+   by 0x........: main (sized_aligned_new_delete_misaligned1.cpp:56)
+ Address 0x........ is 0 bytes inside a block of size 32 alloc'd
+   at 0x........: ...operator new... (vg_replace_malloc.c:...)
+   by 0x........: main (sized_aligned_new_delete_misaligned1.cpp:55)
+
+Mismatched new[]/delete[] alignment alloc value: default-aligned dealloc value: 64
+   at 0x........: operator delete[](void*, unsigned long, std::align_val_t) (vg_replace_malloc.c:...)
+   by 0x........: main (sized_aligned_new_delete_misaligned1.cpp:60)
+ Address 0x........ is 0 bytes inside a block of size 32 alloc'd
+   at 0x........: ...operator new[]... (vg_replace_malloc.c:...)
+   by 0x........: main (sized_aligned_new_delete_misaligned1.cpp:59)
+
index d71c9b38af4146efb7da67b47324aab40ddc354b..3b75726d7816e0ba4777b2837bbe47878332f3d5 100644 (file)
@@ -1,7 +1,7 @@
+used_suppression:      2 array delete aligned alignment mismatch sized_aligned_new_delete_misaligned1_supp.supp
+used_suppression:      2 scalar delete sized aligned alignment mismatch sized_aligned_new_delete_misaligned1_supp.supp
 used_suppression:      1 array delete sized aligned bad alignment sized_aligned_new_delete_misaligned1_supp.supp
-used_suppression:      1 array delete aligned alignment mismatch sized_aligned_new_delete_misaligned1_supp.supp
 used_suppression:      1 scalar delete sized aligned bad alignment sized_aligned_new_delete_misaligned1_supp.supp
-used_suppression:      1 scalar delete sized aligned alignment mismatch sized_aligned_new_delete_misaligned1_supp.supp
 used_suppression:      1 array delete aligned nothrow bad alignment sized_aligned_new_delete_misaligned1_supp.supp
 used_suppression:      1 array new aligned nothrow bad alignment sized_aligned_new_delete_misaligned1_supp.supp
 used_suppression:      2 scalar delete aligned nothrow bad alignment sized_aligned_new_delete_misaligned1_supp.supp
index 5a2602b466eaf35fb013790c311930dade5cd6ea..a7c828863c234376420790bcedf9578b3284e474 100644 (file)
   <unique>0x........</unique>
   <tid>...</tid>
   <kind>MismatchedAllocateDeallocateAlignment</kind>
-  <what>Mismatched new/delete size alloc value: 64 dealloc value: 63</what>
+  <what>Mismatched new/delete alignment alloc value: 64 dealloc value: 63</what>
   <stack>
     <frame>
       <ip>0x........</ip>
   <unique>0x........</unique>
   <tid>...</tid>
   <kind>MismatchedAllocateDeallocateAlignment</kind>
-  <what>Mismatched new[]/delete[] size alloc value: 64 dealloc value: 63</what>
+  <what>Mismatched new[]/delete[] alignment alloc value: 64 dealloc value: 63</what>
   <stack>
     <frame>
       <ip>0x........</ip>
   <unique>0x........</unique>
   <tid>...</tid>
   <kind>MismatchedAllocateDeallocateAlignment</kind>
-  <what>Mismatched new/delete size alloc value: 64 dealloc value: 63</what>
+  <what>Mismatched new/delete alignment alloc value: 64 dealloc value: 63</what>
   <stack>
     <frame>
       <ip>0x........</ip>
   <unique>0x........</unique>
   <tid>...</tid>
   <kind>MismatchedAllocateDeallocateAlignment</kind>
-  <what>Mismatched new[]/delete[] size alloc value: 64 dealloc value: 63</what>
+  <what>Mismatched new[]/delete[] alignment alloc value: 64 dealloc value: 63</what>
   <stack>
     <frame>
       <ip>0x........</ip>
   </stack>
 </error>
 
+<error>
+  <unique>0x........</unique>
+  <tid>...</tid>
+  <kind>MismatchedAllocateDeallocateAlignment</kind>
+  <what>Mismatched new/delete alignment alloc value: default-aligned dealloc value: 64</what>
+  <stack>
+    <frame>
+      <ip>0x........</ip>
+      <obj>...</obj>
+      <fn>operator delete(void*, unsigned long, std::align_val_t)</fn>
+      <dir>...</dir>
+      <file>vg_replace_malloc.c</file>
+      <line>...</line>
+    </frame>
+    <frame>
+      <ip>0x........</ip>
+      <obj>...</obj>
+      <fn>main</fn>
+      <dir>...</dir>
+      <file>sized_aligned_new_delete_misaligned1.cpp</file>
+      <line>...</line>
+    </frame>
+  </stack>
+  <auxwhat>Address 0x........ is 0 bytes inside a block of size 32 alloc'd</auxwhat>
+  <stack>
+    <frame>
+      <ip>0x........</ip>
+      <obj>...</obj>
+      <fn>operator new(unsigned long)</fn>
+      <dir>...</dir>
+      <file>vg_replace_malloc.c</file>
+      <line>...</line>
+    </frame>
+    <frame>
+      <ip>0x........</ip>
+      <obj>...</obj>
+      <fn>main</fn>
+      <dir>...</dir>
+      <file>sized_aligned_new_delete_misaligned1.cpp</file>
+      <line>...</line>
+    </frame>
+  </stack>
+</error>
+
+<error>
+  <unique>0x........</unique>
+  <tid>...</tid>
+  <kind>MismatchedAllocateDeallocateAlignment</kind>
+  <what>Mismatched new[]/delete[] alignment alloc value: default-aligned dealloc value: 64</what>
+  <stack>
+    <frame>
+      <ip>0x........</ip>
+      <obj>...</obj>
+      <fn>operator delete[](void*, unsigned long, std::align_val_t)</fn>
+      <dir>...</dir>
+      <file>vg_replace_malloc.c</file>
+      <line>...</line>
+    </frame>
+    <frame>
+      <ip>0x........</ip>
+      <obj>...</obj>
+      <fn>main</fn>
+      <dir>...</dir>
+      <file>sized_aligned_new_delete_misaligned1.cpp</file>
+      <line>...</line>
+    </frame>
+  </stack>
+  <auxwhat>Address 0x........ is 0 bytes inside a block of size 32 alloc'd</auxwhat>
+  <stack>
+    <frame>
+      <ip>0x........</ip>
+      <obj>...</obj>
+      <fn>operator new[](unsigned long)</fn>
+      <dir>...</dir>
+      <file>vg_replace_malloc.c</file>
+      <line>...</line>
+    </frame>
+    <frame>
+      <ip>0x........</ip>
+      <obj>...</obj>
+      <fn>main</fn>
+      <dir>...</dir>
+      <file>sized_aligned_new_delete_misaligned1.cpp</file>
+      <line>...</line>
+    </frame>
+  </stack>
+</error>
+
 <status>
   <state>FINISHED</state>
   <time>...</time>
     <count>...</count>
     <unique>0x........</unique>
   </pair>
+  <pair>
+    <count>...</count>
+    <unique>0x........</unique>
+  </pair>
+  <pair>
+    <count>...</count>
+    <unique>0x........</unique>
+  </pair>
 </errorcounts>
 
 <suppcounts>...</suppcounts>