bugfix: string-copy issue

This commit is contained in:
Yuichi Nishiwaki 2017-03-23 22:33:41 +09:00
parent 25e2ad7505
commit 4834052556
2 changed files with 12 additions and 6 deletions

View File

@ -80,22 +80,20 @@ make_rope_lit(pic_state *pic, const char *str, int len)
static struct rope *
make_rope_slice(pic_state *pic, struct rope *owner, int i, int j)
{
struct rope *rope;
struct rope *rope, *real_owner;
assert(owner->isleaf);
if (owner->u.leaf.owner != NULL) {
owner = owner->u.leaf.owner;
}
real_owner = owner->u.leaf.owner == NULL ? owner : owner->u.leaf.owner;
rope = pic_malloc(pic, offsetof(struct rope, buf));
rope->refcnt = 1;
rope->weight = j - i;
rope->isleaf = true;
rope->u.leaf.owner = owner;
rope->u.leaf.owner = real_owner;
rope->u.leaf.str = owner->u.leaf.str + i;
pic_rope_incref(owner);
pic_rope_incref(real_owner);
return rope;
}

8
t/issue/string-copy.scm Normal file
View File

@ -0,0 +1,8 @@
(import (scheme base)
(picrin test))
(test-begin)
(test "456" (string-copy (string-copy "1234567" 3) 0 3))
(test-end)