From: Paul Floyd Date: Sat, 1 Nov 2025 15:56:20 +0000 (+0100) Subject: Darwin regtest: add an expected for duplicate_align_size_errors X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=87631266a5375a5fad1e6e0cb20c93ed8b7ef43f;p=thirdparty%2Fvalgrind.git Darwin regtest: add an expected for duplicate_align_size_errors Also start trying to del with some redir issues. For some libc functions the plain function gets replaced by a checked version (not sure if this is only for debug builds). For instance in /usr/include/secure/_string.h there are a load of macros that look like /* void *memccpy(void *dst, const void *src, int c, size_t n) */ __builtin___memccpy_chk (dest, __VA_ARGS__, __darwin_obsz0 (dest)) To defeat these macros I've put the function name in parens. That hasn't solved the issue. In addition these seems to be an ifunc like mechanism that resolves calls to platform functions. For instance nm /usr/lib/system/*dylib | grep memcc 0000000000081e14 T ___memccpy_chk U __platform_memccpy I _memccpy (indirect for __platform_memccpy) 0000000000004eb4 T __platform_memccpy That matches what I see in lldb (memccpy then function lookup code then _platform_memccpy). Need to look at how indirects work. --- diff --git a/memcheck/tests/Makefile.am b/memcheck/tests/Makefile.am index fd3f89cd2..755f422ee 100644 --- a/memcheck/tests/Makefile.am +++ b/memcheck/tests/Makefile.am @@ -168,6 +168,7 @@ EXTRA_DIST = \ cxx17_aligned_new.stdout.exp \ duplicate_align_size_errors.stderr.exp \ duplicate_align_size_errors.stderr.exp-memalign \ + duplicate_align_size_errors.stderr.exp-darwin \ duplicate_align_size_errors.vgtest \ sized_aligned_new_delete_args.stderr.exp \ sized_aligned_new_delete_args.vgtest \ diff --git a/memcheck/tests/duplicate_align_size_errors.stderr.out-darwin b/memcheck/tests/duplicate_align_size_errors.stderr.out-darwin new file mode 100644 index 000000000..93faa3d16 --- /dev/null +++ b/memcheck/tests/duplicate_align_size_errors.stderr.out-darwin @@ -0,0 +1,22 @@ +Invalid alignment value: 0 (should be non-zero and a power of 2) + at 0x........: operator new(unsigned long, std::align_val_t, std::nothrow_t const&) (vg_replace_malloc.c:...) + by 0x........: main (duplicate_align_size_errors.cpp:19) + +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) + +Mismatched new/delete size value: 33 + at 0x........: operator delete(void*, unsigned long, std::align_val_t) (vg_replace_malloc.c:...) + by 0x........: main (duplicate_align_size_errors.cpp:43) + Address 0x........ is 0 bytes inside a block of size 32 alloc'd + at 0x........: operator new(unsigned long, std::align_val_t) (vg_replace_malloc.c:...) + by 0x........: main (duplicate_align_size_errors.cpp:42) + +Mismatched new[]/delete[] alignment alloc value: 64 dealloc value: 128 + at 0x........: operator delete[](void*, unsigned long, std::align_val_t) (vg_replace_malloc.c:...) + by 0x........: main (duplicate_align_size_errors.cpp:48) + Address 0x........ is 0 bytes inside a block of size 32 alloc'd + at 0x........: operator new[](unsigned long, std::align_val_t) (vg_replace_malloc.c:...) + by 0x........: main (duplicate_align_size_errors.cpp:47) + diff --git a/memcheck/tests/memccpy2.c b/memcheck/tests/memccpy2.c index 947324581..be7808d5f 100644 --- a/memcheck/tests/memccpy2.c +++ b/memcheck/tests/memccpy2.c @@ -8,9 +8,9 @@ int main(void) { char* astring = strdup("this is a string # with something to seek"); size_t len = strlen(astring); - memccpy(astring+10, astring, '#', len-10); + (memccpy)(astring+10, astring, '#', len-10); sprintf(astring, "this is a string # with something to seek"); - memccpy(astring, astring+10, '#', len); + (memccpy)(astring, astring+10, '#', len); sprintf(astring, "this is a string # with something to seek"); /* @@ -23,10 +23,10 @@ int main(void) assert(res && *res == 'g'); sprintf(astring, "this is a string # with something to seek"); /* length is 0, nothing copied, returns NULL */ - res = memccpy(astring, "abcdefhhijklmnopqrstuvwxy", 'z', 0); + res = (memccpy)(astring, "abcdefhhijklmnopqrstuvwxy", 'z', 0); assert(NULL == res); /* 'z' not found so 20 bytes copied, returns NULL */ - res = memccpy(astring, "abcdefhhijklmnopqrstuvwxy", 'z', 20); + res = (memccpy)(astring, "abcdefhhijklmnopqrstuvwxy", 'z', 20); assert(NULL == res); free(astring); } diff --git a/memcheck/tests/overlap.c b/memcheck/tests/overlap.c index d868886f3..649b1e34d 100644 --- a/memcheck/tests/overlap.c +++ b/memcheck/tests/overlap.c @@ -42,16 +42,16 @@ int main(void) memcpy(x, x+20, 21); // overlap strncpy(x+20, x, 20); // ok - strncpy(x+20, x, 21); // overlap + (strncpy)(x+20, x, 21); // overlap strncpy(x, x+20, 20); // ok - strncpy(x, x+20, 21); // overlap + (strncpy)(x, x+20, 21); // overlap x[39] = '\0'; strcpy(x, x+20); // ok x[39] = 39; x[40] = '\0'; - strcpy(x, x+20); // overlap + (strcpy)(x, x+20); // overlap x[19] = '\0'; strcpy(x+20, x); // ok @@ -109,8 +109,8 @@ int main(void) always run forever, I think... */ for ( i = 0; i < 2; i++) - strncat(a+20, a, 21); // run twice to check 2nd error isn't shown - strncat(a, a+20, 21); + (strncat)(a+20, a, 21); // run twice to check 2nd error isn't shown + (strncat)(a, a+20, 21); /* This is ok, but once gave a warning when strncpy() was wrong, and used 'n' for the length, even when the src was shorter than 'n' */