mac: Interpret the size returned by _NSGetExecutablePath() correctly

_NSGetExecutablePath() returns a buffer size including space for the
trailing NUL byte. A std::string’s length should be one less than this,
because the std::string’s length does not include the trailing NUL byte
that is guaranteed to be present.

Change-Id: I46b8a68979beda7dc5de09d0eef6f1d3d6a78ecf
Reviewed-on: https://chromium-review.googlesource.com/354100
Reviewed-by: Robert Sesek <rsesek@chromium.org>
This commit is contained in:
Mark Mentovai 2016-06-20 13:37:16 -04:00
parent c281e30f93
commit 6dbf952678

View File

@ -27,7 +27,7 @@ base::FilePath Paths::Executable() {
uint32_t executable_length = 0;
_NSGetExecutablePath(nullptr, &executable_length);
DCHECK_GT(executable_length, 1u);
std::string executable_path(executable_length, std::string::value_type());
std::string executable_path(executable_length - 1, std::string::value_type());
int rv = _NSGetExecutablePath(&executable_path[0], &executable_length);
DCHECK_EQ(rv, 0);