]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
exec-util: use unsigned shift for ExecCommandFlags
authorLuca Boccassi <luca.boccassi@gmail.com>
Sat, 28 Mar 2026 20:13:40 +0000 (20:13 +0000)
committerLuca Boccassi <luca.boccassi@gmail.com>
Sat, 28 Mar 2026 20:13:40 +0000 (20:13 +0000)
Using signed int literal '1' in left shift operations can
theoretically lead to undefined behavior. Use 1U to be explicit
about unsigned arithmetic.

CID#1548018

Follow-up for b3d593673c5b8b0b7d781fd26ab2062ca6e7dbdb

src/shared/exec-util.c

index 2e15f311b88537c6b813128f2b8f6f48b15bd92f..420803c77d43d4b846c92a6b6e709204d471dcda 100644 (file)
@@ -500,7 +500,7 @@ assert_cc((1 << ELEMENTSOF(exec_command_strings)) - 1 == _EXEC_COMMAND_FLAGS_ALL
 
 const char* exec_command_flags_to_string(ExecCommandFlags i) {
         for (size_t idx = 0; idx < ELEMENTSOF(exec_command_strings); idx++)
-                if (i == (1 << idx))
+                if (i == (ExecCommandFlags) (1U << idx))
                         return exec_command_strings[idx];
 
         return NULL;
@@ -516,7 +516,7 @@ ExecCommandFlags exec_command_flags_from_string(const char *s) {
         if (idx < 0)
                 return _EXEC_COMMAND_FLAGS_INVALID;
 
-        return 1 << idx;
+        return 1U << idx;
 }
 
 int fexecve_or_execve(int executable_fd, const char *executable, char *const argv[], char *const envp[]) {