From: Lennart Poettering Date: Mon, 9 Dec 2019 17:24:41 +0000 (+0100) Subject: macro: avoid subtraction overflow in ALIGN_POWER2() X-Git-Tag: v245-rc1~289^2~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=85c267afa7ce4697a1231649de815b2556b3950f;p=thirdparty%2Fsystemd.git macro: avoid subtraction overflow in ALIGN_POWER2() --- diff --git a/src/basic/macro.h b/src/basic/macro.h index 18e5085669c..712bb422b1c 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;