summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSumit Bose <sbose@redhat.com>2011-01-24 11:33:50 +0100
committerStephen Gallagher <sgallagh@redhat.com>2012-04-25 07:44:59 -0400
commitbc2f7c12c035d98e03341629c68f21c639386d91 (patch)
tree9a447347fb9b396f271e141aaffa6d422893c3a0
parentadd869cb76e6ba1e3a16923faf83b68148e9278b (diff)
downloadding-libs-bc2f7c12c035d98e03341629c68f21c639386d91.tar.gz
ding-libs-bc2f7c12c035d98e03341629c68f21c639386d91.tar.xz
ding-libs-bc2f7c12c035d98e03341629c68f21c639386d91.zip
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.
-rw-r--r--dhash/examples/dhash_test.c13
1 files changed, 12 insertions, 1 deletions
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)