From bc2f7c12c035d98e03341629c68f21c639386d91 Mon Sep 17 00:00:00 2001 From: Sumit Bose Date: Mon, 24 Jan 2011 11:33:50 +0100 Subject: Ensure error_string() never returns NULL A Coverity check indicated that ther are platforms where strerror() will return NULL for unknown, e.g. negative error numbers. Chances are that these platforms will have problems with NULL arguments to printf() too. --- dhash/examples/dhash_test.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/dhash/examples/dhash_test.c b/dhash/examples/dhash_test.c index 8c11227..7b4cbbf 100644 --- a/dhash/examples/dhash_test.c +++ b/dhash/examples/dhash_test.c @@ -35,10 +35,21 @@ int verbose = 0; const char *error_string(int error) { + const char *str; + if (IS_HASH_ERROR(error)) return hash_error_string(error); - return strerror(error); + if (error < 0) { + return "Negative error codes are not supported."; + } + + str = strerror(error); + if (str == NULL) { + return "strerror() returned NULL."; + } + + return str; } char *key_string(hash_key_t *key) -- cgit