]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
musl: avoid multiple evaluations in CPU_ISSET_S() macro
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 1 Jul 2025 03:53:14 +0000 (12:53 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 12 Nov 2025 23:02:05 +0000 (08:02 +0900)
musl's CPU_ISSET_S() macro does not avoid multiple evaluations, and it
only accepts simple variable or constant.

Fixes the following error.
```
../src/shared/cpu-set-util.c: In function ‘cpu_set_to_mask_string’:
../src/shared/cpu-set-util.c:101:41: warning: operation on ‘i’ may be undefined [-Werror=sequence-point]
  101 |                         if (CPU_ISSET_S(--i, c->allocated, c->set))
      |                                         ^
```

src/shared/cpu-set-util.c

index 25288046c148993ae23fa603f23a37271f73e1e0..a9bdd235f81c0cf41572690d1bca5b6eed92fc5b 100644 (file)
@@ -96,9 +96,11 @@ char* cpu_set_to_mask_string(const CPUSet *c) {
         for (size_t i = c->allocated * 8; i > 0; ) {
                 uint32_t m = 0;
 
-                for (int j = (i % 32 ?: 32) - 1; j >= 0; j--)
-                        if (CPU_ISSET_S(--i, c->allocated, c->set))
+                for (int j = (i % 32 ?: 32) - 1; j >= 0; j--) {
+                        --i;
+                        if (CPU_ISSET_S(i, c->allocated, c->set))
                                 SET_BIT(m, j);
+                }
 
                 if (!found_nonzero) {
                         if (m == 0)