From 2baa7b421d10933e05edcd379a456222f722f721 Mon Sep 17 00:00:00 2001 From: Matthew Parkinson Date: Thu, 17 Sep 2026 14:50:40 +0100 Subject: [PATCH 1/3] Fix GWP-ASan usable-size expectation Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 75ccdc6c-2024-4d81-b22f-f1b52fbe29cf --- src/test/func/malloc/malloc.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/func/malloc/malloc.cc b/src/test/func/malloc/malloc.cc index b77f389bb..917c6a3aa 100644 --- a/src/test/func/malloc/malloc.cc +++ b/src/test/func/malloc/malloc.cc @@ -24,7 +24,8 @@ void check_result(size_t size, size_t align, void* p, int err, bool null) failed = true; } const auto alloc_size = testlib_malloc_usable_size(p); - auto expected_size = testlib_malloc_good_size(size); + const auto expected_size = + snmalloc::is_owned(p) ? testlib_malloc_good_size(size) : size; const auto exact_size = align == 1; #ifdef __CHERI_PURE_CAPABILITY__ const auto cheri_size = __builtin_cheri_length_get(p); From a27f95a612c5342c6df7726466b03efcca62b93b Mon Sep 17 00:00:00 2001 From: Matthew Parkinson Date: Thu, 17 Sep 2026 15:17:41 +0100 Subject: [PATCH 2/3] Relax secondary usable-size check Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 75ccdc6c-2024-4d81-b22f-f1b52fbe29cf --- src/test/func/malloc/malloc.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/func/malloc/malloc.cc b/src/test/func/malloc/malloc.cc index 917c6a3aa..7c6543738 100644 --- a/src/test/func/malloc/malloc.cc +++ b/src/test/func/malloc/malloc.cc @@ -24,9 +24,9 @@ void check_result(size_t size, size_t align, void* p, int err, bool null) failed = true; } const auto alloc_size = testlib_malloc_usable_size(p); - const auto expected_size = - snmalloc::is_owned(p) ? testlib_malloc_good_size(size) : size; - const auto exact_size = align == 1; + const auto owned = snmalloc::is_owned(p); + const auto expected_size = owned ? testlib_malloc_good_size(size) : size; + const auto exact_size = owned && (align == 1); #ifdef __CHERI_PURE_CAPABILITY__ const auto cheri_size = __builtin_cheri_length_get(p); if (cheri_size != alloc_size && (size != 0)) From a7fdb0891b1fdc83508d93bb9aefa0f1370193f7 Mon Sep 17 00:00:00 2001 From: Matthew Parkinson Date: Fri, 18 Sep 2026 08:37:11 +0100 Subject: [PATCH 3/3] Simplify malloc usable-size checks Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 75ccdc6c-2024-4d81-b22f-f1b52fbe29cf --- src/test/func/malloc/malloc.cc | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/test/func/malloc/malloc.cc b/src/test/func/malloc/malloc.cc index 7c6543738..09b7fdd16 100644 --- a/src/test/func/malloc/malloc.cc +++ b/src/test/func/malloc/malloc.cc @@ -24,9 +24,7 @@ void check_result(size_t size, size_t align, void* p, int err, bool null) failed = true; } const auto alloc_size = testlib_malloc_usable_size(p); - const auto owned = snmalloc::is_owned(p); - const auto expected_size = owned ? testlib_malloc_good_size(size) : size; - const auto exact_size = owned && (align == 1); + const auto exact_size = snmalloc::is_owned(p) && (align == 1); #ifdef __CHERI_PURE_CAPABILITY__ const auto cheri_size = __builtin_cheri_length_get(p); if (cheri_size != alloc_size && (size != 0)) @@ -61,18 +59,20 @@ void check_result(size_t size, size_t align, void* p, int err, bool null) } } #endif - if (exact_size && (alloc_size != expected_size) && (size != 0)) + if (exact_size && (size != 0)) { - INFO( - "Usable size is {}, but required to be {}.", alloc_size, expected_size); - failed = true; + const auto expected_size = testlib_malloc_good_size(size); + if (alloc_size != expected_size) + { + INFO( + "Usable size is {}, but required to be {}.", alloc_size, expected_size); + failed = true; + } } - if ((!exact_size) && (alloc_size < expected_size)) + if ((!exact_size) && (alloc_size < size)) { INFO( - "Usable size is {}, but required to be at least {}.", - alloc_size, - expected_size); + "Usable size is {}, but required to be at least {}.", alloc_size, size); failed = true; } if (((address_cast(p) % align) != 0) && (size != 0))