diff --git a/src/SFML/Window/Linux/WindowImplX11.cpp b/src/SFML/Window/Linux/WindowImplX11.cpp index e26627ff7..ae684fd5c 100644 --- a/src/SFML/Window/Linux/WindowImplX11.cpp +++ b/src/SFML/Window/Linux/WindowImplX11.cpp @@ -62,19 +62,19 @@ namespace // Find the name of the current executable const char* findExecutableName() { - char buffer[512]; + //Default fallback name + const char* executableName = "sfml"; + static char buffer[512]; std::size_t length = readlink("/proc/self/exe", buffer, sizeof(buffer)); + if ((length > 0) && (length < sizeof(buffer))) { // Remove the path to keep the executable name only buffer[length] = '\0'; - return basename(buffer); - } - else - { - // Fallback name - return "sfml"; + executableName = basename(buffer); } + std::memcpy(buffer, executableName, std::strlen(executableName) + 1); + return buffer; } }