comparison src/arglist.c @ 31061:2606fcb01157 v9.0.0865

patch 9.0.0865: duplicate arguments are not always detected Commit: https://github.com/vim/vim/commit/b3052aa1b555ab5a81b1459a4972290381b0e7e4 Author: Nir Lichtman <nir@lichtman.org> Date: Sat Nov 12 17:00:31 2022 +0000 patch 9.0.0865: duplicate arguments are not always detected Problem: Duplicate arguments are not always detected. Solution: Expand to full path before comparing arguments. (Nir Lichtman, closes #11505, closes #9402)
author Bram Moolenaar <Bram@vim.org>
date Sat, 12 Nov 2022 18:15:02 +0100
parents c7983f593fa7
children b1c66bff0a66
comparison
equal deleted inserted replaced
31060:107f500f74d6 31061:2606fcb01157
782 { 782 {
783 int i; 783 int i;
784 int j; 784 int j;
785 785
786 for (i = 0; i < ARGCOUNT; ++i) 786 for (i = 0; i < ARGCOUNT; ++i)
787 {
788 // Expand each argument to a full path to catch different paths leading
789 // to the same file.
790 char_u *firstFullname = FullName_save(ARGLIST[i].ae_fname, FALSE);
791 if (firstFullname == NULL)
792 return; // out of memory
793
787 for (j = i + 1; j < ARGCOUNT; ++j) 794 for (j = i + 1; j < ARGCOUNT; ++j)
788 if (fnamecmp(ARGLIST[i].ae_fname, ARGLIST[j].ae_fname) == 0) 795 {
796 char_u *secondFullname = FullName_save(ARGLIST[j].ae_fname, FALSE);
797 if (secondFullname == NULL)
798 break; // out of memory
799 int areNamesDuplicate =
800 fnamecmp(firstFullname, secondFullname) == 0;
801 vim_free(secondFullname);
802
803 if (areNamesDuplicate)
789 { 804 {
805 // remove one duplicate argument
790 vim_free(ARGLIST[j].ae_fname); 806 vim_free(ARGLIST[j].ae_fname);
791 mch_memmove(ARGLIST + j, ARGLIST + j + 1, 807 mch_memmove(ARGLIST + j, ARGLIST + j + 1,
792 (ARGCOUNT - j - 1) * sizeof(aentry_T)); 808 (ARGCOUNT - j - 1) * sizeof(aentry_T));
793 --ARGCOUNT; 809 --ARGCOUNT;
794 810
797 else if (curwin->w_arg_idx > j) 813 else if (curwin->w_arg_idx > j)
798 --curwin->w_arg_idx; 814 --curwin->w_arg_idx;
799 815
800 --j; 816 --j;
801 } 817 }
818 }
819
820 vim_free(firstFullname);
821 }
802 } 822 }
803 823
804 /* 824 /*
805 * ":argedit" 825 * ":argedit"
806 */ 826 */