summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordefault <nobody@localhost>2023-10-09 21:15:41 +0200
committerdefault <nobody@localhost>2023-10-09 21:15:41 +0200
commite9d2d148733a547fcd4fe680dbe83e754d6c0d81 (patch)
tree5498818fe48f88f6c877a29b24cafb39e8d0ab0e
parent986b87cdfc4f8b20641ad5ec4d38c3921b953e18 (diff)
Backport from xs.
-rw-r--r--xs.h12
1 files changed, 7 insertions, 5 deletions
diff --git a/xs.h b/xs.h
index 1fe210e..18b1d9c 100644
--- a/xs.h
+++ b/xs.h
@@ -365,19 +365,21 @@ xs_val *xs_expand(xs_val *data, int offset, int size)
/* opens a hole in data */
{
int sz = xs_size(data);
+ int n;
+
+ sz += size;
/* open room */
- if (sz == 0 || _xs_blk_size(sz) != _xs_blk_size(sz + size))
- data = xs_realloc(data, _xs_blk_size(sz + size));
+ data = xs_realloc(data, _xs_blk_size(sz));
/* move up the rest of the data */
- if (data != NULL)
- memmove(data + offset + size, data + offset, sz - offset);
+ for (n = sz - 1; n >= offset + size; n--)
+ data[n] = data[n - size];
if (xs_type(data) == XSTYPE_LIST ||
xs_type(data) == XSTYPE_DICT ||
xs_type(data) == XSTYPE_DATA)
- _xs_put_24b(data + 1, sz + size);
+ _xs_put_24b(data + 1, sz);
return data;
}