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

This commit is contained in:
Andreas Kling 2019-02-03 11:48:41 +01:00
commit ab56f36bfb
Notes: sideshowbarker 2024-07-19 15:52:58 +09:00

View file

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