diff --git a/src/string.c b/src/string.c index edaf1edc..e9a0095b 100644 --- a/src/string.c +++ b/src/string.c @@ -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