Loading base/include/base/parseint.h +4 −2 Original line number Diff line number Diff line Loading @@ -31,9 +31,10 @@ namespace base { template <typename T> bool ParseUint(const char* s, T* out, T max = std::numeric_limits<T>::max()) { int base = (s[0] == '0' && s[1] == 'x') ? 16 : 10; errno = 0; char* end; unsigned long long int result = strtoull(s, &end, 10); unsigned long long int result = strtoull(s, &end, base); if (errno != 0 || s == end || *end != '\0') { return false; } Loading @@ -52,9 +53,10 @@ template <typename T> bool ParseInt(const char* s, T* out, T min = std::numeric_limits<T>::min(), T max = std::numeric_limits<T>::max()) { int base = (s[0] == '0' && s[1] == 'x') ? 16 : 10; errno = 0; char* end; long long int result = strtoll(s, &end, 10); long long int result = strtoll(s, &end, base); if (errno != 0 || s == end || *end != '\0') { return false; } Loading base/parseint_test.cpp +10 −0 Original line number Diff line number Diff line Loading @@ -66,3 +66,13 @@ TEST(parseint, no_implicit_octal) { ASSERT_TRUE(android::base::ParseUint("0123", &u)); ASSERT_EQ(123u, u); } TEST(parseint, explicit_hex) { int i; ASSERT_TRUE(android::base::ParseInt("0x123", &i)); ASSERT_EQ(0x123, i); unsigned int u; ASSERT_TRUE(android::base::ParseUint("0x123", &u)); ASSERT_EQ(0x123u, u); } fastboot/fastboot.cpp +2 −0 Original line number Diff line number Diff line Loading @@ -571,11 +571,13 @@ static struct sparse_file **load_sparse_files(int fd, int max_size) static int64_t get_target_sparse_limit(usb_handle* usb) { std::string max_download_size; if (!fb_getvar(usb, "max-download-size", &max_download_size)) { fprintf(stderr, "target didn't report max-download-size\n"); return 0; } uint64_t limit; if (!android::base::ParseUint(max_download_size.c_str(), &limit)) { fprintf(stderr, "couldn't parse max-download-size '%s'\n", max_download_size.c_str()); return 0; } if (limit > 0) { Loading Loading
base/include/base/parseint.h +4 −2 Original line number Diff line number Diff line Loading @@ -31,9 +31,10 @@ namespace base { template <typename T> bool ParseUint(const char* s, T* out, T max = std::numeric_limits<T>::max()) { int base = (s[0] == '0' && s[1] == 'x') ? 16 : 10; errno = 0; char* end; unsigned long long int result = strtoull(s, &end, 10); unsigned long long int result = strtoull(s, &end, base); if (errno != 0 || s == end || *end != '\0') { return false; } Loading @@ -52,9 +53,10 @@ template <typename T> bool ParseInt(const char* s, T* out, T min = std::numeric_limits<T>::min(), T max = std::numeric_limits<T>::max()) { int base = (s[0] == '0' && s[1] == 'x') ? 16 : 10; errno = 0; char* end; long long int result = strtoll(s, &end, 10); long long int result = strtoll(s, &end, base); if (errno != 0 || s == end || *end != '\0') { return false; } Loading
base/parseint_test.cpp +10 −0 Original line number Diff line number Diff line Loading @@ -66,3 +66,13 @@ TEST(parseint, no_implicit_octal) { ASSERT_TRUE(android::base::ParseUint("0123", &u)); ASSERT_EQ(123u, u); } TEST(parseint, explicit_hex) { int i; ASSERT_TRUE(android::base::ParseInt("0x123", &i)); ASSERT_EQ(0x123, i); unsigned int u; ASSERT_TRUE(android::base::ParseUint("0x123", &u)); ASSERT_EQ(0x123u, u); }
fastboot/fastboot.cpp +2 −0 Original line number Diff line number Diff line Loading @@ -571,11 +571,13 @@ static struct sparse_file **load_sparse_files(int fd, int max_size) static int64_t get_target_sparse_limit(usb_handle* usb) { std::string max_download_size; if (!fb_getvar(usb, "max-download-size", &max_download_size)) { fprintf(stderr, "target didn't report max-download-size\n"); return 0; } uint64_t limit; if (!android::base::ParseUint(max_download_size.c_str(), &limit)) { fprintf(stderr, "couldn't parse max-download-size '%s'\n", max_download_size.c_str()); return 0; } if (limit > 0) { Loading