[PATCH 4/5] buffers: Rename buffer_if.len to buffer_if.alloclen.

Ian Jackson ijackson at chiark.greenend.org.uk
Sat Sep 20 00:43:19 BST 2014


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 at chiark.greenend.org.uk>
---
 secnet.h |    2 +-
 util.c   |   12 ++++++------
 util.h   |    2 +-
 3 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/secnet.h b/secnet.h
index 647c940..194341c 100644
--- 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 de182a4..094870f 100644
--- 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 c2f10f8..29b68e7 100644
--- 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);
-- 
1.7.10.4




More information about the sgo-software-discuss mailing list