Skip to content

Commit

Permalink
Fix off-by-one error in CopyListEntries
Browse files Browse the repository at this point in the history
The length of the list may be changed if we add new members to the
list to the end of list, or unbind the final element.
  • Loading branch information
ChrisJefferson authored and fingolfin committed Jul 7, 2022
1 parent bdf94cb commit a40ffa3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/listfunc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1388,7 +1388,7 @@ static Obj FuncCOPY_LIST_ENTRIES(Obj self, Obj args)
}
}

if (dstmax > LEN_PLIST(dstlist))
if (dstmax >= LEN_PLIST(dstlist))
{
sptr = CONST_ADDR_OBJ(dstlist)+dstmax;
ct = dstmax;
Expand Down
9 changes: 9 additions & 0 deletions tst/testinstall/listindex.tst
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,15 @@ gap> CopyListEntries(l,2,2,l,3,2,2); l;
gap> l := [1,2,3,4,5];;
gap> CopyListEntries(l,1,1,l,3,2,2); l;
[ 1, 2, 1, 4, 2 ]
gap> l := [1,2,3,4,5];;
gap> CopyListEntries([],1,1,l,1,1,5); l;
[ ]
gap> l := [1,2,3,4,5];;
gap> CopyListEntries([],1,1,l,1,1,6); l;
[ ]
gap> l := [1,2,3,4,5];;
gap> CopyListEntries([1,,,,,,7],1,1,l,1,1,6); l;
[ 1 ]

#
gap> CopyListEntries();
Expand Down

0 comments on commit a40ffa3

Please sign in to comment.