#986226 db.c: add code to account for the case "line == NULL"

Package:
src:nn
Source:
nn
Submitter:
Bjarni Ingi Gislason
Date:
2021-04-01 02:33:04 UTC
Severity:
normal
Tags:
#986226#5
Date:
2021-04-01 02:31:28 UTC
From:
To:
Dear Maintainer,

  Indicated by the compiler option "-fanalyzer":

In function 'readtimfile':
db.c:1427:22: warning: use of NULL 'line' where non-null expected [CWE-690] [-Wanalyzer-null-argument]
 1427 |  char           *p = strchr(line, ' ');
      |                      ^~~~~~~~~~~~~~~~~
...
In file included from db.c:10:
/usr/include/string.h:226:14: note: argument 1 of 'strchr' must be non-null
  226 | extern char *strchr (const char *__s, int __c)
      |              ^~~~~~

Signed-off-by: Bjarni Ingi Gislason <bjarniig@rhi.hi.is>
---
 db.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/db.c b/db.c
index 251be35..257ee5c 100644
--- a/db.c
+++ b/db.c
@@ -1423,9 +1423,13 @@ readtimfile(void)
 #endif				/* NNTP */

     {
-	char           *line = strkeep(timline, 0, POOL_TIM);
-	char           *p = strchr(line, ' ');
-
+	char   *line = strkeep(timline, 0, POOL_TIM);
+	if (line == NULL) {
+		char   *p = NULL;
+	}
+	else {
+		char   *p = strchr(line, ' ');
+	}
 	if (p == NULL)
 	    continue;
 	*p++ = NUL;