Merge branch 'master' into cde-next
[oweals/cde.git] / cde / programs / dtcm / dtcm / misc.c
index eea23dd3d98d22e44a8ae0e457dce96c565ff0cd..118ad3d12bee65e0b2d497601ee160d6d2a091f8 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;