Sfoglia il codice sorgente

LibC: strdup() forgot to allocate space for the null character.

Andreas Kling 6 anni fa
parent
commit
ab56f36bfb
1 ha cambiato i file con 1 aggiunte e 1 eliminazioni
  1. 1 1
      LibC/string.cpp

+ 1 - 1
LibC/string.cpp

@@ -55,7 +55,7 @@ size_t strlen(const char* str)
 char* strdup(const char* str)
 {
     size_t len = strlen(str);
-    char* new_str = (char*)malloc(len);
+    char* new_str = (char*)malloc(len + 1);
     strcpy(new_str, str);
     return new_str;
 }