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>
uint8_t *base;
uint8_t *start;
int32_t size; /* Size of buffer contents */
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 *****/
};
/***** LOG functions *****/
void buffer_init(struct buffer_if *buffer, int32_t max_start_pad)
{
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;
}
buffer->start=buffer->base+max_start_pad;
buffer->size=0;
}
buf->loc.file=NULL;
buf->loc.line=0;
buf->size=0;
buf->loc.file=NULL;
buf->loc.line=0;
buf->size=0;
buf->start=NULL;
buf->base=safe_malloc(len,"buffer_new");
}
buf->start=NULL;
buf->base=safe_malloc(len,"buffer_new");
}
buf->flags=0;
buf->loc.file=NULL;
buf->loc.line=0;
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;
}
buf->base=buf->start=(uint8_t*)data;
}
void buffer_copy(struct buffer_if *dst, const struct buffer_if *src)
{
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");
if (!dst->base) fatal_perror("buffer_copy");
+ dst->alloclen = src->alloclen;
}
dst->start = dst->base + (src->start - src->base);
dst->size = src->size;
}
dst->start = dst->base + (src->start - src->base);
dst->size = src->size;
static inline int32_t buf_remaining_space(const struct buffer_if *buf)
{
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);
}
extern void buffer_readonly_view(struct buffer_if *n, const void*, int32_t len);