From 6cc5b601aa36a7ede89ab13274cb334aa92f5cf7 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Wed, 27 Dec 2017 22:11:00 -0800 Subject: [PATCH] Cleanup: avoid dereferencing NULL pointer Coverity CID 208330 Coverity CID 208301 Signed-off-by: Dirk Hohndel --- core/file.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/core/file.c b/core/file.c index e818c9e21..d604f94cd 100644 --- a/core/file.c +++ b/core/file.c @@ -927,6 +927,11 @@ int parse_dan_format(const char *filename, char **params, int pnr) ++iter; } + if (!iter) { + fprintf(stderr, "DEBUG: Data corrupt"); + return -1; + } + /* Setting date */ memcpy(tmpbuf, iter, 8); tmpbuf[8] = 0; @@ -950,9 +955,12 @@ int parse_dan_format(const char *filename, char **params, int pnr) } if (ptr) ptr = strstr(ptr, NL); - if (ptr) + if (ptr) { ptr += strlen(NL); - + } else { + fprintf(stderr, "DEBUG: Data corrupt"); + return -1; + } end_ptr = ptr - (char *)mem.buffer; /* Copy the current dive data to start of mem_csv buffer */