From c7a649afb930d5c44d274af6be7bb2b81e189674 Mon Sep 17 00:00:00 2001 From: Peter Howkins Date: Fri, 13 Jul 2018 19:11:29 +0100 Subject: [PATCH] dtcm: Coverity 88006 --- cde/programs/dtcm/dtcm/misc.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/cde/programs/dtcm/dtcm/misc.c b/cde/programs/dtcm/dtcm/misc.c index 55d563a2..b7214123 100644 --- a/cde/programs/dtcm/dtcm/misc.c +++ b/cde/programs/dtcm/dtcm/misc.c @@ -623,7 +623,7 @@ extern char * cm_mbchar(char *str) { static char *string; static char *string_head; - static char *buf; + static char *buf = NULL; int num_byte = 0; if ( str != NULL ) { @@ -644,10 +644,12 @@ cm_mbchar(char *str) { string_head = NULL; } else { num_byte = mblen(string, MB_LEN_MAX); - buf = (char *)malloc(num_byte+1); - strncpy(buf, string, num_byte); - buf[num_byte] = '\0'; - string += num_byte; + if(num_byte > 0) { + buf = (char *)malloc(num_byte+1); + strncpy(buf, string, num_byte); + buf[num_byte] = '\0'; + string += num_byte; + } } return buf; -- 2.25.1