summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/lib/Support/StringRef.cpp3
-rw-r--r--llvm/unittests/ADT/StringRefTest.cpp3
2 files changed, 5 insertions, 1 deletions
diff --git a/llvm/lib/Support/StringRef.cpp b/llvm/lib/Support/StringRef.cpp
index 7503fac240a..51e0394d8bd 100644
--- a/llvm/lib/Support/StringRef.cpp
+++ b/llvm/lib/Support/StringRef.cpp
@@ -351,6 +351,9 @@ size_t StringRef::count(StringRef Str) const {
}
static unsigned GetAutoSenseRadix(StringRef &Str) {
+ if (Str.empty())
+ return 10;
+
if (Str.startswith("0x") || Str.startswith("0X")) {
Str = Str.substr(2);
return 16;
diff --git a/llvm/unittests/ADT/StringRefTest.cpp b/llvm/unittests/ADT/StringRefTest.cpp
index 4249f231481..40ab4e038b8 100644
--- a/llvm/unittests/ADT/StringRefTest.cpp
+++ b/llvm/unittests/ADT/StringRefTest.cpp
@@ -571,7 +571,8 @@ TEST(StringRefTest, getAsInteger) {
static const char* BadStrings[] = {
- "18446744073709551617" // value just over max
+ "" // empty string
+ , "18446744073709551617" // value just over max
, "123456789012345678901" // value way too large
, "4t23v" // illegal decimal characters
, "0x123W56" // illegal hex characters
OpenPOWER on IntegriCloud