diff options
author | Tomasz Kramkowski <tomasz@kramkow.ski> | 2022-11-01 23:38:48 +0100 |
---|---|---|
committer | Tomasz Kramkowski <tomasz@kramkow.ski> | 2022-11-02 00:25:22 +0100 |
commit | b9c3014e6552253435af9a24122c87cf03bb35b2 (patch) | |
tree | ba7b429a961168a7a4e2c20d8284b4f2696c9cc6 | |
parent | c941c00f7ea53acaa54c30d34c9efbf986072888 (diff) | |
download | pack-b9c3014e6552253435af9a24122c87cf03bb35b2.tar.gz pack-b9c3014e6552253435af9a24122c87cf03bb35b2.tar.xz pack-b9c3014e6552253435af9a24122c87cf03bb35b2.zip |
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.c | 2 |
1 files changed, 1 insertions, 1 deletions
@@ -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_); |