chiark / gitweb /
buffers: Rename buffer_if.len to buffer_if.alloclen.
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 19 Sep 2014 23:05:19 +0000 (00:05 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 19 Sep 2014 23:07:22 +0000 (00:07 +0100)
This field contains the total amount of space allocated, starting at
base, which may be less than the amount of space available after
start.

Rename it to help avoid confusion.  This also enabled me to review
every site where this variable was used to verify that the length
checks are all now correct.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
secnet.h
util.c
util.h

index 647c94082b7b2d0afded05e40fa9cb7f6e79c219..194341c434670902e772b58a956fbfbe6fd4b050 100644 (file)
--- a/secnet.h
+++ b/secnet.h
@@ -499,7 +499,7 @@ struct buffer_if {
     uint8_t *base;
     uint8_t *start;
     int32_t size; /* Size of buffer contents */
-    int32_t len; /* Total length allocated at base */
+    int32_t alloclen; /* Total length allocated at base */
 };
 
 /***** LOG functions *****/
diff --git a/util.c b/util.c
index de182a431445abdf34abc8b3f7dbf57f17ee919e..094870ff213cbc41c9f011aa1b316f646ee30992 100644 (file)
--- a/util.c
+++ b/util.c
@@ -247,7 +247,7 @@ void buffer_assert_used(struct buffer_if *buffer, cstring_t file,
 
 void buffer_init(struct buffer_if *buffer, int32_t max_start_pad)
 {
-    assert(max_start_pad<=buffer->len);
+    assert(max_start_pad<=buffer->alloclen);
     buffer->start=buffer->base+max_start_pad;
     buffer->size=0;
 }
@@ -300,7 +300,7 @@ void buffer_new(struct buffer_if *buf, int32_t len)
     buf->loc.file=NULL;
     buf->loc.line=0;
     buf->size=0;
-    buf->len=len;
+    buf->alloclen=len;
     buf->start=NULL;
     buf->base=safe_malloc(len,"buffer_new");
 }
@@ -312,7 +312,7 @@ void buffer_readonly_view(struct buffer_if *buf, const void *data, int32_t len)
     buf->flags=0;
     buf->loc.file=NULL;
     buf->loc.line=0;
-    buf->size=buf->len=len;
+    buf->size=buf->alloclen=len;
     buf->base=buf->start=(uint8_t*)data;
 }
 
@@ -323,10 +323,10 @@ void buffer_readonly_clone(struct buffer_if *out, const struct buffer_if *in)
 
 void buffer_copy(struct buffer_if *dst, const struct buffer_if *src)
 {
-    if (dst->len < src->len) {
-       dst->base=realloc(dst->base,src->len);
+    if (dst->alloclen < src->alloclen) {
+       dst->base=realloc(dst->base,src->alloclen);
        if (!dst->base) fatal_perror("buffer_copy");
-       dst->len = src->len;
+       dst->alloclen = src->alloclen;
     }
     dst->start = dst->base + (src->start - src->base);
     dst->size = src->size;
diff --git a/util.h b/util.h
index c2f10f83d33e0fa697f09d7a43353f77dfeec417..29b68e73d0a906c083b5c116b2a582b960b3c6a7 100644 (file)
--- a/util.h
+++ b/util.h
@@ -31,7 +31,7 @@ extern void *buf_unprepend(struct buffer_if *buf, int32_t amount);
 
 static inline int32_t buf_remaining_space(const struct buffer_if *buf)
 {
-    return (buf->base + buf->len) - buf->start;
+    return (buf->base + buf->alloclen) - buf->start;
 }
 
 extern void buffer_readonly_view(struct buffer_if *n, const void*, int32_t len);