Skip to content

Commit

Permalink
buffer: tidy comments
Browse files Browse the repository at this point in the history
Signed-off-by: He Xian <hexian000@outlook.com>
  • Loading branch information
hexian000 committed Dec 13, 2024
1 parent b43636d commit 1d0e75a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion contrib/csnippets/utils/buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ vbuf_append(struct vbuffer *restrict vbuf, const void *data, size_t n)
}
(void)memcpy(vbuf->data + vbuf->len, data, n);
vbuf->len += n;
vbuf->data[vbuf->len] = '\0'; /* the reserved byte */
/* null-byte is reserved by vbuf_alloc() */
vbuf->data[vbuf->len] = '\0';
return vbuf;
}

Expand All @@ -110,6 +111,7 @@ vbuf_vappendf(struct vbuffer *restrict vbuf, const char *format, va_list args)

va_list args0;
va_copy(args0, args);
/* null-byte is reserved by vbuf_alloc() */
int ret = vsnprintf(b, maxlen + 1, format, args0);
va_end(args0);
if (ret <= 0) {
Expand Down
2 changes: 1 addition & 1 deletion contrib/csnippets/utils/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ vbuf_alloc(struct vbuffer *restrict vbuf, const size_t cap)
return NULL;
}
const size_t len = (vbuf != NULL) ? vbuf->len : 0;
/* with a null-byte */
/* reserve 1 byte for null terminator */
struct vbuffer *restrict newbuf =
realloc(vbuf, sizeof(struct vbuffer) + cap + 1);
if (newbuf == NULL) {
Expand Down

0 comments on commit 1d0e75a

Please sign in to comment.