To: vim_dev@googlegroups.com Subject: Patch 9.0.0865 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 9.0.0865 Problem: Duplicate arguments are not always detected. Solution: Expand to full path before comparing arguments. (Nir Lichtman, closes #11505, closes #9402) Files: src/arglist.c, src/testdir/test_arglist.vim *** ../vim-9.0.0864/src/arglist.c 2022-10-13 22:12:07.160673838 +0100 --- src/arglist.c 2022-11-12 16:59:05.944045526 +0000 *************** *** 784,792 **** int j; for (i = 0; i < ARGCOUNT; ++i) for (j = i + 1; j < ARGCOUNT; ++j) ! if (fnamecmp(ARGLIST[i].ae_fname, ARGLIST[j].ae_fname) == 0) { vim_free(ARGLIST[j].ae_fname); mch_memmove(ARGLIST + j, ARGLIST + j + 1, (ARGCOUNT - j - 1) * sizeof(aentry_T)); --- 784,808 ---- int j; for (i = 0; i < ARGCOUNT; ++i) + { + // Expand each argument to a full path to catch different paths leading + // to the same file. + char_u *firstFullname = FullName_save(ARGLIST[i].ae_fname, FALSE); + if (firstFullname == NULL) + return; // out of memory + for (j = i + 1; j < ARGCOUNT; ++j) ! { ! char_u *secondFullname = FullName_save(ARGLIST[j].ae_fname, FALSE); ! if (secondFullname == NULL) ! break; // out of memory ! int areNamesDuplicate = ! fnamecmp(firstFullname, secondFullname) == 0; ! vim_free(secondFullname); ! ! if (areNamesDuplicate) { + // remove one duplicate argument vim_free(ARGLIST[j].ae_fname); mch_memmove(ARGLIST + j, ARGLIST + j + 1, (ARGCOUNT - j - 1) * sizeof(aentry_T)); *************** *** 799,804 **** --- 815,824 ---- --j; } + } + + vim_free(firstFullname); + } } /* *** ../vim-9.0.0864/src/testdir/test_arglist.vim 2022-10-05 11:24:42.228494178 +0100 --- src/testdir/test_arglist.vim 2022-11-12 16:53:53.967852079 +0000 *************** *** 420,434 **** --- 420,438 ---- call Reset_arglist() argdedupe call assert_equal([], argv()) + args a a a aa b b a b aa argdedupe call assert_equal(['a', 'aa', 'b'], argv()) + args a b c argdedupe call assert_equal(['a', 'b', 'c'], argv()) + args a argdedupe call assert_equal(['a'], argv()) + args a A b B argdedupe if has('fname_case') *************** *** 436,446 **** --- 440,456 ---- else call assert_equal(['a', 'b'], argv()) endif + args a b a c a b last argdedupe next call assert_equal('c', expand('%:t')) + + args a ./a + argdedupe + call assert_equal(['a'], argv()) + %argd endfunc *** ../vim-9.0.0864/src/version.c 2022-11-12 16:36:31.235201639 +0000 --- src/version.c 2022-11-12 16:52:54.759815324 +0000 *************** *** 697,698 **** --- 697,700 ---- { /* Add new patch number below this line */ + /**/ + 865, /**/ -- hundred-and-one symptoms of being an internet addict: 46. Your wife makes a new rule: "The computer cannot come to bed." /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///