summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDongHun Kwak <dh0128.kwak@samsung.com>2019-09-25 15:36:25 +0900
committerDongHun Kwak <dh0128.kwak@samsung.com>2019-09-25 15:36:25 +0900
commit35612b8b1de67ece87a87c1a16a498a20fe42347 (patch)
tree1b61dacad3754cefc00a7ee4ea5dc42adc50eba3
parent25519175010718a309b1616cfae68d75cdb1f046 (diff)
downloadre2-35612b8b1de67ece87a87c1a16a498a20fe42347.tar.gz
re2-35612b8b1de67ece87a87c1a16a498a20fe42347.tar.bz2
re2-35612b8b1de67ece87a87c1a16a498a20fe42347.zip
Imported Upstream version 20190601upstream/20190601
-rw-r--r--.travis.yml9
-rw-r--r--CMakeLists.txt4
-rw-r--r--re2/fuzzing/re2_fuzzer.cc38
-rw-r--r--re2/re2.h15
-rw-r--r--re2/testing/parse_test.cc4
-rw-r--r--re2/testing/re2_test.cc15
-rw-r--r--re2/tostring.cc4
7 files changed, 50 insertions, 39 deletions
diff --git a/.travis.yml b/.travis.yml
index 0ddc4a9..f89c96d 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -61,6 +61,15 @@ matrix:
- g++-8
env:
- MATRIX_EVAL="CC=gcc-8 CXX=g++-8"
+ - os: linux
+ addons:
+ apt:
+ sources:
+ - ubuntu-toolchain-r-test
+ packages:
+ - g++-9
+ env:
+ - MATRIX_EVAL="CC=gcc-9 CXX=g++-9"
- os: linux
addons:
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f87c4ff..639c715 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -84,6 +84,7 @@ set(RE2_SOURCES
)
add_library(re2 ${RE2_SOURCES})
+add_library(re2::re2 ALIAS re2)
if(RE2_BUILD_TESTING)
set(TESTING_SOURCES
@@ -147,4 +148,5 @@ set(RE2_HEADERS
)
install(FILES ${RE2_HEADERS} DESTINATION include/re2)
-install(TARGETS re2 ARCHIVE DESTINATION lib LIBRARY DESTINATION lib RUNTIME DESTINATION bin)
+install(TARGETS re2 EXPORT re2Config ARCHIVE DESTINATION lib LIBRARY DESTINATION lib RUNTIME DESTINATION bin INCLUDES DESTINATION include)
+install(EXPORT re2Config DESTINATION lib/cmake/re2 NAMESPACE re2::)
diff --git a/re2/fuzzing/re2_fuzzer.cc b/re2/fuzzing/re2_fuzzer.cc
index 2faebe0..061c418 100644
--- a/re2/fuzzing/re2_fuzzer.cc
+++ b/re2/fuzzing/re2_fuzzer.cc
@@ -22,25 +22,6 @@ void Test(StringPiece pattern, const RE2::Options& options, StringPiece text) {
if (!re.ok())
return;
- // Don't waste time fuzzing high-size programs.
- // They can cause bug reports due to fuzzer timeouts.
- int size = re.ProgramSize();
- if (size > 9999)
- return;
- int rsize = re.ReverseProgramSize();
- if (rsize > 9999)
- return;
-
- // Don't waste time fuzzing high-fanout programs.
- // They can cause bug reports due to fuzzer timeouts.
- std::map<int, int> histogram;
- int fanout = re.ProgramFanout(&histogram);
- if (fanout > 9)
- return;
- int rfanout = re.ReverseProgramFanout(&histogram);
- if (rfanout > 9)
- return;
-
// Don't waste time fuzzing programs with large substrings.
// They can cause bug reports due to fuzzer timeouts when they
// are repetitions (e.g. hundreds of NUL bytes) and matching is
@@ -63,6 +44,25 @@ void Test(StringPiece pattern, const RE2::Options& options, StringPiece text) {
}
}
+ // Don't waste time fuzzing high-size programs.
+ // They can cause bug reports due to fuzzer timeouts.
+ int size = re.ProgramSize();
+ if (size > 9999)
+ return;
+ int rsize = re.ReverseProgramSize();
+ if (rsize > 9999)
+ return;
+
+ // Don't waste time fuzzing high-fanout programs.
+ // They can cause bug reports due to fuzzer timeouts.
+ std::map<int, int> histogram;
+ int fanout = re.ProgramFanout(&histogram);
+ if (fanout > 9)
+ return;
+ int rfanout = re.ReverseProgramFanout(&histogram);
+ if (rfanout > 9)
+ return;
+
if (re.NumberOfCapturingGroups() == 0) {
// Avoid early return due to too many arguments.
StringPiece sp = text;
diff --git a/re2/re2.h b/re2/re2.h
index 299501e..c39589d 100644
--- a/re2/re2.h
+++ b/re2/re2.h
@@ -305,13 +305,13 @@ class RE2 {
// useful to invoke them directly, but the syntax is awkward, so the 'N'-less
// versions should be preferred.
static bool FullMatchN(const StringPiece& text, const RE2& re,
- const Arg* const args[], int argc);
+ const Arg* const args[], int n);
static bool PartialMatchN(const StringPiece& text, const RE2& re,
- const Arg* const args[], int argc);
+ const Arg* const args[], int n);
static bool ConsumeN(StringPiece* input, const RE2& re,
- const Arg* const args[], int argc);
+ const Arg* const args[], int n);
static bool FindAndConsumeN(StringPiece* input, const RE2& re,
- const Arg* const args[], int argc);
+ const Arg* const args[], int n);
#ifndef SWIG
private:
@@ -323,8 +323,8 @@ class RE2 {
template <typename F, typename SP, typename... A>
static inline bool Apply(F f, SP sp, const RE2& re, const A&... a) {
const Arg* const args[] = {&a...};
- const int argc = sizeof...(a);
- return f(sp, re, args, argc);
+ const int n = sizeof...(a);
+ return f(sp, re, args, n);
}
public:
@@ -377,7 +377,8 @@ class RE2 {
// Like FullMatch() and PartialMatch(), except that "re" has to match
// a prefix of the text, and "input" is advanced past the matched
- // text. Note: "input" is modified iff this routine returns true.
+ // text. Note: "input" is modified iff this routine returns true
+ // and "re" matched a non-empty substring of "text".
template <typename... A>
static bool Consume(StringPiece* input, const RE2& re, A&&... a) {
return Apply(ConsumeN, input, re, Arg(std::forward<A>(a))...);
diff --git a/re2/testing/parse_test.cc b/re2/testing/parse_test.cc
index 5cb3952..a3289b9 100644
--- a/re2/testing/parse_test.cc
+++ b/re2/testing/parse_test.cc
@@ -217,6 +217,10 @@ static Test tests[] = {
Regexp::PerlClasses | Regexp::NeverNL },
{ "\\S", "cc{0-0x8 0xb 0xe-0x1f 0x21-0x10ffff}",
Regexp::PerlClasses | Regexp::NeverNL | Regexp::FoldCase },
+
+ // Bug in Regexp::ToString() that emitted [^], which
+ // would (obviously) fail to parse when fed back in.
+ { "[\\s\\S]", "cc{0-0x10ffff}" },
};
bool RegexpEqualTestingOnly(Regexp* a, Regexp* b) {
diff --git a/re2/testing/re2_test.cc b/re2/testing/re2_test.cc
index 2d692a6..52c9294 100644
--- a/re2/testing/re2_test.cc
+++ b/re2/testing/re2_test.cc
@@ -1461,9 +1461,8 @@ TEST(RE2, NullVsEmptyStringSubmatches) {
EXPECT_TRUE(re.Match(null, 0, null.size(), RE2::UNANCHORED,
matches, arraysize(matches)));
for (int i = 0; i < arraysize(matches); i++) {
- EXPECT_TRUE(matches[i] == StringPiece());
EXPECT_TRUE(matches[i].data() == NULL); // always null
- EXPECT_TRUE(matches[i] == "");
+ EXPECT_TRUE(matches[i].empty());
}
for (int i = 0; i < arraysize(matches); i++)
@@ -1472,18 +1471,14 @@ TEST(RE2, NullVsEmptyStringSubmatches) {
StringPiece empty("");
EXPECT_TRUE(re.Match(empty, 0, empty.size(), RE2::UNANCHORED,
matches, arraysize(matches)));
- EXPECT_TRUE(matches[0] == StringPiece());
EXPECT_TRUE(matches[0].data() != NULL); // empty, not null
- EXPECT_TRUE(matches[0] == "");
- EXPECT_TRUE(matches[1] == StringPiece());
+ EXPECT_TRUE(matches[0].empty());
EXPECT_TRUE(matches[1].data() != NULL); // empty, not null
- EXPECT_TRUE(matches[1] == "");
- EXPECT_TRUE(matches[2] == StringPiece());
+ EXPECT_TRUE(matches[1].empty());
EXPECT_TRUE(matches[2].data() == NULL);
- EXPECT_TRUE(matches[2] == "");
- EXPECT_TRUE(matches[3] == StringPiece());
+ EXPECT_TRUE(matches[2].empty());
EXPECT_TRUE(matches[3].data() == NULL);
- EXPECT_TRUE(matches[3] == "");
+ EXPECT_TRUE(matches[3].empty());
}
// Issue 1816809
diff --git a/re2/tostring.cc b/re2/tostring.cc
index 2d06551..a608c87 100644
--- a/re2/tostring.cc
+++ b/re2/tostring.cc
@@ -269,9 +269,9 @@ int ToStringWalker::PostVisit(Regexp* re, int parent_arg, int pre_arg,
}
t_->append("[");
// Heuristic: show class as negated if it contains the
- // non-character 0xFFFE.
+ // non-character 0xFFFE and yet somehow isn't full.
CharClass* cc = re->cc();
- if (cc->Contains(0xFFFE)) {
+ if (cc->Contains(0xFFFE) && !cc->full()) {
cc = cc->Negate();
t_->append("^");
}