summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2017-05-08 06:14:18 -0700
committerKaz Kylheku <kaz@kylheku.com>2017-05-08 06:14:18 -0700
commitef35d8ffb30211d2145d30b0cb9de88d2f3e729a (patch)
tree2a1b16804db94292e655d90c0393113f84dab388
parent33acb79f64de9a05122f0e3cc103cbcf58864b9c (diff)
downloadtxr-ef35d8ffb30211d2145d30b0cb9de88d2f3e729a.tar.gz
txr-ef35d8ffb30211d2145d30b0cb9de88d2f3e729a.tar.bz2
txr-ef35d8ffb30211d2145d30b0cb9de88d2f3e729a.zip
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.
-rw-r--r--buf.c5
1 files 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);
}