The procedure System.Regexp.Compile.Check_Well_Formed_Pattern is
intended to verify the syntactic correctness of a regular expression
pattern. It was failing to detect the (incorrect) case of a pattern that
ends in a "|".  Subsequent code depends on the pattern being correct, so
failing to detect this error led to other problems (discussed in the
ticket). Add the missing check.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

        * libgnat/s-regexp.adb (Compile.Check_Well_Formed_Patern): When
        a "|" operator is encountered in a pattern, check that it is not
        the last character of the pattern.
diff --git a/gcc/ada/libgnat/s-regexp.adb b/gcc/ada/libgnat/s-regexp.adb
--- a/gcc/ada/libgnat/s-regexp.adb
+++ b/gcc/ada/libgnat/s-regexp.adb
@@ -210,7 +210,7 @@ package body System.Regexp is
          --  or the last occurrence of an opening curly brace, if Glob=True.
 
          procedure Raise_Exception_If_No_More_Chars (K : Integer := 0);
-         --  If no more characters are raised, call Raise_Exception
+         --  If S(J + 1 .. S'Last)'Length < K then call Raise_Exception
 
          --------------------------------------
          -- Raise_Exception_If_No_More_Chars --
@@ -431,6 +431,9 @@ package body System.Regexp is
                            & "applied to a term in regular expression", J);
                      end if;
 
+                     --  A second term must follow
+                     Raise_Exception_If_No_More_Chars (K => 1);
+
                      Past_Elmt := False;
                      Past_Term := False;
                   end if;


Reply via email to