regcomp.c: Change loop variable name, associated changes
authorKarl Williamson <public@khwilliamson.com>
Fri, 6 Jan 2012 17:18:53 +0000 (10:18 -0700)
committerKarl Williamson <public@khwilliamson.com>
Fri, 13 Jan 2012 16:58:39 +0000 (09:58 -0700)
The variable 'value' is already used for something else.  Using it as a
loop variable corrupts the other use.  This commit changes to a
different name, and adds code to keep 'value', and 'prevvalue' in sync
with their other meanings.

regcomp.c

index 1bcfc68..1b738b6 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -10940,9 +10940,18 @@ parseit:
            || (ANYOF_FLAGS(ret) & ANYOF_NONBITMAP_NON_UTF8))
        && SvCUR(listsv) == initial_listsv_len)
     {
+       int i;
        if (! nonbitmap) {
-           for (value = 0; value < ANYOF_BITMAP_SIZE; ++value)
-               ANYOF_BITMAP(ret)[value] ^= 0xFF;
+           for (i = 0; i < 256; ++i) {
+               if (ANYOF_BITMAP_TEST(ret, i)) {
+                   ANYOF_BITMAP_CLEAR(ret, i);
+               }
+               else {
+                   ANYOF_BITMAP_SET(ret, i);
+                   prevvalue = value;
+                   value = i;
+               }
+           }
            /* The inversion means that everything above 255 is matched */
            ANYOF_FLAGS(ret) |= ANYOF_UNICODE_ALL;
        }
@@ -10951,14 +10960,19 @@ parseit:
             * individually and add it to the list to get rid of from those
             * things not in the bitmap */
            SV *remove_list = _new_invlist(2);
+
+           /* Now invert both the bitmap and the nonbitmap.  Anything in the
+            * bitmap has to also be removed from the non-bitmap */
            _invlist_invert(nonbitmap);
-           for (value = 0; value < 256; ++value) {
-               if (ANYOF_BITMAP_TEST(ret, value)) {
-                   ANYOF_BITMAP_CLEAR(ret, value);
-                   remove_list = add_cp_to_invlist(remove_list, value);
+           for (i = 0; i < 256; ++i) {
+               if (ANYOF_BITMAP_TEST(ret, i)) {
+                   ANYOF_BITMAP_CLEAR(ret, i);
+                   remove_list = add_cp_to_invlist(remove_list, i);
                }
                else {
-                   ANYOF_BITMAP_SET(ret, value);
+                   ANYOF_BITMAP_SET(ret, i);
+                   prevvalue = value;
+                   value = i;
                }
            }