Skip to content

Commit

Permalink
Fix overlapping memcpy in APPEND_LIST
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisJefferson authored and fingolfin committed Feb 13, 2019
1 parent 7f93980 commit 67e51c0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/listfunc.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,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, CHARS_STRING(list2), len2 + 1);
// Can't use memcpy, in case list1 == list2
SyMemmove(CHARS_STRING(list1) + len1, CHARS_STRING(list2), len2 + 1);
return (Obj) 0;
}

Expand Down
14 changes: 14 additions & 0 deletions tst/testinstall/listindex.tst
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,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: <list1> must be a mutable list
gap> Append([1,2,3], () );
Expand Down

0 comments on commit 67e51c0

Please sign in to comment.