]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw/rgw_cksum: work around -Wsometimes-uninitialized 62946/head
authorMax Kellermann <max.kellermann@ionos.com>
Thu, 24 Apr 2025 11:22:55 +0000 (13:22 +0200)
committerMax Kellermann <max.kellermann@ionos.com>
Thu, 24 Apr 2025 11:27:50 +0000 (13:27 +0200)
clang complains that `cck3` might not be initialized:

```
 /home/jenkins-build/build/workspace/ceph-api/src/rgw/rgw_cksum.cc:74:2: error: variable 'cck3' is used uninitialized whenever switch default is taken [-Werror,-Wsometimes-uninitialized]
    74 |         default:
       |         ^~~~~~~
 /home/jenkins-build/build/workspace/ceph-api/src/rgw/rgw_cksum.cc:78:31: note: uninitialized use occurs here
    78 |         cck3 = rgw::digest::byteswap(cck3);
       |                                      ^~~~
 /home/jenkins-build/build/workspace/ceph-api/src/rgw/rgw_cksum.cc:61:15: note: initialize the variable 'cck3' to silence this warning
    61 |         uint32_t cck3;
       |                      ^
       |                       = 0
```

The `default:` case however is not reachable because `ck1.type` has
already been checked.  Adding initializers to `cck3` would only hide
potential future bugs, therefore I suggest just bailing out of the
function for this unreachable piece of code.  With C++23, we could use
`std::unreachable()` instead.

Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
src/rgw/rgw_cksum.cc

index e6e4c5b56353c4fc92579d36aaaa8f07e92dc51f..bef606bb9aa598e8d724097c26664f1e9dff1078 100644 (file)
@@ -72,7 +72,9 @@ namespace rgw::cksum {
          cck3 =  crc32iscsi_comb(cck1, cck2, len1);
          break;
        default:
-         break;
+         /* unreachable (already checked by outer switch/case) */
+         // TODO change to std::unreachable() once we are C++23
+         goto out;
        }
         /* and byteswap */
        cck3 = rgw::digest::byteswap(cck3);