]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
[test_utils] Fix a minor UB
authorTim Kientzle <kientzle@acm.org>
Fri, 8 May 2026 04:50:50 +0000 (21:50 -0700)
committerTim Kientzle <kientzle@acm.org>
Fri, 8 May 2026 04:50:50 +0000 (21:50 -0700)
(UBSan occasionally finds something interesting and
often reports whacky non-bugs like this one. "Fixing"
it will make the real UB bugs easier to identify, so...)

According to C's integer promotion rules, `unsigned short` gets
promoted to _signed_ `int`, and shifting into the sign bit of an `int`
is technically UB.  Explicit cast to `unsigned` quiets UBSan.

test_utils/test_utils.c

index be717f4ccfe09a2bd63f43a1930ee644ff43a7a3..a24b0272cb1f6728fa8356a4033d93adee67b761 100644 (file)
@@ -149,7 +149,7 @@ unsigned int
 i4le(const void* p_)
 {
        const char *p = p_;
-       return (i2le(p) | (i2le(p + 2) << 16));
+       return (i2le(p) | ((unsigned int)i2le(p + 2) << 16));
 }
 unsigned long long
 i8le(const void* p_)