Add EOS checking to 'parseLeadingNumber' function.
authorYablonskyy@axilera.com <Yablonskyy@axilera.com>
Fri, 12 Jun 2015 20:13:15 +0000 (13:13 -0700)
committerSara Golemon <sgolemon@fb.com>
Fri, 12 Jun 2015 20:18:17 +0000 (13:18 -0700)
Summary: parseLeadingNumber does not contain EOS validation and raise an exception when '/sys/devices/system/cpu/cpu0/index0/shared_cpu_list' contains only one number like '0'.
Closes #207

Reviewed By: @yfeldblum

Differential Revision: D2148015

Pulled By: @sgolemon

folly/detail/CacheLocality.cpp

index 8f03a9f8e861417f3868a3d8627e4fab85e1e93a..26cb12651991ccebf549d4a121bae2899b927f29 100644 (file)
@@ -84,7 +84,7 @@ static size_t parseLeadingNumber(const std::string& line) {
   auto raw = line.c_str();
   char *end;
   unsigned long val = strtoul(raw, &end, 10);
-  if (end == raw || (*end != ',' && *end != '-' && *end != '\n')) {
+  if (end == raw || (*end != ',' && *end != '-' && *end != '\n' && *end != 0)) {
     throw std::runtime_error(to<std::string>(
         "error parsing list '", line, "'").c_str());
   }