Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Skip to content
Snippets Groups Projects
Commit 93e02985 authored by Tom Cherry's avatar Tom Cherry Committed by Gerrit Code Review
Browse files

Merge "Assert that ParseInt/ParseUint are only used with signed/unsigned numbers respectively"

parents c35c6099 bc64e50b
Branches
No related tags found
No related merge requests found
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <limits> #include <limits>
#include <string> #include <string>
#include <type_traits>
namespace android { namespace android {
namespace base { namespace base {
...@@ -33,6 +34,7 @@ namespace base { ...@@ -33,6 +34,7 @@ namespace base {
template <typename T> template <typename T>
bool ParseUint(const char* s, T* out, T max = std::numeric_limits<T>::max(), bool ParseUint(const char* s, T* out, T max = std::numeric_limits<T>::max(),
bool allow_suffixes = false) { bool allow_suffixes = false) {
static_assert(std::is_unsigned<T>::value, "ParseUint can only be used with unsigned types");
while (isspace(*s)) { while (isspace(*s)) {
s++; s++;
} }
...@@ -96,6 +98,7 @@ template <typename T> ...@@ -96,6 +98,7 @@ template <typename T>
bool ParseInt(const char* s, T* out, bool ParseInt(const char* s, T* out,
T min = std::numeric_limits<T>::min(), T min = std::numeric_limits<T>::min(),
T max = std::numeric_limits<T>::max()) { 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)) { while (isspace(*s)) {
s++; s++;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment