bugfix: string-copy issue
This commit is contained in:
parent
25e2ad7505
commit
4834052556
10
lib/string.c
10
lib/string.c
|
@ -80,22 +80,20 @@ make_rope_lit(pic_state *pic, const char *str, int len)
|
||||||
static struct rope *
|
static struct rope *
|
||||||
make_rope_slice(pic_state *pic, struct rope *owner, int i, int j)
|
make_rope_slice(pic_state *pic, struct rope *owner, int i, int j)
|
||||||
{
|
{
|
||||||
struct rope *rope;
|
struct rope *rope, *real_owner;
|
||||||
|
|
||||||
assert(owner->isleaf);
|
assert(owner->isleaf);
|
||||||
|
|
||||||
if (owner->u.leaf.owner != NULL) {
|
real_owner = owner->u.leaf.owner == NULL ? owner : owner->u.leaf.owner;
|
||||||
owner = owner->u.leaf.owner;
|
|
||||||
}
|
|
||||||
|
|
||||||
rope = pic_malloc(pic, offsetof(struct rope, buf));
|
rope = pic_malloc(pic, offsetof(struct rope, buf));
|
||||||
rope->refcnt = 1;
|
rope->refcnt = 1;
|
||||||
rope->weight = j - i;
|
rope->weight = j - i;
|
||||||
rope->isleaf = true;
|
rope->isleaf = true;
|
||||||
rope->u.leaf.owner = owner;
|
rope->u.leaf.owner = real_owner;
|
||||||
rope->u.leaf.str = owner->u.leaf.str + i;
|
rope->u.leaf.str = owner->u.leaf.str + i;
|
||||||
|
|
||||||
pic_rope_incref(owner);
|
pic_rope_incref(real_owner);
|
||||||
|
|
||||||
return rope;
|
return rope;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
(import (scheme base)
|
||||||
|
(picrin test))
|
||||||
|
|
||||||
|
(test-begin)
|
||||||
|
|
||||||
|
(test "456" (string-copy (string-copy "1234567" 3) 0 3))
|
||||||
|
|
||||||
|
(test-end)
|
Loading…
Reference in New Issue