diff options
author | Darshan Shaligram <dshaligram@users.sourceforge.net> | 2009-10-02 16:59:12 +0530 |
---|---|---|
committer | Darshan Shaligram <dshaligram@users.sourceforge.net> | 2009-10-04 22:45:49 +0530 |
commit | 94fc68984cda3ddc502acae229170529e722f4af (patch) | |
tree | f582b8d014f46c74770e4b610112f0776b236adc | |
parent | 0a9bc55e9cd63d2badb476ff24d5cb66d4a15950 (diff) | |
download | crawl-ref-94fc68984cda3ddc502acae229170529e722f4af.tar.gz crawl-ref-94fc68984cda3ddc502acae229170529e722f4af.zip |
readlink does not NULL-terminate, must terminate explicitly.
-rw-r--r-- | crawl-ref/source/initfile.cc | 15 |
1 files 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); |