From 4384183ab856a5087586ae283a4e25671af782cb Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 29 Oct 2015 11:20:09 +0100 Subject: [PATCH] coverity scan CID 22504: argument cannot be negative handle error cases for ftell, just because they could happen, I guess? --- src/bind_config.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/bind_config.c b/src/bind_config.c index 66f3cb47f..a80cd279f 100644 --- a/src/bind_config.c +++ b/src/bind_config.c @@ -67,14 +67,16 @@ int config_read(const char *filename, const char * relpath) if (F) { int result; char *data; - size_t sz; fseek(F, 0, SEEK_END); - sz = ftell(F); + result = ftell(F); rewind(F); - data = malloc(sz); - fread(data, 1, sz, F); - fclose(F); + if (result > 0) { + size_t sz = (size_t)result; + data = malloc(sz); + fread(data, 1, sz, F); + fclose(F); + } result = config_parse(data); free(data); return result;