summaryrefslogtreecommitdiffstats
path: root/buf.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-05-04 06:44:28 -0700
committerKaz Kylheku <kaz@kylheku.com>2021-05-04 06:44:28 -0700
commit9a7f2d51807c182c7cb7e554c3be109ccd066ad8 (patch)
treec641a65025a31bffe8eff8d43d82b88c56a1adf6 /buf.c
parente1666e62bc27c89a6ff529c308eacbad9d132e31 (diff)
downloadtxr-9a7f2d51807c182c7cb7e554c3be109ccd066ad8.tar.gz
txr-9a7f2d51807c182c7cb7e554c3be109ccd066ad8.tar.bz2
txr-9a7f2d51807c182c7cb7e554c3be109ccd066ad8.zip
buf: bugfix: int-buf, uint-buf refer to alloc size.
* buf.c (int_buf, uint_buf): Refer to the buffer length b->len rather than the underlying allocation size b->size. Referring to b->size will not only produce the wrong value when it is larger than len, but b->size can be null for a borrowed buffer, producing a crash. * tests/012/buf.tl: Tests.
Diffstat (limited to 'buf.c')
-rw-r--r--buf.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/buf.c b/buf.c
index f4193a74..4305952e 100644
--- a/buf.c
+++ b/buf.c
@@ -1184,7 +1184,7 @@ static val int_buf(val buf)
{
val self = lit("int-buf");
struct buf *b = buf_handle(buf, self);
- ucnum size = c_unum(b->size, self);
+ ucnum size = c_unum(b->len, self);
ucnum bits = size * 8;
val ubn = make_bignum();
mp_err mpe = mp_read_unsigned_bin(mp(ubn), b->data, size);
@@ -1197,7 +1197,7 @@ static val uint_buf(val buf)
{
val self = lit("uint-buf");
struct buf *b = buf_handle(buf, self);
- ucnum size = c_unum(b->size, self);
+ ucnum size = c_unum(b->len, self);
val ubn = make_bignum();
mp_err mpe = mp_read_unsigned_bin(mp(ubn), b->data, size);
if (mpe != MP_OKAY)