summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorTom Cherry <tomcherry@google.com>2018-08-22 15:26:20 -0700
committerTom Cherry <tomcherry@google.com>2018-10-05 14:30:39 -0700
commitbc64e50bd75479b16cdbcd16e0ce151ead89dddd (patch)
tree90b1fa4af4c5d5a483fb6a125138d9944641b80b /base
parente0bc5a9aa2c670f1003ac1c4331b77c594adf3a4 (diff)
downloadsystem_core-bc64e50bd75479b16cdbcd16e0ce151ead89dddd.tar.gz
system_core-bc64e50bd75479b16cdbcd16e0ce151ead89dddd.tar.bz2
system_core-bc64e50bd75479b16cdbcd16e0ce151ead89dddd.zip
Assert that ParseInt/ParseUint are only used with signed/unsigned numbers respectively
Test: build fails when the signedness is mismatched Test: build succeeds otherwise Change-Id: Idd6b146cc167d4607eafc81dbad6c2a79b167094
Diffstat (limited to 'base')
-rw-r--r--base/include/android-base/parseint.h3
1 files changed, 3 insertions, 0 deletions
diff --git a/base/include/android-base/parseint.h b/base/include/android-base/parseint.h
index 9444fddf0..be8b97b78 100644
--- a/base/include/android-base/parseint.h
+++ b/base/include/android-base/parseint.h
@@ -22,6 +22,7 @@
#include <limits>
#include <string>
+#include <type_traits>
namespace android {
namespace base {
@@ -33,6 +34,7 @@ namespace base {
template <typename T>
bool ParseUint(const char* s, T* out, T max = std::numeric_limits<T>::max(),
bool allow_suffixes = false) {
+ static_assert(std::is_unsigned<T>::value, "ParseUint can only be used with unsigned types");
while (isspace(*s)) {
s++;
}
@@ -96,6 +98,7 @@ template <typename T>
bool ParseInt(const char* s, T* out,
T min = std::numeric_limits<T>::min(),
T max = std::numeric_limits<T>::max()) {
+ static_assert(std::is_signed<T>::value, "ParseInt can only be used with signed types");
while (isspace(*s)) {
s++;
}