diff --git a/libs/chapter12/reverse_string.cpp b/libs/chapter12/reverse_string.cpp index c6dc7e1..aec0f1f 100644 --- a/libs/chapter12/reverse_string.cpp +++ b/libs/chapter12/reverse_string.cpp @@ -9,7 +9,7 @@ void reverse_str(char *str){ size_t len = strlen(str); - char *tmp = reinterpret_cast(malloc(len)); + char *tmp = reinterpret_cast(malloc(len + 1)); strcpy(tmp, str); for(unsigned int offset = 0; offset < len; ++offset){ str[offset] = tmp[len-offset-1];