Use apt-get instead of dpkg to install Debian package, which is more
[privoxy.git] / src / pcrs.c
index d61c61d..bb420a8 100644 (file)
@@ -1,4 +1,4 @@
-const char pcrs_rcs[] = "$Id: pcrs.c,v 2.0 2002/06/04 14:34:21 jongfoster Exp $";
+const char pcrs_rcs[] = "$Id: pcrs.c,v 2.4 2003/01/21 02:49:27 david__schmidt Exp $";
 
 /*********************************************************************
  *
@@ -33,6 +33,25 @@ const char pcrs_rcs[] = "$Id: pcrs.c,v 2.0 2002/06/04 14:34:21 jongfoster Exp $"
  *
  * Revisions   :
  *    $Log: pcrs.c,v $
+ *    Revision 2.4  2003/01/21 02:49:27  david__schmidt
+ *    Developer TODO 612294: src: C++ keyword as variable name
+ *    I changed all ocurrences of 'new' to 'new_something' wherever I found
+ *    one.  I also brought up all the source files in MSDEV to see if I could
+ *    spot any highlighted keywords that really were variables.  Non-scientific,
+ *    but at least I tried. :-)
+ *
+ *    Revision 2.3  2002/10/08 16:25:30  oes
+ *    Bugfix: Need to check validity of backreferences explicitly, because when max_matches are reached and matches is expanded, realloc() does not zero the memory. Fixes Bug # 606227
+ *
+ *    Revision 2.2  2002/09/04 15:52:02  oes
+ *    Synced with the stable branch:
+ *        Revision 1.19.2.1  2002/08/10 11:23:40  oes
+ *        Include prce.h via project.h, where the appropriate
+ *        source will have been selected
+ *
+ *    Revision 2.1  2002/08/26 11:18:24  sarantis
+ *    Fix typo.
+ *
  *    Revision 2.0  2002/06/04 14:34:21  jongfoster
  *    Moving source files to src/
  *
@@ -132,7 +151,12 @@ const char pcrs_rcs[] = "$Id: pcrs.c,v 2.0 2002/06/04 14:34:21 jongfoster Exp $"
  *********************************************************************/
 \f
 
-#include <pcre.h>
+/*
+ * Include project.h just so that the right pcre.h gets
+ * included from there
+ */
+#include "project.h"
+
 #include <string.h>
 #include <ctype.h>
 
@@ -726,18 +750,18 @@ pcrs_job *pcrs_compile(const char *pattern, const char *substitute, const char *
 int pcrs_execute_list(pcrs_job *joblist, char *subject, size_t subject_length, char **result, size_t *result_length)
 {
    pcrs_job *job;
-   char *old, *new;
+   char *old_item, *new_item;
    int hits, total_hits;
  
-   old = subject;
+   old_item = subject;
    *result_length = subject_length;
    hits = total_hits = 0;
 
    for (job = joblist; job != NULL; job = job->next)
    {
-      hits = pcrs_execute(job, old, *result_length, &new, result_length);
+      hits = pcrs_execute(job, old_item, *result_length, &new_item, result_length);
 
-      if (old != subject) free(old);
+      if (old_item != subject) free(old_item);
 
       if (hits < 0)
       {
@@ -746,11 +770,11 @@ int pcrs_execute_list(pcrs_job *joblist, char *subject, size_t subject_length, c
       else
       {
          total_hits += hits;
-         old = new;
+         old_item = new_item;
       }
    }
 
-   *result = new;
+   *result = new_item;
    return(total_hits);
 
 }
@@ -913,7 +937,9 @@ int pcrs_execute(pcrs_job *job, char *subject, size_t subject_length, char **res
          if (k != job->substitute->backrefs
              /* ..in legal range.. */
              && job->substitute->backref[k] < PCRS_MAX_SUBMATCHES + 2
-             /* ..and referencing a nonempty match.. */
+              /* ..and referencing a real submatch.. */
+             && job->substitute->backref[k] < matches[i].submatches
+             /* ..that is nonempty.. */
              && matches[i].submatch_length[job->substitute->backref[k]] > 0)
          {
             /* ..copy the submatch that is ref'd. */