[PATCH] D35891: [Support/GlobPattern] - Do not crash when pattern has characters with int value < 0.
George Rimar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 26 08:17:51 PDT 2017
grimar updated this revision to Diff 108284.
grimar added a comment.
- Use character literals in testcase.
https://reviews.llvm.org/D35891
Files:
lib/Support/GlobPattern.cpp
unittests/Support/GlobPatternTest.cpp
Index: unittests/Support/GlobPatternTest.cpp
===================================================================
--- unittests/Support/GlobPatternTest.cpp
+++ unittests/Support/GlobPatternTest.cpp
@@ -67,4 +67,13 @@
EXPECT_FALSE((bool)Pat1);
handleAllErrors(Pat1.takeError(), [&](ErrorInfoBase &EIB) {});
}
+
+TEST_F(GlobPatternTest, ExtSym) {
+ Expected<GlobPattern> Pat1 = GlobPattern::create("a*\xFF");
+ EXPECT_TRUE((bool)Pat1);
+ EXPECT_TRUE(Pat1->match("axxxョ"));
+ Expected<GlobPattern> Pat2 = GlobPattern::create("[\xFF-\xFF]");
+ EXPECT_TRUE((bool)Pat2);
+ EXPECT_TRUE(Pat2->match("ョ"));
+}
}
Index: lib/Support/GlobPattern.cpp
===================================================================
--- lib/Support/GlobPattern.cpp
+++ lib/Support/GlobPattern.cpp
@@ -36,24 +36,24 @@
// If it doesn't start with something like X-Y,
// consume the first character and proceed.
if (S[1] != '-') {
- BV[S[0]] = true;
+ BV[(uint8_t)S[0]] = true;
S = S.substr(1);
continue;
}
// It must be in the form of X-Y.
// Validate it and then interpret the range.
- if (S[0] > S[2])
+ if ((uint8_t)S[0] > (uint8_t)S[2])
return make_error<StringError>("invalid glob pattern: " + Original,
errc::invalid_argument);
- for (int C = S[0]; C <= S[2]; ++C)
- BV[C] = true;
+ for (int C = (uint8_t)S[0]; C <= (uint8_t)S[2]; ++C)
+ BV[(uint8_t)C] = true;
S = S.substr(3);
}
for (char C : S)
- BV[C] = true;
+ BV[(uint8_t)C] = true;
return BV;
}
@@ -89,7 +89,7 @@
}
default:
BitVector BV(256, false);
- BV[S[0]] = true;
+ BV[(uint8_t)S[0]] = true;
S = S.substr(1);
return BV;
}
@@ -159,7 +159,7 @@
}
// If Pats[0] is not '*', it must consume one character.
- if (S.empty() || !Pats[0][S[0]])
+ if (S.empty() || !Pats[0][(uint8_t)S[0]])
return false;
Pats = Pats.slice(1);
S = S.substr(1);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D35891.108284.patch
Type: text/x-patch
Size: 2003 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170726/217ef61c/attachment.bin>
More information about the llvm-commits
mailing list