diff options
author | michael-grunder <michael.grunder@gmail.com> | 2023-07-17 10:40:55 -0700 |
---|---|---|
committer | Michael Grunder <michael.grunder@gmail.com> | 2023-07-25 11:16:07 -0700 |
commit | e07ae7d3b6248be8be842eca3e1e97595a17aa1a (patch) | |
tree | 542b96530e6a7a1f575a599d40f29bf660bcf967 | |
parent | bfe45d9f80ae5802fe3547ceccd03e1a66d41062 (diff) | |
download | hiredict-e07ae7d3b6248be8be842eca3e1e97595a17aa1a.tar.xz |
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.
-rw-r--r-- | test.c | 13 |
1 files changed, 10 insertions, 3 deletions
@@ -104,6 +104,13 @@ static long long usec(void) { #define assert(e) (void)(e) #endif +#define redisTestPanic(msg) \ + do { \ + fprintf(stderr, "PANIC: %s (In function \"%s\", file \"%s\", line %d)\n", \ + msg, __func__, __FILE__, __LINE__); \ + exit(1); \ + } while (1) + /* Helper to extract Redis version information. Aborts on any failure. */ #define REDIS_VERSION_FIELD "redis_version:" void get_redis_version(redisContext *c, int *majorptr, int *minorptr) { @@ -232,7 +239,7 @@ static redisContext *do_connect(struct config config) { c = redisConnectFd(fd); } } else { - assert(NULL); + redisTestPanic("Unknown connection type!"); } if (c == NULL) { @@ -1352,7 +1359,7 @@ static void test_invalid_timeout_errors(struct config config) { } else if(config.type == CONN_UNIX) { c = redisConnectUnixWithTimeout(config.unix_sock.path, config.connect_timeout); } else { - assert(NULL); + redisTestPanic("Unknown connection type!"); } 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) { } else if(config.type == CONN_UNIX) { c = redisConnectUnixWithTimeout(config.unix_sock.path, config.connect_timeout); } else { - assert(NULL); + redisTestPanic("Unknown connection type!"); } test_cond(c != NULL && c->err == REDIS_ERR_IO && strcmp(c->errstr, "Invalid timeout specified") == 0); |