fix xr_put

This commit is contained in:
Yuichi Nishiwaki 2014-06-27 17:40:43 +09:00
parent 4501b9bd93
commit 3ee807a347
1 changed files with 7 additions and 6 deletions

View File

@ -74,28 +74,29 @@ pic_str_ref(pic_state *pic, pic_str *str, size_t i)
static xrope *
xr_put(xrope *rope, size_t i, char c)
{
xrope *x, *y;
char buf[1];
xrope *x, *y, *z;
char buf[2];
if (xr_len(rope) <= i) {
return NULL;
}
buf[0] = c;
buf[1] = '\0';
x = xr_sub(rope, 0, i);
y = xr_new_copy(buf, 1);
rope = xr_cat(x, y);
z = xr_cat(x, y);
XROPE_DECREF(x);
XROPE_DECREF(y);
x = rope;
x = z;
y = xr_sub(rope, i + 1, xr_len(rope));
rope = xr_cat(x, y);
z = xr_cat(z, y);
XROPE_DECREF(x);
XROPE_DECREF(y);
return rope;
return z;
}
void