diff --git a/src/listfunc.c b/src/listfunc.c index 8cd6fc5d68..62da1e572b 100644 --- a/src/listfunc.c +++ b/src/listfunc.c @@ -267,7 +267,8 @@ Obj FuncAPPEND_LIST_INTR ( SET_LEN_STRING(list1, len1 + len2); CLEAR_FILTS_LIST(list1); // copy data, including terminating zero byte - memcpy(CHARS_STRING(list1) + len1, CONST_CHARS_STRING(list2), len2 + 1); + // Can't use memcpy, in case list1 == list2 + SyMemmove(CHARS_STRING(list1) + len1, CONST_CHARS_STRING(list2), len2 + 1); return (Obj) 0; } diff --git a/tst/testinstall/listindex.tst b/tst/testinstall/listindex.tst index b5d9f0dd6a..3ce69f27e7 100644 --- a/tst/testinstall/listindex.tst +++ b/tst/testinstall/listindex.tst @@ -186,6 +186,20 @@ gap> l := "cheese";; Append(l, [true]); l; [ 'c', 'h', 'e', 'e', 's', 'e', true ] gap> l := "cheese";; Append(l, []); l; "cheese" +gap> Append(l, l); l; +"cheesecheese" +gap> l := "chee";; Append(l, l); l; +"cheechee" +gap> l := "cheeseXX";; Append(l, l); l; +"cheeseXXcheeseXX" +gap> l := [true];; Append(l, l); l; +[ true, true ] +gap> Append(l,l); l; +[ true, true, true, true ] +gap> l := [];; Append(l,l); l; +[ ] +gap> l := [1,2,3,4];; Append(l,l); l; +[ 1, 2, 3, 4, 1, 2, 3, 4 ] gap> Append(Immutable([1,2,3]), [1,2,3]); Error, Append: must be a mutable list gap> Append([1,2,3], () );