summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorThomas Weißschuh <thomas@t-8ch.de>2023-01-12 00:49:35 +0000
committerThomas Weißschuh <thomas@t-8ch.de>2023-01-12 00:49:35 +0000
commita9b89327746b7c5fbe0cedd8aee992de6580ca8a (patch)
treedf3dfb8a6932bf7faaa34a0ca2d24b9f129d5bac /include
parent3870b182b7b0d98f487e023cd0030c8acd2adc1e (diff)
downloadutil-linux-a9b89327746b7c5fbe0cedd8aee992de6580ca8a.tar.gz
c.h: avoid undefined behavior in SINT_MAX macro
The previous implementation relied on signed-integer overflow. This is undefined behavior. Instead use an implementation that only requires twos-complement representation. This is what everybody uses anyways and it will be required by C23.
Diffstat (limited to 'include')
-rw-r--r--include/c.h2
1 files changed, 1 insertions, 1 deletions
diff --git a/include/c.h b/include/c.h
index 0663774d2..eab6ff505 100644
--- a/include/c.h
+++ b/include/c.h
@@ -526,6 +526,6 @@ static inline void print_features(const char **features, const char *prefix)
# define MAP_ANONYMOUS (MAP_ANON)
#endif
-#define SINT_MAX(t) (((size_t) 1 << (sizeof(t) * 8 - 1)) - 1)
+#define SINT_MAX(t) ((t)((~(t) 0) ^ (t) 1 << (sizeof(t) * 8 - 1)))
#endif /* UTIL_LINUX_C_H */