Skip to content

src/rdma.c: unused variable warnings with -DNDEBUG (treated as error with -Werror) #311

@trim21

Description

@trim21

Description

When building libvalkey v0.5.0 with -DNDEBUG -Werror, compilation fails in src/rdma.c:

src/rdma.c:1039:36: error: variable 'event' set but not used [-Werror=unused-but-set-variable]
 1039 |     struct epoll_event events[1], *event;
      |                                    ^~~~~
src/rdma.c:1038:18: error: unused variable 'ctx' [-Werror=unused-variable]
 1038 |     RdmaContext *ctx = c->privctx;
      |                  ^~~

Root Cause

In the valkeyRdmaWaitConn function, both ctx and event are only used inside an assert() call:

event = &events[0];
assert(event->data.fd == ctx->cm_channel->fd);

When building with -DNDEBUG, the assert() macro is removed by the preprocessor, leaving both variables unused. Since the build uses -Werror, these warnings become fatal errors.

Suggested Fix

Add VALKEY_UNUSED (already defined in include/valkey/async.h and used elsewhere in the same file) to both variable declarations:

-    RdmaContext *ctx = c->privctx;
-    struct epoll_event events[1], *event;
+    VALKEY_UNUSED RdmaContext *ctx = c->privctx;
+    struct epoll_event events[1];
+    VALKEY_UNUSED struct epoll_event *event;

Reproducer

cmake . -B build -DCMAKE_BUILD_TYPE=Release -DENABLE_RDMA=1 -G Ninja
ninja -C build

NDEBUG is implicitly defined in CMake Release builds.

This issue was found while packaging for conda-forge: conda-forge/libvalkey-feedstock#15

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions