Skip to content

Commit e07ae7d

Browse files
Add a panic helper for non-assert aborts.
We merged a fix for a "maybe uninitialized" warning in #1209, but after merging there could actually have then been a double free. The reason is that when compiling with NDEBUG our assert macro becomes a no-op, meaning that execution would no longer stop after `assert(NULL)`. This commit just adds a simple panic macro which will execute regardless of whether NDEBUG is defined or not.
1 parent bfe45d9 commit e07ae7d

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

test.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,13 @@ static long long usec(void) {
104104
#define assert(e) (void)(e)
105105
#endif
106106

107+
#define redisTestPanic(msg) \
108+
do { \
109+
fprintf(stderr, "PANIC: %s (In function \"%s\", file \"%s\", line %d)\n", \
110+
msg, __func__, __FILE__, __LINE__); \
111+
exit(1); \
112+
} while (1)
113+
107114
/* Helper to extract Redis version information. Aborts on any failure. */
108115
#define REDIS_VERSION_FIELD "redis_version:"
109116
void get_redis_version(redisContext *c, int *majorptr, int *minorptr) {
@@ -232,7 +239,7 @@ static redisContext *do_connect(struct config config) {
232239
c = redisConnectFd(fd);
233240
}
234241
} else {
235-
assert(NULL);
242+
redisTestPanic("Unknown connection type!");
236243
}
237244

238245
if (c == NULL) {
@@ -1352,7 +1359,7 @@ static void test_invalid_timeout_errors(struct config config) {
13521359
} else if(config.type == CONN_UNIX) {
13531360
c = redisConnectUnixWithTimeout(config.unix_sock.path, config.connect_timeout);
13541361
} else {
1355-
assert(NULL);
1362+
redisTestPanic("Unknown connection type!");
13561363
}
13571364

13581365
test_cond(c != NULL && c->err == REDIS_ERR_IO && strcmp(c->errstr, "Invalid timeout specified") == 0);
@@ -1368,7 +1375,7 @@ static void test_invalid_timeout_errors(struct config config) {
13681375
} else if(config.type == CONN_UNIX) {
13691376
c = redisConnectUnixWithTimeout(config.unix_sock.path, config.connect_timeout);
13701377
} else {
1371-
assert(NULL);
1378+
redisTestPanic("Unknown connection type!");
13721379
}
13731380

13741381
test_cond(c != NULL && c->err == REDIS_ERR_IO && strcmp(c->errstr, "Invalid timeout specified") == 0);

0 commit comments

Comments
 (0)