aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Kramkowski <tomasz@kramkow.ski>2022-11-01 23:38:48 +0100
committerTomasz Kramkowski <tomasz@kramkow.ski>2022-11-02 00:25:22 +0100
commitb9c3014e6552253435af9a24122c87cf03bb35b2 (patch)
treeba7b429a961168a7a4e2c20d8284b4f2696c9cc6
parentc941c00f7ea53acaa54c30d34c9efbf986072888 (diff)
downloadpack-master.tar.gz
pack-master.tar.xz
pack-master.zip
unpack.c: Cast negative signed offset to signedHEADmaster
As N1570ยง6.5.16.2p3 states, E1 += E2 is equivalent to E1 = E1 + (E2). This means that E1 + (E2) will be subject to (6.5.6p4) "the usual arithmetic conversions". Since both types have equal integer conversion rank (6.3.1.1p1), E1 which was intmax_t will first be converted to uintmax_t before being added to (E2). This is not the intended result as it relies on integer wrapping behaviour again. Casting E2 to intmax_t first prevents the conversion of E1 and produces the correct result.
-rw-r--r--unpack.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/unpack.c b/unpack.c
index 7786ca6..45ba8fd 100644
--- a/unpack.c
+++ b/unpack.c
@@ -79,7 +79,7 @@ static void read_fields(struct dest dest, const void *src_, enum pack_endian end
vals = val.unsigned_;
} else {
vals = minval(s);
- vals += val.unsigned_ ^ (UINTMAX_C(1) << (s * 8 - 1));
+ vals += (intmax_t)(val.unsigned_ ^ (UINTMAX_C(1) << (s * 8 - 1)));
}
val.signed_ = vals;
tr_debug("val.s: %" PRIdMAX, val.signed_);