From 3c429387f2cee104ce9792aad3d204c9c90fc2e3 Mon Sep 17 00:00:00 2001 From: Emmanuel Atse Date: Thu, 18 Jul 2013 04:04:22 +0200 Subject: [PATCH] Fixed undefined behavior of returned pointer --- src/SFML/Window/Linux/WindowImplX11.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) 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; } }