void
buf_size_error(const size_t size)
{
- msg(M_FATAL, "fatal buffer size error, size=%lu", (unsigned long)size);
+ msg(M_FATAL, "fatal buffer size error, size=%zu", size);
}
struct buffer
return ret;
}
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wsign-compare"
-#endif
-
/*
* write a string to the end of a buffer that was
* truncated by buf_printf
if (buf_forward_capacity(buf) <= 1)
{
size_t len = strlen(str) + 1;
- if (len < buf_forward_capacity_total(buf))
+ if (buf_size_valid(len) && (int)len < buf_forward_capacity_total(buf))
{
memcpy(buf->data + buf->capacity - len, str, len);
}
buf_string_match_head_str(const struct buffer *src, const char *match)
{
const size_t size = strlen(match);
- if (size > src->len)
+ if (!buf_size_valid(size) || (int)size > src->len)
{
return false;
}
bool
buffer_list_defined(const struct buffer_list *ol)
{
- return ol && ol->head != NULL;
+ return ol && ol->head != NULL && ol->size > 0;
}
void
struct buffer_entry *e = buffer_list_push_data(ol, str, len + 1);
if (e)
{
- e->buf.len = (int)len; /* Don't count trailing '\0' as part of length */
+ e->buf.len--; /* Don't count trailing '\0' as part of length */
}
}
}
}
e->buf = alloc_buf(size);
memcpy(e->buf.data, data, size);
+ /* Note: size implicitly checked by alloc_buf */
e->buf.len = (int)size;
ol->tail = e;
}
const size_t sep_len = strlen(sep);
struct buffer_entry *more = bl->head;
size_t size = 0;
- int count = 0;
+ size_t count = 0;
for (; more; ++count)
{
size_t extra_len = BLENZ(&more->buf) + sep_len;
}
}
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
void
buffer_list_aggregate(struct buffer_list *bl, const size_t max)
{
void
buffer_list_pop(struct buffer_list *ol)
{
- if (ol && ol->head)
+ if (buffer_list_defined(ol))
{
struct buffer_entry *e = ol->head->next;
free_buf(&ol->head->buf);