aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Kramkowski <tk@the-tk.com>2020-09-11 01:15:48 +0100
committerTomasz Kramkowski <tk@the-tk.com>2020-09-11 01:15:48 +0100
commit92483316beaab8082635c35a5aca7cbe18b4d9f3 (patch)
tree7f4f64abfb0aa52c60c240e7a1eaed836959f12a
parent2644c6fc2c99b63936c3e505340e597b1c1f4fa7 (diff)
downloadpack-92483316beaab8082635c35a5aca7cbe18b4d9f3.tar.gz
pack-92483316beaab8082635c35a5aca7cbe18b4d9f3.tar.xz
pack-92483316beaab8082635c35a5aca7cbe18b4d9f3.zip
unpack: Add BITMASK helper macro
-rw-r--r--unpack.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/unpack.c b/unpack.c
index 5331525..1bf0ddf 100644
--- a/unpack.c
+++ b/unpack.c
@@ -18,6 +18,8 @@
enum endian { BIG, LITTLE };
+#define BITMASK(n) (UINTMAX_MAX >> (sizeof (uintmax_t) * CHAR_BIT - n))
+
static float ieee754tof(uintmax_t b)
{
bool isneg;
@@ -144,7 +146,7 @@ enum pack_status unpack(void *buf_, size_t size, const char *fmt, ...)
if (!(val.u & (UINTMAX_C(1) << (s * 8 - 1)))) {
vals = val.u;
} else {
- uintmax_t offt = UINTMAX_MAX >> (sizeof offt * CHAR_BIT - s * 8);
+ uintmax_t offt = BITMASK(s * 8);
vals = val.u - offt - 1;
}
val.s = vals;