]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
macro: sizeof() returns size_t, and that's good
authorLennart Poettering <lennart@poettering.net>
Thu, 29 Jul 2021 15:45:19 +0000 (17:45 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 30 Jul 2021 13:58:09 +0000 (15:58 +0200)
Now that CONST_MAX() is a bit more foregiving, let's stick to the native
return type of sizeof() everywhere, which is size_t, instead of casting
to "unsigned", so that on the common archs we don't unnecessarily lose
the upper 32bits.

This semi-reverts d3e40294572512810c9329933a488619e7ce22fd.

src/basic/macro.h

index a8476184c2d8dce06e641a4a696cde2d60003e6d..829d8dc8a7093c7dae8e0e137d264e63b0fdadbb 100644 (file)
@@ -214,7 +214,7 @@ static inline size_t GREEDY_ALLOC_ROUND_UP(size_t l) {
  *          Contrary to strlen(), this is a constant expression.
  * @x: a string literal.
  */
-#define STRLEN(x) ((unsigned) sizeof(""x"") - 1)
+#define STRLEN(x) (sizeof(""x"") - 1U)
 
 /*
  * container_of - cast a member of a structure out to the containing structure
@@ -345,7 +345,7 @@ static inline int __coverity_check_and_return__(int condition) {
         (2U+(sizeof(type) <= 1 ? 3U :                                   \
              sizeof(type) <= 2 ? 5U :                                   \
              sizeof(type) <= 4 ? 10U :                                  \
-             sizeof(type) <= 8 ? 20U : (unsigned) sizeof(int[-2*(sizeof(type) > 8)])))
+             sizeof(type) <= 8 ? 20U : sizeof(int[-2*(sizeof(type) > 8)])))
 
 #define DECIMAL_STR_WIDTH(x)                            \
         ({                                              \