From 1caa9c33330c1927fd9435d919607d513d8b3f89 Mon Sep 17 00:00:00 2001 From: Linus Nordberg Date: Sun, 30 Jul 2017 21:46:29 +0200 Subject: Don't use r if malloc fails. coverity: 1450949 --- util.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'util.c') diff --git a/util.c b/util.c index dc36ed9..a7c7926 100644 --- a/util.c +++ b/util.c @@ -34,8 +34,10 @@ char *stringcopy(const char *s, int len) { r = malloc(len + 1); if (!r) debug(DBG_ERR, "stringcopy: malloc failed"); - memcpy(r, s, len); - r[len] = '\0'; + else { + memcpy(r, s, len); + r[len] = '\0'; + } return r; } -- cgit v1.1