diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2020-04-25 08:17:22 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2020-04-25 08:17:22 -0700 |
commit | 0b52768a15706b53e38890e1dc1ebc7f92e00166 (patch) | |
tree | 6306b6ddc21336d37413de4efd59756fdaec9197 /lib.c | |
parent | fe6db6bcc360dded3383f06a47275610371be874 (diff) | |
download | txr-0b52768a15706b53e38890e1dc1ebc7f92e00166.tar.gz txr-0b52768a15706b53e38890e1dc1ebc7f92e00166.tar.bz2 txr-0b52768a15706b53e38890e1dc1ebc7f92e00166.zip |
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.
Diffstat (limited to 'lib.c')
-rw-r--r-- | lib.c | 6 |
1 files changed, 3 insertions, 3 deletions
@@ -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; } |