From 08ae1917e8a5957bdb9267c20dbaad6d89fae4f1 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Wed, 25 Jan 2023 20:33:23 +0100 Subject: [PATCH] Fix proper `readlink` usage on Linux to get app path --- Source/Engine/Platform/Linux/LinuxPlatform.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Source/Engine/Platform/Linux/LinuxPlatform.cpp b/Source/Engine/Platform/Linux/LinuxPlatform.cpp index a5bd099c9..fc265d7ea 100644 --- a/Source/Engine/Platform/Linux/LinuxPlatform.cpp +++ b/Source/Engine/Platform/Linux/LinuxPlatform.cpp @@ -2714,8 +2714,10 @@ Rectangle LinuxPlatform::GetVirtualDesktopBounds() String LinuxPlatform::GetMainDirectory() { char buffer[UNIX_APP_BUFF_SIZE]; - readlink("/proc/self/exe", buffer, UNIX_APP_BUFF_SIZE); - const String str(buffer); + const int32 len = readlink("/proc/self/exe", buffer, UNIX_APP_BUFF_SIZE); + if (len <= 0) + return String::Empty; + const String str(buffer, len); int32 pos = str.FindLast(TEXT('/')); if (pos != -1 && ++pos < str.Length()) return str.Left(pos); @@ -2725,8 +2727,10 @@ String LinuxPlatform::GetMainDirectory() String LinuxPlatform::GetExecutableFilePath() { char buffer[UNIX_APP_BUFF_SIZE]; - readlink("/proc/self/exe", buffer, UNIX_APP_BUFF_SIZE); - return String(buffer); + const int32 len = readlink("/proc/self/exe", buffer, UNIX_APP_BUFF_SIZE); + if (len <= 0) + return String::Empty; + return String(buffer, len); } Guid LinuxPlatform::GetUniqueDeviceId()