]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Avoid dead code warning when using a constant boolean
authorTony Finch <dot@dotat.at>
Wed, 5 Oct 2022 11:11:41 +0000 (12:11 +0100)
committerTony Finch <fanf@isc.org>
Wed, 5 Oct 2022 15:51:05 +0000 (15:51 +0000)
The value of `sign_bit` is platform-dependent but constant at compile
time. Use a cast to convert the boolean `sign_bit` to 0 or 1 instead of
ternary `?:` because one branch of the conditional is dead code. (We
could leave out the cast to `size_t` but our style prefers to handle
booleans more explicitly, hence the `?:` that caused the issue.)

    *** CID 358310:  Possible Control flow issues  (DEADCODE)
    /lib/isc/resource.c: 118 in isc_resource_setlimit()
    112       * rlim_t, and whether rlim_t has a sign bit.
    113       */
    114      isc_resourcevalue_t rlim_max = UINT64_MAX;
    115      size_t wider = sizeof(rlim_max) - sizeof(rlim_t);
    116      bool sign_bit = (double)(rlim_t)-1 < 0;
    117
    >>>     CID 358310:  Possible Control flow issues  (DEADCODE)
    >>>     Execution cannot reach the expression "1" inside this statement: "rlim_max >>= 8UL * wider + ...".
    118      rlim_max >>= CHAR_BIT * wider + (sign_bit ? 1 : 0);
    119      rlim_value = ISC_MIN(value, rlim_max);
    120      }
    121
    122      rl.rlim_cur = rl.rlim_max = rlim_value;
    123      unixresult = setrlimit(unixresource, &rl);

lib/isc/resource.c

index 2f5b47742e46532decb1e7ebc0120dfd5c150568..f6965755dbe8327a055d4e28719eda3d2ce7ddcc 100644 (file)
@@ -113,9 +113,9 @@ isc_resource_setlimit(isc_resource_t resource, isc_resourcevalue_t value) {
                 */
                isc_resourcevalue_t rlim_max = UINT64_MAX;
                size_t wider = sizeof(rlim_max) - sizeof(rlim_t);
-               bool sign_bit = (double)(rlim_t)-1 < 0;
+               size_t sign_bit = (size_t)(0.0 > (double)(rlim_t)-1);
 
-               rlim_max >>= CHAR_BIT * wider + (sign_bit ? 1 : 0);
+               rlim_max >>= CHAR_BIT * wider + sign_bit;
                rlim_value = ISC_MIN(value, rlim_max);
        }