diff options
author | Lennart Poettering <lennart@poettering.net> | 2019-12-09 18:24:41 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2019-12-09 18:34:05 +0100 |
commit | 85c267afa7ce4697a1231649de815b2556b3950f (patch) | |
tree | 925df2e8e3c357549a72839939e25d7d8907765e | |
parent | fb4b0465abbd96e6d342e5606c61c919c99a82ff (diff) | |
download | systemd-85c267afa7ce4697a1231649de815b2556b3950f.tar.gz |
macro: avoid subtraction overflow in ALIGN_POWER2()
-rw-r--r-- | src/basic/macro.h | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/src/basic/macro.h b/src/basic/macro.h index 18e5085669..712bb422b1 100644 --- a/src/basic/macro.h +++ b/src/basic/macro.h @@ -163,6 +163,11 @@ static inline size_t ALIGN_TO(size_t l, size_t ali) { /* align to next higher power-of-2 (except for: 0 => 0, overflow => 0) */ static inline unsigned long ALIGN_POWER2(unsigned long u) { + + /* Avoid subtraction overflow */ + if (u == 0) + return 0; + /* clz(0) is undefined */ if (u == 1) return 1; |