From 94fc68984cda3ddc502acae229170529e722f4af Mon Sep 17 00:00:00 2001 From: Darshan Shaligram Date: Fri, 2 Oct 2009 16:59:12 +0530 Subject: readlink does not NULL-terminate, must terminate explicitly. --- crawl-ref/source/initfile.cc | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/crawl-ref/source/initfile.cc b/crawl-ref/source/initfile.cc index d38f411eb0..4cc5d74b19 100644 --- a/crawl-ref/source/initfile.cc +++ b/crawl-ref/source/initfile.cc @@ -3452,21 +3452,16 @@ std::string find_executable_path() tempPath[0] = 0; #if defined ( _MSC_VER ) - - int retval = GetModuleFileName ( NULL, tempPath, sizeof(tempPath) ); - + GetModuleFileName ( NULL, tempPath, sizeof(tempPath) ); #elif defined ( __linux__ ) - - int retval = readlink ( "/proc/self/exe", tempPath, sizeof(tempPath) ); - + const ssize_t rsize = + readlink("/proc/self/exe", tempPath, sizeof(tempPath) - 1); + if (rsize > 0) + tempPath[rsize] = 0; #elif defined ( __MACH__ ) - strncpy ( tempPath, NXArgv[0], sizeof(tempPath) ); - #else - // We don't know how to find the executable's path on this OS. - #endif return std::string(tempPath); -- cgit v1.2.3-54-g00ecf