]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Darwin regtest: add an expected for duplicate_align_size_errors
authorPaul Floyd <pjfloyd@wanadoo.fr>
Sat, 1 Nov 2025 15:56:20 +0000 (16:56 +0100)
committerPaul Floyd <pjfloyd@wanadoo.fr>
Sat, 1 Nov 2025 15:56:20 +0000 (16:56 +0100)
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.

memcheck/tests/Makefile.am
memcheck/tests/duplicate_align_size_errors.stderr.out-darwin [new file with mode: 0644]
memcheck/tests/memccpy2.c
memcheck/tests/overlap.c

index fd3f89cd286ad9bd3e6e12210411c25232f534af..755f422ee548b9092a50e8e1fc3791c99f55ad5a 100644 (file)
@@ -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 (file)
index 0000000..93faa3d
--- /dev/null
@@ -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)
+
index 947324581715a7cb52fff98f72ebe05d4182c183..be7808d5fda5c71b444de8f37f5a59927bcd0f6e 100644 (file)
@@ -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);
 }
index d868886f381f3f17a41abbc4776b28be4ed60a51..649b1e34d354dc83f2e0475e26e5ba9f0fa30e54 100644 (file)
@@ -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' */