From e8dd9967034c89d0493c7dffe13cfd08bab9e83a Mon Sep 17 00:00:00 2001 From: Jurica Bradaric Date: Tue, 9 Feb 2016 20:25:08 +0100 Subject: vim-patch:7.4.835 Problem: Comparing utf-8 sequences does not handle different byte sizes correctly. Solution: Get the byte size of each character. (Dominique Pelle) https://github.com/vim/vim/commit/f6470c288cb6f8efd60a507baf2c070f9d209ae6 --- src/nvim/file_search.c | 15 ++++++++------- src/nvim/path.c | 13 +++++++++---- src/nvim/version.c | 2 +- 3 files changed, 18 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/nvim/file_search.c b/src/nvim/file_search.c index b213a42c52..8c4a2f8275 100644 --- a/src/nvim/file_search.c +++ b/src/nvim/file_search.c @@ -1057,7 +1057,7 @@ static ff_visited_list_hdr_T *ff_get_visited_list(char_u *filename, ff_visited_l */ static int ff_wc_equal(char_u *s1, char_u *s2) { - int i; + int i, j; int prev1 = NUL; int prev2 = NUL; @@ -1067,18 +1067,19 @@ static int ff_wc_equal(char_u *s1, char_u *s2) if (s1 == NULL || s2 == NULL) return FALSE; - if (STRLEN(s1) != STRLEN(s2)) - return FAIL; - - for (i = 0; s1[i] != NUL && s2[i] != NUL; i += MB_PTR2LEN(s1 + i)) { + for (i = 0, j = 0; s1[i] != NUL;) { int c1 = PTR2CHAR(s1 + i); - int c2 = PTR2CHAR(s2 + i); + int c2 = PTR2CHAR(s2 + j); if ((p_fic ? vim_tolower(c1) != vim_tolower(c2) : c1 != c2) - && (prev1 != '*' || prev2 != '*')) + && (prev1 != '*' || prev2 != '*')) { return FAIL; + } prev2 = prev1; prev1 = c1; + + i += MB_PTR2LEN(s1 + i); + j += MB_PTR2LEN(s2 + j); } return TRUE; } diff --git a/src/nvim/path.c b/src/nvim/path.c index 8b9a49dfc0..e0e5f19911 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -1775,19 +1775,20 @@ bool same_directory(char_u *f1, char_u *f2) */ int pathcmp(const char *p, const char *q, int maxlen) { - int i; + int i, j; int c1, c2; const char *s = NULL; - for (i = 0; maxlen < 0 || i < maxlen; i += MB_PTR2LEN((char_u *)p + i)) { + for (i = 0, j = 0; maxlen < 0 || (i < maxlen && j < maxlen);) { c1 = PTR2CHAR((char_u *)p + i); - c2 = PTR2CHAR((char_u *)q + i); + c2 = PTR2CHAR((char_u *)q + j); /* End of "p": check if "q" also ends or just has a slash. */ if (c1 == NUL) { if (c2 == NUL) /* full match */ return 0; s = q; + i = j; break; } @@ -1811,9 +1812,13 @@ int pathcmp(const char *p, const char *q, int maxlen) return p_fic ? vim_toupper(c1) - vim_toupper(c2) : c1 - c2; /* no match */ } + + i += MB_PTR2LEN((char_u *)p + i); + j += MB_PTR2LEN((char_u *)q + j); } - if (s == NULL) /* "i" ran into "maxlen" */ + if (s == NULL) { // "i" or "j" ran into "maxlen" return 0; + } c1 = PTR2CHAR((char_u *)s + i); c2 = PTR2CHAR((char_u *)s + i + MB_PTR2LEN((char_u *)s + i)); diff --git a/src/nvim/version.c b/src/nvim/version.c index 487f3fc27b..0c36996854 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -453,7 +453,7 @@ static int included_patches[] = { // 838, // 837 NA 836, - // 835, + 835, 834, // 833, // 832, -- cgit From ab8a771dbd1fd4bf0a3ed0c90c0b7bec040c4c7a Mon Sep 17 00:00:00 2001 From: Jurica Bradaric Date: Wed, 10 Feb 2016 11:21:11 +0100 Subject: file_search: Declare loop variables inside the loop. --- src/nvim/file_search.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src') diff --git a/src/nvim/file_search.c b/src/nvim/file_search.c index 8c4a2f8275..a421c555c1 100644 --- a/src/nvim/file_search.c +++ b/src/nvim/file_search.c @@ -1057,7 +1057,6 @@ static ff_visited_list_hdr_T *ff_get_visited_list(char_u *filename, ff_visited_l */ static int ff_wc_equal(char_u *s1, char_u *s2) { - int i, j; int prev1 = NUL; int prev2 = NUL; @@ -1067,7 +1066,7 @@ static int ff_wc_equal(char_u *s1, char_u *s2) if (s1 == NULL || s2 == NULL) return FALSE; - for (i = 0, j = 0; s1[i] != NUL;) { + for (int i = 0, j = 0; s1[i] != NUL;) { int c1 = PTR2CHAR(s1 + i); int c2 = PTR2CHAR(s2 + j); -- cgit From c9898e0ec3c6e1eccf816536b780c5da6c047c2a Mon Sep 17 00:00:00 2001 From: Jurica Bradaric Date: Tue, 9 Feb 2016 22:59:16 +0100 Subject: vim-patch:7.4.843 Problem: Still possible to go beyond the end of a string. Solution: Check for NUL also in second string. (Dominique Pelle) https://github.com/vim/vim/commit/d43f0951bca162d4491d57df9277b5dbc462944f --- src/nvim/file_search.c | 12 +++++++----- src/nvim/version.c | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/nvim/file_search.c b/src/nvim/file_search.c index a421c555c1..7b1ad85faa 100644 --- a/src/nvim/file_search.c +++ b/src/nvim/file_search.c @@ -1057,6 +1057,8 @@ static ff_visited_list_hdr_T *ff_get_visited_list(char_u *filename, ff_visited_l */ static int ff_wc_equal(char_u *s1, char_u *s2) { + int c1 = NUL; + int c2 = NUL; int prev1 = NUL; int prev2 = NUL; @@ -1066,13 +1068,13 @@ static int ff_wc_equal(char_u *s1, char_u *s2) if (s1 == NULL || s2 == NULL) return FALSE; - for (int i = 0, j = 0; s1[i] != NUL;) { - int c1 = PTR2CHAR(s1 + i); - int c2 = PTR2CHAR(s2 + j); + for (int i = 0, j = 0; s1[i] != NUL && s2[j] != NUL;) { + c1 = PTR2CHAR(s1 + i); + c2 = PTR2CHAR(s2 + j); if ((p_fic ? vim_tolower(c1) != vim_tolower(c2) : c1 != c2) && (prev1 != '*' || prev2 != '*')) { - return FAIL; + return false; } prev2 = prev1; prev1 = c1; @@ -1080,7 +1082,7 @@ static int ff_wc_equal(char_u *s1, char_u *s2) i += MB_PTR2LEN(s1 + i); j += MB_PTR2LEN(s2 + j); } - return TRUE; + return c1 == c2; } /* diff --git a/src/nvim/version.c b/src/nvim/version.c index 0c36996854..e1910895b6 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -445,7 +445,7 @@ static int included_patches[] = { // 846 NA // 845, // 844, - // 843, + 843, // 842 NA // 841 NA // 840 NA -- cgit From b86553c7ad23cac71aaf51fd8bb77b50921def62 Mon Sep 17 00:00:00 2001 From: Jurica Bradaric Date: Tue, 9 Feb 2016 23:12:33 +0100 Subject: file_search: Change return type of ff_wc_equal to bool. This makes sense since the function returns only TRUE or FALSE. --- src/nvim/file_search.c | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/nvim/file_search.c b/src/nvim/file_search.c index 7b1ad85faa..9ee1aa5359 100644 --- a/src/nvim/file_search.c +++ b/src/nvim/file_search.c @@ -1046,27 +1046,27 @@ static ff_visited_list_hdr_T *ff_get_visited_list(char_u *filename, ff_visited_l return retptr; } -/* - * check if two wildcard paths are equal. Returns TRUE or FALSE. - * They are equal if: - * - both paths are NULL - * - they have the same length - * - char by char comparison is OK - * - the only differences are in the counters behind a '**', so - * '**\20' is equal to '**\24' - */ -static int ff_wc_equal(char_u *s1, char_u *s2) +// Check if two wildcard paths are equal. +// They are equal if: +// - both paths are NULL +// - they have the same length +// - char by char comparison is OK +// - the only differences are in the counters behind a '**', so +// '**\20' is equal to '**\24' +static bool ff_wc_equal(char_u *s1, char_u *s2) { int c1 = NUL; int c2 = NUL; int prev1 = NUL; int prev2 = NUL; - if (s1 == s2) - return TRUE; + if (s1 == s2) { + return true; + } - if (s1 == NULL || s2 == NULL) - return FALSE; + if (s1 == NULL || s2 == NULL) { + return false; + } for (int i = 0, j = 0; s1[i] != NUL && s2[j] != NUL;) { c1 = PTR2CHAR(s1 + i); @@ -1113,10 +1113,11 @@ static int ff_check_visited(ff_visited_T **visited_list, char_u *fname, char_u * if ((url && fnamecmp(vp->ffv_fname, ff_expand_buffer) == 0) || (!url && vp->file_id_valid && os_fileid_equal(&(vp->file_id), &file_id))) { - /* are the wildcard parts equal */ - if (ff_wc_equal(vp->ffv_wc_path, wc_path) == TRUE) - /* already visited */ + // are the wildcard parts equal + if (ff_wc_equal(vp->ffv_wc_path, wc_path)) { + // already visited return FAIL; + } } } -- cgit From a21becf7ee1cb9079b1d97da282538ad43d74352 Mon Sep 17 00:00:00 2001 From: Jurica Bradaric Date: Thu, 11 Feb 2016 22:29:43 +0100 Subject: vim-patch:7.4.877 Problem: ":find" sometimes fails. (Excanoe) Solution: Compare current characters instead of previous ones. https://github.com/vim/vim/commit/4d0c7bc74ac6fad5cb599dc3ade6996e848d83b6 --- src/nvim/file_search.c | 5 +++-- src/nvim/version.c | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/nvim/file_search.c b/src/nvim/file_search.c index 9ee1aa5359..3ad20991a4 100644 --- a/src/nvim/file_search.c +++ b/src/nvim/file_search.c @@ -1055,6 +1055,7 @@ static ff_visited_list_hdr_T *ff_get_visited_list(char_u *filename, ff_visited_l // '**\20' is equal to '**\24' static bool ff_wc_equal(char_u *s1, char_u *s2) { + int i, j; int c1 = NUL; int c2 = NUL; int prev1 = NUL; @@ -1068,7 +1069,7 @@ static bool ff_wc_equal(char_u *s1, char_u *s2) return false; } - for (int i = 0, j = 0; s1[i] != NUL && s2[j] != NUL;) { + for (i = 0, j = 0; s1[i] != NUL && s2[j] != NUL;) { c1 = PTR2CHAR(s1 + i); c2 = PTR2CHAR(s2 + j); @@ -1082,7 +1083,7 @@ static bool ff_wc_equal(char_u *s1, char_u *s2) i += MB_PTR2LEN(s1 + i); j += MB_PTR2LEN(s2 + j); } - return c1 == c2; + return s1[i] == s2[j]; } /* diff --git a/src/nvim/version.c b/src/nvim/version.c index e1910895b6..9a9d6dfd38 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -411,7 +411,7 @@ static int included_patches[] = { // 880 NA // 879, // 878, - // 877, + 877, // 876 NA // 875 NA // 874 NA -- cgit