OSSP CVS Repository

ossp - Check-in [1967]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 1967
Date: 2002-Mar-07 15:03:50 (local)
2002-Mar-07 14:03:50 (UTC)
User:rse
Branch:
Comment: Shit happens! Our tokenbuf_copy() function was a good idea, but cannot be used for the loop construct expansion, because an intermediate tokenbuf_append() can realloc(3) the underlying buffer, so the backuped token buffer would point to no longer valid data. We really have to re-introduce the original trick of Peter Simons where an offset is used only.
Tickets:
Inspections:
Files:
ossp-pkg/var/var.c      1.86 -> 1.87     8 inserted, 15 deleted

ossp-pkg/var/var.c 1.86 -> 1.87

--- var.c        2002/03/07 12:11:09     1.86
+++ var.c        2002/03/07 14:03:50     1.87
@@ -44,6 +44,9 @@
 #  include <regex.h>
 #endif
 #include "var.h"
+#if defined(HAVE_DMALLOC_H) && defined(WITH_DMALLOC)
+#include "dmalloc.h"
+#endif
 
 /* unique library identifier */
 const char var_id[] = "OSSP var";
@@ -309,16 +312,6 @@
 }
 
 static void 
-tokenbuf_copy(
-    tokenbuf_t *src, tokenbuf_t *dst)
-{
-    dst->begin = src->begin;
-    dst->end = src->end;
-    dst->buffer_size = src->buffer_size;
-    return;
-}
-
-static void 
 tokenbuf_move(
     tokenbuf_t *src, tokenbuf_t *dst)
 {
@@ -2244,7 +2237,7 @@
     tokenbuf_t result;
     int start, step, stop, open_stop;
     int i;
-    tokenbuf_t output_backup;
+    int output_backup;
     int rel_lookup_cnt;
     int loop_limit_length;
     var_parse_t myctx;
@@ -2267,7 +2260,7 @@
             start = 0;
             step  = 1;
             stop  = 0;
-            tokenbuf_copy(output, &output_backup);
+            output_backup = 0;
 
             /* iterate over loop construct, either as long as there is
                (still) nothing known about the limit, or there is an open
@@ -2283,7 +2276,7 @@
                  i += step) {
 
                 /* remember current output end for restoring */
-                tokenbuf_copy(output, &output_backup);
+                output_backup = (output->end - output->begin);
 
                 /* open temporary context for recursion */ 
                 ctx = var_parse_push(ctx, &myctx);
@@ -2320,7 +2313,7 @@
                     else if (rc2 > 0) {
                         loop_limit_length = rc2;
                         /* restart loop from scratch */
-                        tokenbuf_copy(&output_backup, output);
+                        output->end = (output->begin + output_backup);
                         goto re_loop;
                     }
                 }
@@ -2330,7 +2323,7 @@
                because the last iteration was just to determine the loop
                termination and its result has to be discarded */
             if (open_stop)
-                tokenbuf_copy(&output_backup, output);
+                output->end = (output->begin + output_backup);
 
             /* skip parsed loop construct */
             p += rc;

CVSTrac 2.0.1