]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
contrib/mempattern: silence UBSAN on newer clang docs-ubsan-mempat-hcm04l/deployments/7640 1743/head
authorVladimír Čunát <vladimir.cunat@nic.cz>
Thu, 25 Sep 2025 10:25:10 +0000 (12:25 +0200)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Thu, 25 Sep 2025 10:29:19 +0000 (12:29 +0200)
Equivalent to
https://gitlab.nic.cz/knot/knot-dns/-/commit/27825e4c595d952

The problem happens now with clang 20.
I don't think I've seen it happen with GCC 15
or with some earlier clang versions.

contrib/mempattern.c

index e0c784de1507770183b4ee0ab634f78836d16ee1..ea17eb866aa8692efc33e1d76c00b0fc08c18a82 100644 (file)
@@ -113,10 +113,16 @@ void mm_ctx_init(knot_mm_t *mm)
        mm->free = free;
 }
 
+// UBSAN type punning workaround
+static void *mp_alloc_wrap(void *ctx, size_t size)
+{
+       return mp_alloc(ctx, size);
+}
+
 void mm_ctx_mempool(knot_mm_t *mm, size_t chunk_size)
 {
        mm->ctx = mp_new(chunk_size);
-       mm->alloc = (knot_mm_alloc_t)mp_alloc;
+       mm->alloc = mp_alloc_wrap;
        mm->free = mm_nofree;
 }