mirror of
https://github.com/SFML/SFML.git
synced 2025-02-18 06:18:01 +08:00
Fixed undefined behavior of returned pointer
This commit is contained in:
parent
b3357eed2a
commit
3c429387f2
@ -62,19 +62,19 @@ namespace
|
|||||||
// Find the name of the current executable
|
// Find the name of the current executable
|
||||||
const char* findExecutableName()
|
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));
|
std::size_t length = readlink("/proc/self/exe", buffer, sizeof(buffer));
|
||||||
|
|
||||||
if ((length > 0) && (length < sizeof(buffer)))
|
if ((length > 0) && (length < sizeof(buffer)))
|
||||||
{
|
{
|
||||||
// Remove the path to keep the executable name only
|
// Remove the path to keep the executable name only
|
||||||
buffer[length] = '\0';
|
buffer[length] = '\0';
|
||||||
return basename(buffer);
|
executableName = basename(buffer);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Fallback name
|
|
||||||
return "sfml";
|
|
||||||
}
|
}
|
||||||
|
std::memcpy(buffer, executableName, std::strlen(executableName) + 1);
|
||||||
|
return buffer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user