From df2833b318ee1d8bac8253bb3f7d3b65d6cb72aa Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 8 Jun 2026 08:09:10 +1000 Subject: [PATCH] io: drop the dead/unnecessary read_varint UBSan guard The cherry-picked #428 wrapped no_sanitize attributes on read_varint() and read_varlong() in `#ifndef CAREFUL_ALIGNMENT`, but byteorder.h always #defines CAREFUL_ALIGNMENT (to 0 or 1), so that guard is never true and the attributes were dead code. They are also unnecessary: both functions read the assembled value through an aligned union member (union { char b[5]; int32 x; }), not an unaligned cast, so UBSan's alignment check never fires there (verified: the ASan+UBSan suite is clean without them). Remove the whole block rather than fix the guard. (The byteorder.h annotations from #428, which are real and correctly placed inside the !CAREFUL_ALIGNMENT branch, are kept.) --- io.c | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/io.c b/io.c index 8d240e44..0b96c270 100644 --- a/io.c +++ b/io.c @@ -1813,13 +1813,6 @@ uint32 read_uint(int f) return IVAL(b, 0); } -#ifndef CAREFUL_ALIGNMENT -#ifdef __clang__ -__attribute__((no_sanitize("undefined"))) -#elif GCC_VERSION >= 409 -__attribute__((no_sanitize_undefined)) -#endif -#endif int32 read_varint(int f) { union { @@ -1852,13 +1845,6 @@ int32 read_varint(int f) return u.x; } -#ifndef CAREFUL_ALIGNMENT -#ifdef __clang__ -__attribute__((no_sanitize("undefined"))) -#elif GCC_VERSION >= 409 -__attribute__((no_sanitize_undefined)) -#endif -#endif int64 read_varlong(int f, uchar min_bytes) { union {