From c2c320def33099394309312415131d4fe8fb69e7 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Mon, 8 May 2017 06:14:18 -0700 Subject: buffers: correct length check in buf-put- functions. * buf.c (buf_put_bytes): We must extend the buffer based on looking at the end position of the data transfer, not the start position, so the buffer is large enough to old the entire transfer. --- buf.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/buf.c b/buf.c index c9cb4332..c9dcef5d 100644 --- a/buf.c +++ b/buf.c @@ -216,8 +216,9 @@ static void buf_put_bytes(val buf, val pos, mem_t *ptr, cnum size, val self) { struct buf *b = buf_handle(buf, self); cnum p = buf_check_index(pos, self); - if (p >= c_num(b->len)) - buf_do_set_len(buf, b, plus(pos, num_fast(size)), nil, self); + val req_len = plus(pos, num_fast(size)); + if (gt(req_len, b->len)) + buf_do_set_len(buf, b, req_len, nil, self); memcpy(b->data + p, ptr, size); } -- cgit v1.2.3