summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2025-05-07 07:52:56 -0700
committerKaz Kylheku <kaz@kylheku.com>2025-05-07 07:52:56 -0700
commit7bd9bb82eed3064c241aa4d20212aadb769130cc (patch)
tree222c4be0db72fdf8e81ca905ae6b007404541e46
parent31c387fe210456000ec421337f6cfeb5bc61b8e4 (diff)
downloadtxr-7bd9bb82eed3064c241aa4d20212aadb769130cc.tar.gz
txr-7bd9bb82eed3064c241aa4d20212aadb769130cc.tar.bz2
txr-7bd9bb82eed3064c241aa4d20212aadb769130cc.zip
buf: int-buf: unsigned multiplication overflow.
* buf.c (int_buf): Do not multiply the buffer length by 8 as a built-in unsigned integer. Use the mul function instead on the original Lisp integer length. sign-extend handles bignum values for the bit width.
-rw-r--r--buf.c3
1 files changed, 1 insertions, 2 deletions
diff --git a/buf.c b/buf.c
index f5f27b39..906a800a 100644
--- a/buf.c
+++ b/buf.c
@@ -1305,12 +1305,11 @@ static val int_buf(val buf)
val self = lit("int-buf");
struct buf *b = buf_handle(buf, 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);
if (mpe != MP_OKAY)
do_mp_error(self, mpe);
- return sign_extend(normalize(ubn), unum(bits));
+ return sign_extend(normalize(ubn), mul(b->len, num_fast(8)));
}
static val uint_buf(val buf)