From: Vladimír Čunát Date: Thu, 25 Sep 2025 10:25:10 +0000 (+0200) Subject: contrib/mempattern: silence UBSAN on newer clang X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fmerge-requests%2F1743%2Fhead;p=thirdparty%2Fknot-resolver.git contrib/mempattern: silence UBSAN on newer clang 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. --- diff --git a/contrib/mempattern.c b/contrib/mempattern.c index e0c784de1..ea17eb866 100644 --- a/contrib/mempattern.c +++ b/contrib/mempattern.c @@ -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; }