dtcm: Coverity 88006
authorPeter Howkins <flibble@users.sf.net>
Fri, 13 Jul 2018 18:11:29 +0000 (19:11 +0100)
committerPeter Howkins <flibble@users.sf.net>
Fri, 13 Jul 2018 18:11:29 +0000 (19:11 +0100)
cde/programs/dtcm/dtcm/misc.c

index 55d563a2555a64b4654a75ab67567cd1cbf8eb03..b72141234ca11521297b1ef5745d0f1c5715aade 100644 (file)
@@ -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;