]> git.puffer.fish Git - mirror/frr.git/commitdiff
2005-01-28 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
authorajs <ajs>
Fri, 28 Jan 2005 20:41:07 +0000 (20:41 +0000)
committerajs <ajs>
Fri, 28 Jan 2005 20:41:07 +0000 (20:41 +0000)
* lib/buffer.h: Document behavior of buffer_getstr function.
* lib/buffer.c: (buffer_getstr) Fix bug: must handle case where
  the string extends beyond the head struct buffer_data.

lib/ChangeLog
lib/buffer.c
lib/buffer.h

index 750e310f9aec135979289d13a4ea763c32b75869..7955f0985d2f42bc8cd7752bc740eacf8da79383 100644 (file)
@@ -1,3 +1,9 @@
+2005-01-28 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
+
+       * lib/buffer.h: Document behavior of buffer_getstr function.
+       * lib/buffer.c: (buffer_getstr) Fix bug: must handle case where
+         the string extends beyond the head struct buffer_data.
+
 2005-01-28 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
 
        * lib/command.h: Document behavior of argv_concat function.
index 296fd144e7438687a4f220a5d2b5171f9b6162fe..60048bc08a6edb832c7b55565592ac4f773b1b16 100644 (file)
@@ -88,7 +88,23 @@ buffer_free (struct buffer *b)
 char *
 buffer_getstr (struct buffer *b)
 {
-  return strdup ((char *)b->head->data);
+  size_t totlen = 0;
+  struct buffer_data *data;
+  char *s;
+  char *p;
+
+  for (data = b->head; data; data = data->next)
+    totlen += data->cp - data->sp;
+  if (!(s = malloc(totlen+1)))
+    return NULL;
+  p = s;
+  for (data = b->head; data; data = data->next)
+    {
+      memcpy(p, data->data + data->sp, data->cp - data->sp);
+      p += data->cp - data->sp;
+    }
+  *p = '\0';
+  return s;
 }
 
 /* Return 1 if buffer is empty. */
index 65b8a8ca29675c545e35e5df74911d03466f9883..c3787d78afd921a13c41ddc0a88e47c0496bf47e 100644 (file)
@@ -65,7 +65,14 @@ struct buffer_data
 struct buffer *buffer_new (size_t);
 int buffer_write (struct buffer *, const void *, size_t);
 void buffer_free (struct buffer *);
+
+/* Combine all accumulated (and unflushed) data inside the buffer into a
+   single NUL-terminated string allocated using malloc (N.B. should be changed
+   to use XMALLOC(MTYPE_TMP)).  Note that this function does not alter
+   the state of the buffer, so the data is still inside waiting to be
+   flushed. */
 char *buffer_getstr (struct buffer *);
+
 int buffer_putc (struct buffer *, u_char);
 int buffer_putstr (struct buffer *, const char *);
 void buffer_reset (struct buffer *);