diff options
-rw-r--r-- | jim.c | 8 | ||||
-rw-r--r-- | regtest.tcl | 5 |
2 files changed, 11 insertions, 2 deletions
@@ -6659,8 +6659,12 @@ static void ListRemoveDuplicates(Jim_Obj *listObjPtr, int (*comp)(Jim_Obj **lhs, } ele[dst] = ele[src]; } - /* At end of list, keep the final element */ - ele[++dst] = ele[src]; + + /* At end of list, keep the final element unless all elements were kept */ + dst++; + if (dst < listObjPtr->internalRep.listValue.len) { + ele[dst] = ele[src]; + } /* Set the new length */ listObjPtr->internalRep.listValue.len = dst; diff --git a/regtest.tcl b/regtest.tcl index 0761c49..df25d13 100644 --- a/regtest.tcl +++ b/regtest.tcl @@ -310,6 +310,11 @@ puts "TEST 42 PASSED" catch {format %----------------------------------------d 1} puts "TEST 43 PASSED" +# REGTEST 44 +# lsort -unique with no duplicate - invalid memory write +lsort -unique {a b c d} +puts "TEST 44 PASSED" + # TAKE THE FOLLOWING puts AS LAST LINE puts "--- ALL TESTS PASSED ---" |