diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2017-05-08 06:14:18 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2017-05-08 06:14:18 -0700 |
commit | ef35d8ffb30211d2145d30b0cb9de88d2f3e729a (patch) | |
tree | 2a1b16804db94292e655d90c0393113f84dab388 | |
parent | 33acb79f64de9a05122f0e3cc103cbcf58864b9c (diff) | |
download | txr-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.c | 5 |
1 files changed, 3 insertions, 2 deletions
@@ -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); } |