mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-15 01:55:03 +00:00
Backport from xs.
This commit is contained in:
parent
986b87cdfc
commit
e9d2d14873
1 changed files with 7 additions and 5 deletions
12
xs.h
12
xs.h
|
@ -365,19 +365,21 @@ xs_val *xs_expand(xs_val *data, int offset, int size)
|
||||||
/* opens a hole in data */
|
/* opens a hole in data */
|
||||||
{
|
{
|
||||||
int sz = xs_size(data);
|
int sz = xs_size(data);
|
||||||
|
int n;
|
||||||
|
|
||||||
|
sz += size;
|
||||||
|
|
||||||
/* open room */
|
/* open room */
|
||||||
if (sz == 0 || _xs_blk_size(sz) != _xs_blk_size(sz + size))
|
data = xs_realloc(data, _xs_blk_size(sz));
|
||||||
data = xs_realloc(data, _xs_blk_size(sz + size));
|
|
||||||
|
|
||||||
/* move up the rest of the data */
|
/* move up the rest of the data */
|
||||||
if (data != NULL)
|
for (n = sz - 1; n >= offset + size; n--)
|
||||||
memmove(data + offset + size, data + offset, sz - offset);
|
data[n] = data[n - size];
|
||||||
|
|
||||||
if (xs_type(data) == XSTYPE_LIST ||
|
if (xs_type(data) == XSTYPE_LIST ||
|
||||||
xs_type(data) == XSTYPE_DICT ||
|
xs_type(data) == XSTYPE_DICT ||
|
||||||
xs_type(data) == XSTYPE_DATA)
|
xs_type(data) == XSTYPE_DATA)
|
||||||
_xs_put_24b(data + 1, sz + size);
|
_xs_put_24b(data + 1, sz);
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue