NetworkBlockDevice / nbd

Network Block Device
GNU General Public License v2.0
450 stars 116 forks source link

fix clang 14 warnings in nbd-server.c #160

Closed RokerHRO closed 5 months ago

RokerHRO commented 5 months ago

Clang 14 on macOS 12.7.4 (and I guess also newer versions) emits these warnings when compiling nbd-server.c:

  CC       nbd_server-nbd-server.o
nbd-server.c:2885:15: warning: & has lower precedence than !=; != will be evaluated first [-Wparentheses]
        if(req->type & NBD_CMD_FLAG_DF != 0) {
                     ^~~~~~~~~~~~~~~~~~~~~~
nbd-server.c:2885:15: note: place parentheses around the '!=' expression to silence this warning
        if(req->type & NBD_CMD_FLAG_DF != 0) {
                     ^ ~~~~~~~~~~~~~~~~~~~~
nbd-server.c:2885:15: note: place parentheses around the & expression to evaluate it first
        if(req->type & NBD_CMD_FLAG_DF != 0) {
           ~~~~~~~~~~^~~~~~~~~~~~~~~~~
nbd-server.c:3315:10: warning: result of comparison of constant 18446744073709551614 with expression of type 'uint32_t' (aka 'unsigned int') is always false [-Wtautological-constant-out-of-range-compare]
        if (len >= ULONG_MAX - 1) {
            ~~~ ^  ~~~~~~~~~~~~~

This commit will address these 2 warnings and fix the code.

RokerHRO commented 5 months ago

Thank you. :-)