summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2018-02-28 18:45:41 -0800
committerKaz Kylheku <kaz@kylheku.com>2018-02-28 18:45:41 -0800
commit7486b46baa2647cae926ffa6b8847b9079aa2ad1 (patch)
treedb597493b2e0daaa3db46a1fba868cf41bba34a8
parentb766793fbaa1190b5ccd05e37cc8b0bd0869e625 (diff)
downloadtxr-7486b46baa2647cae926ffa6b8847b9079aa2ad1.tar.gz
txr-7486b46baa2647cae926ffa6b8847b9079aa2ad1.tar.bz2
txr-7486b46baa2647cae926ffa6b8847b9079aa2ad1.zip
bugfix: buf-get-* not allowing last byte of buffer.
* buf.c (buf_get_bytes): Fix off-by-one test for reading past end of buffer. This prevents, e.g. a buf-get-u32 from the last four bytes of a buffer (or from a four-byte-long buffer, period).
-rw-r--r--buf.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/buf.c b/buf.c
index 192449c2..3e1ed76a 100644
--- a/buf.c
+++ b/buf.c
@@ -423,7 +423,7 @@ static void buf_get_bytes(val buf, val pos, mem_t *ptr, cnum size, val self)
cnum e = p + size;
cnum l = c_num(b->len);
- if (e >= l || e < 0)
+ if (e > l || e < 0)
uw_throwf(error_s, lit("~a: attempted read past buffer end"), self, nao);
memcpy(ptr, b->data + p, size);