mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-14 09:37:34 -05:00
New functions to shrink a strbuf.
These are better than my previous approach of just assigning to sb->len, because firstly they check by assertion that the new length is within range, and secondly they preserve the invariant that the byte stored in the buffer just after the length runs out is \0. Switched to using the new functions everywhere a grep could turn up opportunities.
This commit is contained in:
14
utils.c
14
utils.c
@ -429,6 +429,20 @@ void *strbuf_append(strbuf *buf_o, size_t len)
|
||||
return toret;
|
||||
}
|
||||
|
||||
void strbuf_shrink_to(strbuf *buf, size_t new_len)
|
||||
{
|
||||
assert(new_len <= buf->len);
|
||||
buf->len = new_len;
|
||||
buf->s[buf->len] = '\0';
|
||||
}
|
||||
|
||||
void strbuf_shrink_by(strbuf *buf, size_t amount_to_remove)
|
||||
{
|
||||
assert(amount_to_remove <= buf->len);
|
||||
buf->len -= amount_to_remove;
|
||||
buf->s[buf->len] = '\0';
|
||||
}
|
||||
|
||||
static void strbuf_BinarySink_write(
|
||||
BinarySink *bs, const void *data, size_t len)
|
||||
{
|
||||
|
Reference in New Issue
Block a user