summaryrefslogtreecommitdiffstats
path: root/base/include/android-base/parseint.h
diff options
context:
space:
mode:
authorSteven Moreland <smoreland@google.com>2018-07-20 11:02:47 -0700
committerSteven Moreland <smoreland@google.com>2018-07-20 11:02:47 -0700
commita96e43d3d6736ebe4985ac3a818135768a9672f8 (patch)
tree16f21aea3a73c4cdb0be0ae8331cec5fc5e3a231 /base/include/android-base/parseint.h
parent74be24d696f2d67293de6b9bb6e715c1728abed7 (diff)
downloadsystem_core-a96e43d3d6736ebe4985ac3a818135768a9672f8.tar.gz
system_core-a96e43d3d6736ebe4985ac3a818135768a9672f8.tar.bz2
system_core-a96e43d3d6736ebe4985ac3a818135768a9672f8.zip
ParseInt/ParseUint: allow validation only.
Removes segfault if T* out != nullptr and just returns validation result. Bug: 110758329 Test: libbase_test Change-Id: I0f304533a7076bba977fbd1a715b9cc0d9e58e75
Diffstat (limited to 'base/include/android-base/parseint.h')
-rw-r--r--base/include/android-base/parseint.h8
1 files changed, 6 insertions, 2 deletions
diff --git a/base/include/android-base/parseint.h b/base/include/android-base/parseint.h
index fc68d56b4..bb54c99b8 100644
--- a/base/include/android-base/parseint.h
+++ b/base/include/android-base/parseint.h
@@ -47,7 +47,9 @@ bool ParseUint(const char* s, T* out, T max = std::numeric_limits<T>::max(),
if (max < result) {
return false;
}
- *out = static_cast<T>(result);
+ if (out != nullptr) {
+ *out = static_cast<T>(result);
+ }
return true;
}
@@ -87,7 +89,9 @@ bool ParseInt(const char* s, T* out,
if (result < min || max < result) {
return false;
}
- *out = static_cast<T>(result);
+ if (out != nullptr) {
+ *out = static_cast<T>(result);
+ }
return true;
}