XEmacs 21.4.10 "Military Intelligence".
[chise/xemacs-chise.git.1] / src / regex.c
index 3ef8353..d70f7d6 100644 (file)
@@ -3649,7 +3649,7 @@ re_compile_fastmap (struct re_pattern_buffer *bufp)
          goto done;
 
 #ifdef emacs
-#if 0   /* Removed during syntax-table properties patch -- 2000/12/07 mct */
+#if 0  /* Removed during syntax-table properties patch -- 2000/12/07 mct */
         case syntaxspec:
          k = *p++;
 #endif
@@ -3692,7 +3692,7 @@ re_compile_fastmap (struct re_pattern_buffer *bufp)
          break;
 
 
-#if 0   /* Removed during syntax-table properties patch -- 2000/12/07 mct */
+#if 0  /* Removed during syntax-table properties patch -- 2000/12/07 mct */
        case notsyntaxspec:
          k = *p++;
 #endif
@@ -3752,7 +3752,7 @@ re_compile_fastmap (struct re_pattern_buffer *bufp)
        case at_dot:
        case after_dot:
           continue;
-#endif /* not emacs */
+#endif /* emacs */
 
 
         case no_op:
@@ -4716,16 +4716,24 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1,
                        = (regoff_t) POINTER_TO_OFFSET (regend[mcnt]);
                     }
                }
-
-              /* If the regs structure we return has more elements than
-                 were in the pattern, set the extra elements to -1.  If
-                 we (re)allocated the registers, this is the case,
-                 because we always allocate enough to have at least one
-                 -1 at the end.  */
-              for (mcnt = num_regs; mcnt < regs->num_regs; mcnt++)
-                regs->start[mcnt] = regs->end[mcnt] = -1;
            } /* regs && !bufp->no_sub */
 
+         /* If we have regs and the regs structure has more elements than
+             were in the pattern, set the extra elements to -1.  If we
+            (re)allocated the registers, this is the case, because we
+            always allocate enough to have at least one -1 at the end.
+
+            We do this even when no_sub is set because some applications
+             (XEmacs) reuse register structures which may contain stale
+            information, and permit attempts to access those registers.
+
+            It would be possible to require the caller to do this, but we'd
+            have to change the API for this function to reflect that, and
+            audit all callers. */
+         if (regs && regs->num_regs > 0)
+           for (mcnt = num_regs; mcnt < regs->num_regs; mcnt++)
+             regs->start[mcnt] = regs->end[mcnt] = -1;
+
           DEBUG_PRINT4 ("%u failure points pushed, %u popped (%u remain).\n",
                         nfailure_points_pushed, nfailure_points_popped,
                         nfailure_points_pushed - nfailure_points_popped);
@@ -5711,7 +5719,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp, re_char *string1,
 #endif
 
            emch = charptr_emchar ((const Bufbyte *) d);
-           matches = (SYNTAX_FROM_CACHE (regex_emacs_buffer->mirror_syntax_table,
+           matches = (SYNTAX_FROM_CACHE (XCHAR_TABLE (regex_emacs_buffer->mirror_syntax_table),
                        emch) == (enum syntaxcode) mcnt);
            INC_CHARPTR (d);
            if (matches != should_succeed)