]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
Refine ComponentClass::class_empty
authorJustin Viiret <justin.viiret@intel.com>
Mon, 9 Nov 2015 01:59:36 +0000 (12:59 +1100)
committerMatthew Barr <matthew.barr@intel.com>
Tue, 10 Nov 2015 03:36:39 +0000 (14:36 +1100)
ComponentClass::class_empty should only be used on finalized classes to
determine whether a given class contains any elements; it should not
take the cr_ucp or cps_ucp into account, as they have been folden in by
the finalize call.

Fixes our failure to identify that the pattern /[^\D\d]/8W can never
match.

src/parser/AsciiComponentClass.cpp
src/parser/ComponentClass.cpp
src/parser/ComponentClass.h
src/parser/Utf8ComponentClass.cpp
unit/hyperscan/bad_patterns.txt

index de7a40d4c872c26d26dafff5cd0c16dc6eacbf06..44ecb5bb70205d66b30e8d5b2fb77f01b66bc512 100644 (file)
@@ -52,7 +52,8 @@ AsciiComponentClass *AsciiComponentClass::clone() const {
 }
 
 bool AsciiComponentClass::class_empty(void) const {
-    return cr.none() && cr_ucp.none();
+    assert(finalized);
+    return cr.none();
 }
 
 void AsciiComponentClass::createRange(unichar to) {
index 4570734d828dad489d5dcfb6093b627cacd589b1..43c05898f8523b77ffa5ce1406fb0fc98853e3d0 100644 (file)
@@ -441,7 +441,6 @@ void ComponentClass::addDash(void) {
 }
 
 void ComponentClass::negate() {
-    assert(class_empty());
     m_negate = true;
 }
 
index ce3b49f3605c37f3db5df9ae0ce5317ab4f37982..1cb1a7d0f44eea66c42d29cea1a4ed3d6a4027b3 100644 (file)
@@ -232,8 +232,12 @@ public:
     Component *accept(ComponentVisitor &v) override = 0;
     void accept(ConstComponentVisitor &v) const override = 0;
 
-     /** True iff we have already started adding members to the class. This is
-      * a different concept to Component::empty */
+    /** \brief True if the class contains no members (i.e. it will not match
+     * against anything). This function can only be called on a finalized
+     * class.
+     *
+     * Note: This is a different concept to Component::empty.
+     */
     virtual bool class_empty(void) const = 0;
 
     virtual void add(PredefinedClass c, bool negated) = 0;
index 72fc214697a3da894bc4f3ad2930bfc300f54a12..3a6a85a401c17d394819a2fc27b180e558211919 100644 (file)
@@ -484,7 +484,8 @@ UTF8ComponentClass *UTF8ComponentClass::clone() const {
 }
 
 bool UTF8ComponentClass::class_empty(void) const {
-    return cps.none() && cps_ucp.none();
+    assert(finalized);
+    return cps.none();
 }
 
 void UTF8ComponentClass::createRange(unichar to) {
index 837ba871fdb9cf31b56ec94bd104eb57a1dd8a06..3b13e06479418f8664867678705f38a8275a9720 100644 (file)
 132:/[a[==]]/ #Unsupported POSIX collating element at index 2.
 133:/[a[.\].]]/ #Unsupported POSIX collating element at index 2.
 134:/[a[=\]=]]/ #Unsupported POSIX collating element at index 2.
+135:/[^\D\d]/8W #Pattern can never match.