Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1350)

Unified Diff: base/sys_info_linux.cc

Issue 8382001: OpenBSD patches for base and build, part 2 (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: remove newline from string Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/sys_info_freebsd.cc ('k') | base/sys_info_openbsd.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/sys_info_linux.cc
diff --git a/base/sys_info_linux.cc b/base/sys_info_linux.cc
index 67bfe5a64e0d4f2b5644977eb7ff142d5fd31e45..b4fc1c20dc13e29b5c1e23a50f82d0188d43df46 100644
--- a/base/sys_info_linux.cc
+++ b/base/sys_info_linux.cc
@@ -4,8 +4,11 @@
#include "base/sys_info.h"
+#include <limits>
+
#include "base/file_util.h"
#include "base/logging.h"
+#include "base/string_number_conversions.h"
namespace base {
@@ -22,15 +25,25 @@ int64 SysInfo::AmountOfPhysicalMemory() {
// static
size_t SysInfo::MaxSharedMemorySize() {
- static size_t limit;
+ static int64 limit;
static bool limit_valid = false;
if (!limit_valid) {
std::string contents;
file_util::ReadFileToString(FilePath("/proc/sys/kernel/shmmax"), &contents);
- limit = strtoul(contents.c_str(), NULL, 0);
- limit_valid = true;
+ DCHECK(!contents.empty());
+ if (!contents.empty() && contents[contents.length() - 1] == '\n') {
+ contents.erase(contents.length() - 1);
+ }
+ if (base::StringToInt64(contents, &limit)) {
+ DCHECK(limit >= 0);
+ DCHECK(static_cast<uint64>(limit) <= std::numeric_limits<size_t>::max());
+ limit_valid = true;
+ } else {
+ NOTREACHED();
+ return 0;
+ }
}
- return limit;
+ return static_cast<size_t>(limit);
}
} // namespace base
« no previous file with comments | « base/sys_info_freebsd.cc ('k') | base/sys_info_openbsd.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698