From 0b52768a15706b53e38890e1dc1ebc7f92e00166 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sat, 25 Apr 2020 08:17:22 -0700 Subject: lib/buf: use unsigned integers around allocations. * buf.c (buf_shrink): Convert len to alloc size using c_unum, which will reject negative values that will implicitly convert to a wrong/huge size. * lib.c (upcase_str, downcase_str): Similar reasoning. (sub_vec): nelem is a size_t, so use unum on it, rather than num. --- buf.c | 2 +- lib.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/buf.c b/buf.c index 4fb25ad6..3cd050ef 100644 --- a/buf.c +++ b/buf.c @@ -160,7 +160,7 @@ static void buf_shrink(struct buf *b) len = succ(len); /* avoid reallocing to zero length; i.e. freeing */ if (len != b->size) { - b->data = chk_realloc(b->data, c_num(len)); + b->data = chk_realloc(b->data, c_unum(len)); b->size = b->len; } } diff --git a/lib.c b/lib.c index 1ad10b78..e1ffbf66 100644 --- a/lib.c +++ b/lib.c @@ -3574,7 +3574,7 @@ val copy_str(val str) val upcase_str(val str) { val len = length_str(str); - wchar_t *dst = chk_wmalloc(c_num(len) + 1); + wchar_t *dst = chk_wmalloc(c_unum(len) + 1); const wchar_t *src = c_str(str); val out = string_own(dst); @@ -3587,7 +3587,7 @@ val upcase_str(val str) val downcase_str(val str) { val len = length_str(str); - wchar_t *dst = chk_wmalloc(c_num(len) + 1); + wchar_t *dst = chk_wmalloc(c_unum(len) + 1); const wchar_t *src = c_str(str); val out = string_own(dst); @@ -7553,7 +7553,7 @@ val sub_vec(val vec_in, val from, val to) #endif v += 2; vec->v.vec = v; - v[vec_length] = v[vec_alloc] = num(nelem); + v[vec_length] = v[vec_alloc] = unum(nelem); memcpy(vec->v.vec, vec_in->v.vec + cfrom, nelem * sizeof *vec->v.vec); return vec; } -- cgit v1.2.3