Reviewers: Christian Plesner Hansen,

Description:
* Remember to check for end of string even where we
   know the character class must match.
Thanks to Mads and Christian for finding this bug

Please review this at http://codereview.chromium.org/18750

SVN Base: http://v8.googlecode.com/svn/branches/bleeding_edge/

Affected files:
   M     src/jsregexp.cc
   M     src/regexp-macro-assembler-ia32.h
   M     src/regexp-macro-assembler.h


Index: src/regexp-macro-assembler-ia32.h
===================================================================
--- src/regexp-macro-assembler-ia32.h   (revision 1149)
+++ src/regexp-macro-assembler-ia32.h   (working copy)
@@ -71,6 +71,9 @@
                                                uc16 minus,
                                                uc16 mask,
                                                Label* on_not_equal);
+  // Checks whether the given offset from the current position is before
+  // the end of the string.
+  virtual void CheckPosition(int cp_offset, Label* on_outside_input);
    virtual bool CheckSpecialCharacterClass(uc16 type,
                                            int cp_offset,
                                            bool check_offset,
@@ -171,10 +174,6 @@
    // This function must not trigger a garbage collection.
    static Address GrowStack(Address stack_top);

-  // Checks whether the given offset from the current position is before
-  // the end of the string.
-  void CheckPosition(int cp_offset, Label* on_outside_input);
-
    // The ebp-relative location of a regexp register.
    Operand register_location(int register_index);

Index: src/regexp-macro-assembler.h
===================================================================
--- src/regexp-macro-assembler.h        (revision 1149)
+++ src/regexp-macro-assembler.h        (working copy)
@@ -111,6 +111,12 @@
    virtual void CheckNotRegistersEqual(int reg1,
                                        int reg2,
                                        Label* on_not_equal) = 0;
+
+  // Checks whether the given offset from the current position is before
+  // the end of the string.  May overwrite the current character.
+  virtual void CheckPosition(int cp_offset, Label* on_outside_input) {
+    LoadCurrentCharacter(cp_offset, on_outside_input, true);
+  }
    // Check whether a standard/default character class matches the current
    // character. Returns false if the type of special character class does
    // not have custom support.
Index: src/jsregexp.cc
===================================================================
--- src/jsregexp.cc     (revision 1149)
+++ src/jsregexp.cc     (working copy)
@@ -1835,6 +1835,9 @@
        // ASCII optimizations for us.
        macro_assembler->GoTo(on_failure);
      }
+    if (check_offset) {
+      macro_assembler->CheckPosition(cp_offset, on_failure);
+    }
      return;
    }

@@ -1842,10 +1845,8 @@
        !cc->is_negated() &&
        ranges->at(0).IsEverything(max_char)) {
      // This is a common case hit by non-anchored expressions.
-    // TODO(erikcorry): We should have a macro assembler instruction that  
just
-    // checks for end of string without loading the character.
      if (check_offset) {
-      macro_assembler->LoadCurrentCharacter(cp_offset, on_failure);
+      macro_assembler->CheckPosition(cp_offset, on_failure);
      }
      return;
    }
@@ -2477,7 +2478,7 @@
    switch (type_) {
      case AT_END: {
        Label ok;
-      assembler->LoadCurrentCharacter(trace->cp_offset(), &ok);
+      assembler->CheckPosition(trace->cp_offset(), &ok);
        assembler->GoTo(trace->backtrack());
        assembler->Bind(&ok);
        break;



--~--~---------~--~----~------------~-------~--~----~
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
-~----------~----~----~----~------~----~------~--~---

Reply via email to