aboutgitcodebugslistschat
path: root/util.h
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2023-11-30 13:02:11 +1100
committerStefano Brivio <sbrivio@redhat.com>2023-12-04 09:51:06 +0100
commit9d44aba7e05ea84a3dd7192c97f561b962cac5b9 (patch)
treeee03a94e5107544ea7299067ed4191969ce2739f /util.h
parente2e8219f13b80cef257134ebcb4d2616b2f1578c (diff)
downloadpasst-9d44aba7e05ea84a3dd7192c97f561b962cac5b9.tar
passt-9d44aba7e05ea84a3dd7192c97f561b962cac5b9.tar.gz
passt-9d44aba7e05ea84a3dd7192c97f561b962cac5b9.tar.bz2
passt-9d44aba7e05ea84a3dd7192c97f561b962cac5b9.tar.lz
passt-9d44aba7e05ea84a3dd7192c97f561b962cac5b9.tar.xz
passt-9d44aba7e05ea84a3dd7192c97f561b962cac5b9.tar.zst
passt-9d44aba7e05ea84a3dd7192c97f561b962cac5b9.zip
util: MAX_FROM_BITS() should be unsigned
MAX_FROM_BITS() computes the maximum value representable in a number of bits. The expression for that is an unsigned value, but we explicitly cast it to a signed int. It looks like this is because one of the main users is for FD_REF_MAX, which is used to bound fd values, typically stored as a signed int. The value MAX_FROM_BITS() is calculating is naturally non-negative, though, so it makes more sense for it to be unsigned, and to move the case to the definition of FD_REF_MAX. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'util.h')
-rw-r--r--util.h2
1 files changed, 1 insertions, 1 deletions
diff --git a/util.h b/util.h
index 86f1a7e..53bb54b 100644
--- a/util.h
+++ b/util.h
@@ -43,7 +43,7 @@
#define ROUND_DOWN(x, y) ((x) & ~((y) - 1))
#define ROUND_UP(x, y) (((x) + (y) - 1) & ~((y) - 1))
-#define MAX_FROM_BITS(n) ((int)((1U << (n)) - 1))
+#define MAX_FROM_BITS(n) (((1U << (n)) - 1))
#define BIT(n) (1UL << (n))
#define BITMAP_BIT(n) (BIT((n) % (sizeof(long) * 8)))