fix off by one error

This commit is contained in:
Kurtis Rader 2016-04-13 09:00:07 -07:00
parent 706bfa70c1
commit ea3d9c36a5

View file

@ -62,9 +62,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
#include "input_common.h" #include "input_common.h"
#include "wildcard.h" #include "wildcard.h"
/* PATH_MAX may not exist */ // PATH_MAX may not exist.
#ifndef PATH_MAX #ifndef PATH_MAX
#define PATH_MAX 1024 #define PATH_MAX 4096
#endif #endif
/* If we are doing profiling, the filename to output to */ /* If we are doing profiling, the filename to output to */
@ -95,7 +95,7 @@ extern "C" {
// Return the path to the current executable. This needs to be realpath'd. // Return the path to the current executable. This needs to be realpath'd.
static std::string get_executable_path(const char *argv0) static std::string get_executable_path(const char *argv0)
{ {
char buff[PATH_MAX + 1]; char buff[PATH_MAX];
#if __APPLE__ #if __APPLE__
// On OS X use it's proprietary API to get the path to the executable. // On OS X use it's proprietary API to get the path to the executable.
@ -104,11 +104,11 @@ static std::string get_executable_path(const char *argv0)
#else #else
// On non-OS X UNIXes, try /proc directory. // On non-OS X UNIXes, try /proc directory.
ssize_t len; ssize_t len;
len = readlink("/proc/self/exe", buff, sizeof buff); // Linux len = readlink("/proc/self/exe", buff, sizeof buff - 1); // Linux
if (len == -1) { if (len == -1) {
len = readlink("/proc/curproc/file", buff, sizeof buff); // BSD len = readlink("/proc/curproc/file", buff, sizeof buff - 1); // BSD
if (len == -1) { if (len == -1) {
len = readlink("/proc/self/path/a.out", buff, sizeof buff); // Solaris len = readlink("/proc/self/path/a.out", buff, sizeof buff - 1); // Solaris
} }
} }
if (len > 0) { if (len > 0) {