Skip to content

Commit 91f6c97

Browse files
authored
Compile with -Wundef (#2025)
This catches spelling errors in macros, like `#if MACCRO`. Signed-off-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
1 parent 49e44e5 commit 91f6c97

File tree

11 files changed

+25
-15
lines changed

11 files changed

+25
-15
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ option(BUILD_EXAMPLE_MODULES "Build example modules" OFF)
1919

2020
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
2121
project("valkey")
22+
add_compile_options(-Wundef)
2223

2324
set(CMAKE_C_STANDARD 11)
2425
set(CMAKE_C_STANDARD_REQUIRED ON)

src/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ ifneq (,$(findstring FreeBSD,$(uname_S)))
4646
STD+=-Wno-c11-extensions
4747
endif
4848
endif
49-
WARN=-Wall -W -Wno-missing-field-initializers -Werror=deprecated-declarations -Wstrict-prototypes
49+
WARN=-Wall -W -Wno-missing-field-initializers -Werror=deprecated-declarations -Wstrict-prototypes -Werror=undef
5050
OPT=$(OPTIMIZATION)
5151

5252
# Detect if the compiler supports C11 _Atomic.

src/config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ void setproctitle(const char *fmt, ...);
283283
#endif /* __aarch64__ && __APPLE__ */
284284
#endif /* CACHE_LINE_SIZE */
285285

286-
#if (__i386 || __amd64 || __powerpc__) && __GNUC__
286+
#if (defined(__i386) || defined(__amd64) || defined(__powerpc__)) && defined(__GNUC__)
287287
#define GNUC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
288288
#if defined(__clang__)
289289
#define HAVE_ATOMIC

src/crcspeed.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ void crcspeed64little_init(crcfn64 crcfn, uint64_t table[8][256]) {
6161
table[k][n] = crc;
6262
}
6363
}
64-
#if USE_STATIC_COMBINE_CACHE
64+
#if defined(USE_STATIC_COMBINE_CACHE) && USE_STATIC_COMBINE_CACHE
6565
/* initialize combine cache for CRC stapling for slice-by 16/24+ */
6666
init_combine_cache(CRC64_REVERSED_POLY, 64);
6767
#endif

src/debug.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1098,7 +1098,7 @@ void serverLogObjectDebugInfo(const robj *o) {
10981098
serverLog(LL_WARNING, "Object type: %u", o->type);
10991099
serverLog(LL_WARNING, "Object encoding: %u", o->encoding);
11001100
serverLog(LL_WARNING, "Object refcount: %d", o->refcount);
1101-
#if UNSAFE_CRASH_REPORT
1101+
#if defined(UNSAFE_CRASH_REPORT) && UNSAFE_CRASH_REPORT
11021102
/* This code is now disabled. o->ptr may be unreliable to print. in some
11031103
* cases a ziplist could have already been freed by realloc, but not yet
11041104
* updated to o->ptr. in other cases the call to ziplistLen may need to

src/lzfP.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,11 @@
133133
* not being able to store offset above UINT32_MAX in 64bit. */
134134
#define LZF_USE_OFFSETS 0
135135

136+
/* Use assembly "rep movsb". Small win on amd, big loss on intel. */
137+
#ifndef USE_REP_MOVSB
138+
# define USE_REP_MOVSB 0
139+
#endif
140+
136141
/*****************************************************************************/
137142
/* nothing should be changed below */
138143

src/rdma.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
#include "server.h"
1818
#include "connection.h"
1919

20-
#if defined __linux__ /* currently RDMA is only supported on Linux */
21-
#if (USE_RDMA == 1 /* BUILD_YES */) || ((USE_RDMA == 2 /* BUILD_MODULE */) && (BUILD_RDMA_MODULE == 2))
20+
#if defined __linux__ && defined USE_RDMA /* currently RDMA is only supported on Linux */
21+
#if (USE_RDMA == 1 /* BUILD_YES */) || \
22+
((USE_RDMA == 2 /* BUILD_MODULE */) && defined(BUILD_RDMA_MODULE) && (BUILD_RDMA_MODULE == 2))
2223
#include "connhelpers.h"
2324

2425
#include <assert.h>
@@ -1884,7 +1885,7 @@ int RegisterConnectionTypeRdma(void) {
18841885

18851886
#endif
18861887

1887-
#if BUILD_RDMA_MODULE == 2 /* BUILD_MODULE */
1888+
#if defined(BUILD_RDMA_MODULE) && BUILD_RDMA_MODULE == 2 /* BUILD_MODULE */
18881889

18891890
#include "release.h"
18901891

src/rio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ static size_t rioFileWrite(rio *r, const void *buf, size_t len) {
131131
serverAssert(processed % r->io.file.autosync == 0);
132132
serverAssert(r->io.file.buffered == r->io.file.autosync);
133133

134-
#if HAVE_SYNC_FILE_RANGE
134+
#if defined(HAVE_SYNC_FILE_RANGE) && HAVE_SYNC_FILE_RANGE
135135
/* Start writeout asynchronously. */
136136
if (sync_file_range(fileno(r->io.file.fp), processed - r->io.file.autosync, r->io.file.autosync,
137137
SYNC_FILE_RANGE_WRITE) == -1)

src/sentinel.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
#include "server.h"
3232
#include "hiredis.h"
33-
#if USE_OPENSSL == 1 /* BUILD_YES */
33+
#if defined(USE_OPENSSL) && USE_OPENSSL == 1 /* BUILD_YES */
3434
#include "openssl/ssl.h"
3535
#include "hiredis_ssl.h"
3636
#endif
@@ -44,7 +44,7 @@
4444

4545
extern char **environ;
4646

47-
#if USE_OPENSSL == 1 /* BUILD_YES */
47+
#if defined(USE_OPENSSL) && USE_OPENSSL == 1 /* BUILD_YES */
4848
extern SSL_CTX *valkey_tls_ctx;
4949
extern SSL_CTX *valkey_tls_client_ctx;
5050
#endif
@@ -2296,7 +2296,7 @@ void sentinelSetClientName(sentinelValkeyInstance *ri, redisAsyncContext *c, cha
22962296
}
22972297

22982298
static int instanceLinkNegotiateTLS(redisAsyncContext *context) {
2299-
#if USE_OPENSSL == 1 /* BUILD_YES */
2299+
#if defined(USE_OPENSSL) && USE_OPENSSL == 1 /* BUILD_YES */
23002300
if (!valkey_tls_ctx) return C_ERR;
23012301
SSL *ssl = SSL_new(valkey_tls_client_ctx ? valkey_tls_client_ctx : valkey_tls_ctx);
23022302
if (!ssl) return C_ERR;

src/setproctitle.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ void spt_init(int argc, char *argv[]) {
232232
if (!(SPT.arg0 = strdup(argv[0])))
233233
goto syerr;
234234

235-
#if __linux__
235+
#if defined __linux__
236236
if (!(tmp = strdup(program_invocation_name)))
237237
goto syerr;
238238

@@ -242,7 +242,7 @@ void spt_init(int argc, char *argv[]) {
242242
goto syerr;
243243

244244
program_invocation_short_name = tmp;
245-
#elif __APPLE__
245+
#elif defined __APPLE__
246246
if (!(tmp = strdup(getprogname())))
247247
goto syerr;
248248

0 commit comments

Comments
 (0)