]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
macro: avoid subtraction overflow in ALIGN_POWER2()
authorLennart Poettering <lennart@poettering.net>
Mon, 9 Dec 2019 17:24:41 +0000 (18:24 +0100)
committerLennart Poettering <lennart@poettering.net>
Mon, 9 Dec 2019 17:34:05 +0000 (18:34 +0100)
src/basic/macro.h

index 18e5085669c0cb20421ff1ccc4bf0846040b7d4f..712bb422b1c2362202e635bd58832a972c131a1c 100644 (file)
@@ -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;