From 7bd8874cf3ea8d1922c999092b0a17bdd590e5cd Mon Sep 17 00:00:00 2001 From: Mathieu Schroeter Date: Sat, 11 Feb 2017 23:19:47 +0100 Subject: [PATCH] Fix memory overflow --- src/misc.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/misc.cpp b/src/misc.cpp index 88729b0..23cb809 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -101,22 +101,21 @@ void AddUserPath(char *pFilename) char last; temp = SDL_GetPrefPath ("Epsitec SA", "Planet Blupi"); + std::string path = temp; pText = strstr(pFilename, "/"); if ( pText != nullptr ) { - pos = strlen(temp)+(pText-pFilename)+1; - strcat(temp, pFilename); - last = temp[pos]; - temp[pos] = 0; - mkdir (temp, 755); - temp[pos] = last; + pos = path.size () + (pText - pFilename) + 1; + path += pFilename; + last = path[pos]; + path[pos] = 0; + mkdir (path.c_str (), 755); + path[pos] = last; } else - { - strcat(temp, pFilename); - } + path += pFilename; - strcpy(pFilename, temp); + strcpy(pFilename, path.c_str ()); SDL_free (temp); }