This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
regcomp.c: Properly count elements in [] for false ranges
authorKarl Williamson <public@khwilliamson.com>
Fri, 20 Jul 2012 17:35:07 +0000 (11:35 -0600)
committerKarl Williamson <public@khwilliamson.com>
Wed, 25 Jul 2012 03:13:49 +0000 (21:13 -0600)
When something that looks like a range turns out not to be, the hyphen
is matched literally, and so is a separate element in the character
class.  It needs to be accounted as such.

regcomp.c

index 8f48844..9c79400 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -11816,8 +11816,10 @@ parseit:
                               "False [] range \"%*.*s\"",
                               w, w, rangebegin);
                    }
-                    if (!SIZE_ONLY)
+                    if (!SIZE_ONLY) {
                         cp_list = add_cp_to_invlist(cp_list, '-');
+                        element_count++;
+                    }
                } else
                    range = 1;  /* yeah, it's a range! */
                continue;       /* but do it the next time */