From fe074611cd5b3319a3f639f68289df6a718e64eb Mon Sep 17 00:00:00 2001 From: Jurica Bradarić Date: Sun, 6 Oct 2019 05:35:48 +0200 Subject: vim-patch:8.1.1371: cannot recover from a swap file #11081 Problem: Cannot recover from a swap file. Solution: Do not expand environment variables in the swap file name. Do not check the extension when we already know a file is a swap file. (Ken Takata, closes 4415, closes vim/vim#4369) https://github.com/vim/vim/commit/99499b1c05f85f83876b828eea3f6e14f0f407b4 --- src/nvim/spell.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/nvim/spell.c') diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 724a0332bc..ab40355a8a 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -2031,7 +2031,8 @@ char_u *did_set_spelllang(win_T *wp) // Check if we loaded this language before. for (slang = first_lang; slang != NULL; slang = slang->sl_next) { - if (path_full_compare(lang, slang->sl_fname, false) == kEqualFiles) { + if (path_full_compare(lang, slang->sl_fname, false, true) + == kEqualFiles) { break; } } @@ -2076,7 +2077,7 @@ char_u *did_set_spelllang(win_T *wp) // Loop over the languages, there can be several files for "lang". for (slang = first_lang; slang != NULL; slang = slang->sl_next) { if (filename - ? path_full_compare(lang, slang->sl_fname, false) == kEqualFiles + ? path_full_compare(lang, slang->sl_fname, false, true) == kEqualFiles : STRICMP(lang, slang->sl_name) == 0) { region_mask = REGION_ALL; if (!filename && region != NULL) { @@ -2129,7 +2130,7 @@ char_u *did_set_spelllang(win_T *wp) for (c = 0; c < ga.ga_len; ++c) { p = LANGP_ENTRY(ga, c)->lp_slang->sl_fname; if (p != NULL - && path_full_compare(spf_name, p, false) == kEqualFiles) { + && path_full_compare(spf_name, p, false, true) == kEqualFiles) { break; } } @@ -2139,7 +2140,8 @@ char_u *did_set_spelllang(win_T *wp) // Check if it was loaded already. for (slang = first_lang; slang != NULL; slang = slang->sl_next) { - if (path_full_compare(spf_name, slang->sl_fname, false) == kEqualFiles) { + if (path_full_compare(spf_name, slang->sl_fname, false, true) + == kEqualFiles) { break; } } -- cgit From 09232958ff9c7d4737701160549c8d64a0f92856 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sun, 6 Oct 2019 20:52:30 -0400 Subject: vim-patch:8.1.2120: some MB_ macros are more complicated than necessary Problem: Some MB_ macros are more complicated than necessary. (Dominique Pelle) Solution: Simplify the macros. Expand inline. https://github.com/vim/vim/commit/1614a14901558ca091329315d14a7d5e1b53aa47 --- src/nvim/spell.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'src/nvim/spell.c') diff --git a/src/nvim/spell.c b/src/nvim/spell.c index ab40355a8a..503657c427 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -2577,7 +2577,7 @@ static bool spell_iswordp(char_u *p, win_T *wp) int c; if (has_mbyte) { - l = MB_PTR2LEN(p); + l = utfc_ptr2len(p); s = p; if (l == 1) { // be quick for ASCII @@ -4118,7 +4118,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so && goodword_ends) { int l; - l = MB_PTR2LEN(fword + sp->ts_fidx); + l = utfc_ptr2len(fword + sp->ts_fidx); if (fword_ends) { // Copy the skipped character to preword. memmove(preword + sp->ts_prewordlen, @@ -4264,7 +4264,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so // Correct ts_fidx for the byte length of the // character (we didn't check that before). sp->ts_fidx = sp->ts_fcharstart - + MB_PTR2LEN(fword + sp->ts_fcharstart); + + utfc_ptr2len(fword + sp->ts_fcharstart); // For changing a composing character adjust // the score from SCORE_SUBST to @@ -4363,7 +4363,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so // a bit illogical for soundfold tree but it does give better // results. c = utf_ptr2char(fword + sp->ts_fidx); - stack[depth].ts_fidx += MB_PTR2LEN(fword + sp->ts_fidx); + stack[depth].ts_fidx += utfc_ptr2len(fword + sp->ts_fidx); if (utf_iscomposing(c)) { stack[depth].ts_score -= SCORE_DEL - SCORE_DELCOMP; } else if (c == utf_ptr2char(fword + stack[depth].ts_fidx)) { @@ -4533,9 +4533,9 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so case STATE_UNSWAP: // Undo the STATE_SWAP swap: "21" -> "12". p = fword + sp->ts_fidx; - n = MB_PTR2LEN(p); + n = utfc_ptr2len(p); c = utf_ptr2char(p + n); - memmove(p + MB_PTR2LEN(p + n), p, n); + memmove(p + utfc_ptr2len(p + n), p, n); utf_char2bytes(c, p); FALLTHROUGH; @@ -4589,11 +4589,11 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so case STATE_UNSWAP3: // Undo STATE_SWAP3: "321" -> "123" p = fword + sp->ts_fidx; - n = MB_PTR2LEN(p); + n = utfc_ptr2len(p); c2 = utf_ptr2char(p + n); - fl = MB_PTR2LEN(p + n); + fl = utfc_ptr2len(p + n); c = utf_ptr2char(p + n + fl); - tl = MB_PTR2LEN(p + n + fl); + tl = utfc_ptr2len(p + n + fl); memmove(p + fl + tl, p, n); utf_char2bytes(c, p); utf_char2bytes(c2, p + tl); @@ -4637,10 +4637,10 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so case STATE_UNROT3L: // Undo ROT3L: "231" -> "123" p = fword + sp->ts_fidx; - n = MB_PTR2LEN(p); - n += MB_PTR2LEN(p + n); + n = utfc_ptr2len(p); + n += utfc_ptr2len(p + n); c = utf_ptr2char(p + n); - tl = MB_PTR2LEN(p + n); + tl = utfc_ptr2len(p + n); memmove(p + tl, p, n); utf_char2bytes(c, p); @@ -4675,9 +4675,9 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so // Undo ROT3R: "312" -> "123" p = fword + sp->ts_fidx; c = utf_ptr2char(p); - tl = MB_PTR2LEN(p); - n = MB_PTR2LEN(p + tl); - n += MB_PTR2LEN(p + tl + n); + tl = utfc_ptr2len(p); + n = utfc_ptr2len(p + tl); + n += utfc_ptr2len(p + tl + n); memmove(p, p + tl, n); utf_char2bytes(c, p + n); -- cgit From 97cdfdcde24c6a804f879b6464512008db4b5cef Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sun, 6 Oct 2019 21:22:02 -0400 Subject: Remove dead code --- src/nvim/spell.c | 46 ++++++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 24 deletions(-) (limited to 'src/nvim/spell.c') diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 503657c427..a3c1746383 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -2570,36 +2570,33 @@ void init_spell_chartab(void) /// Thus this only works properly when past the first character of the word. /// /// @param wp Buffer used. -static bool spell_iswordp(char_u *p, win_T *wp) +static bool spell_iswordp(const char_u *p, const win_T *wp) + FUNC_ATTR_NONNULL_ALL { - char_u *s; - int l; int c; - if (has_mbyte) { - l = utfc_ptr2len(p); - s = p; - if (l == 1) { - // be quick for ASCII - if (wp->w_s->b_spell_ismw[*p]) - s = p + 1; // skip a mid-word character - } else { - c = utf_ptr2char(p); - if (c < 256 ? wp->w_s->b_spell_ismw[c] - : (wp->w_s->b_spell_ismw_mb != NULL - && vim_strchr(wp->w_s->b_spell_ismw_mb, c) != NULL)) { - s = p + l; - } + const int l = utfc_ptr2len(p); + const char_u *s = p; + if (l == 1) { + // be quick for ASCII + if (wp->w_s->b_spell_ismw[*p]) { + s = p + 1; // skip a mid-word character } - - c = utf_ptr2char(s); - if (c > 255) { - return spell_mb_isword_class(mb_get_class(s), wp); + } else { + c = utf_ptr2char(p); + if (c < 256 + ? wp->w_s->b_spell_ismw[c] + : (wp->w_s->b_spell_ismw_mb != NULL + && vim_strchr(wp->w_s->b_spell_ismw_mb, c) != NULL)) { + s = p + l; } - return spelltab.st_isw[c]; } - return spelltab.st_isw[wp->w_s->b_spell_ismw[*p] ? p[1] : p[0]]; + c = utf_ptr2char(s); + if (c > 255) { + return spell_mb_isword_class(mb_get_class(s), wp); + } + return spelltab.st_isw[c]; } // Returns true if "p" points to a word character. @@ -2617,7 +2614,8 @@ bool spell_iswordp_nmw(const char_u *p, win_T *wp) // Only for characters above 255. // Unicode subscript and superscript are not considered word characters. // See also utf_class() in mbyte.c. -static bool spell_mb_isword_class(int cl, win_T *wp) +static bool spell_mb_isword_class(int cl, const win_T *wp) + FUNC_ATTR_PURE FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT { if (wp->w_s->b_cjk) // East Asian characters are not considered word characters. -- cgit From 034077ed1c1fa71aa15829ed2dfb27de4a5e5359 Mon Sep 17 00:00:00 2001 From: Jaehwang Jerry Jung Date: Fri, 25 Oct 2019 19:54:53 +0900 Subject: vim-patch:8.1.2173: searchit() has too many arguments Problem: Searchit() has too many arguments. Solution: Move optional arguments to a struct. Add the "wrapped" argument. https://github.com/vim/vim/commit/92ea26b925a0835badb0af2d5887238a4198cabb --- src/nvim/spell.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/spell.c') diff --git a/src/nvim/spell.c b/src/nvim/spell.c index a3c1746383..687c86b4a8 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -3031,7 +3031,7 @@ void ex_spellrepall(exarg_T *eap) sub_nlines = 0; curwin->w_cursor.lnum = 0; while (!got_int) { - if (do_search(NULL, '/', frompat, 1L, SEARCH_KEEP, NULL, NULL) == 0 + if (do_search(NULL, '/', frompat, 1L, SEARCH_KEEP, NULL) == 0 || u_save_cursor() == FAIL) { break; } -- cgit From a0c18bf2017ac7d38d13014a810bda44d09dfcbb Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Wed, 13 Nov 2019 06:12:46 -0500 Subject: spell: fix clang logic error https://neovim.io/doc/reports/clang/report-487b01.html#EndPath https://neovim.io/doc/reports/clang/report-ce4c3c.html#EndPath --- src/nvim/spell.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/nvim/spell.c') diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 687c86b4a8..5feb7efda9 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -1910,11 +1910,11 @@ int init_syl_tab(slang_T *slang) // Count the number of syllables in "word". // When "word" contains spaces the syllables after the last space are counted. // Returns zero if syllables are not defines. -static int count_syllables(slang_T *slang, char_u *word) +static int count_syllables(slang_T *slang, const char_u *word) + FUNC_ATTR_NONNULL_ALL { int cnt = 0; bool skip = false; - char_u *p; int len; syl_item_T *syl; int c; @@ -1922,7 +1922,7 @@ static int count_syllables(slang_T *slang, char_u *word) if (slang->sl_syllable == NULL) return 0; - for (p = word; *p != NUL; p += len) { + for (const char_u *p = word; *p != NUL; p += len) { // When running into a space reset counter. if (*p == ' ') { len = 1; @@ -2625,9 +2625,10 @@ static bool spell_mb_isword_class(int cl, const win_T *wp) // Returns true if "p" points to a word character. // Wide version of spell_iswordp(). -static bool spell_iswordp_w(int *p, win_T *wp) +static bool spell_iswordp_w(const int *p, const win_T *wp) + FUNC_ATTR_NONNULL_ALL { - int *s; + const int *s; if (*p < 256 ? wp->w_s->b_spell_ismw[*p] : (wp->w_s->b_spell_ismw_mb != NULL -- cgit From 1042338c0062ea091ea1e52b161fd25adcdc927f Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Thu, 16 Jan 2020 00:10:16 -0500 Subject: clang/'Logic error': zero-init struct --- src/nvim/spell.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/spell.c') diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 5feb7efda9..96ae75718d 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -6145,8 +6145,8 @@ static void spell_soundfold_sal(slang_T *slang, char_u *inword, char_u *res) static void spell_soundfold_wsal(slang_T *slang, char_u *inword, char_u *res) { salitem_T *smp = (salitem_T *)slang->sl_sal.ga_data; - int word[MAXWLEN]; - int wres[MAXWLEN]; + int word[MAXWLEN] = { 0 }; + int wres[MAXWLEN] = { 0 }; int l; int *ws; int *pf; -- cgit From a7aa1fc87da0bd66b64afc39b5d6bf7c4c129986 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Thu, 16 Jan 2020 00:24:26 -0500 Subject: spell: spell_soundfold_sal() is dead code --- src/nvim/spell.c | 242 +------------------------------------------------------ 1 file changed, 1 insertion(+), 241 deletions(-) (limited to 'src/nvim/spell.c') diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 96ae75718d..c75a53a777 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -5835,10 +5835,7 @@ void spell_soundfold(slang_T *slang, char_u *inword, bool folded, char_u *res) word = fword; } - if (has_mbyte) - spell_soundfold_wsal(slang, word, res); - else - spell_soundfold_sal(slang, word, res); + spell_soundfold_wsal(slang, word, res); } } @@ -5903,243 +5900,6 @@ static void spell_soundfold_sofo(slang_T *slang, char_u *inword, char_u *res) res[ri] = NUL; } -static void spell_soundfold_sal(slang_T *slang, char_u *inword, char_u *res) -{ - salitem_T *smp; - char_u word[MAXWLEN]; - char_u *s = inword; - char_u *t; - char_u *pf; - int i, j, z; - int reslen; - int n, k = 0; - int z0; - int k0; - int n0; - int c; - int pri; - int p0 = -333; - int c0; - - // Remove accents, if wanted. We actually remove all non-word characters. - // But keep white space. We need a copy, the word may be changed here. - if (slang->sl_rem_accents) { - t = word; - while (*s != NUL) { - if (ascii_iswhite(*s)) { - *t++ = ' '; - s = skipwhite(s); - } else { - if (spell_iswordp_nmw(s, curwin)) - *t++ = *s; - ++s; - } - } - *t = NUL; - } else - STRLCPY(word, s, MAXWLEN); - - smp = (salitem_T *)slang->sl_sal.ga_data; - - // This comes from Aspell phonet.cpp. Converted from C++ to C. - // Changed to keep spaces. - i = reslen = z = 0; - while ((c = word[i]) != NUL) { - // Start with the first rule that has the character in the word. - n = slang->sl_sal_first[c]; - z0 = 0; - - if (n >= 0) { - // check all rules for the same letter - for (; (s = smp[n].sm_lead)[0] == c; ++n) { - // Quickly skip entries that don't match the word. Most - // entries are less then three chars, optimize for that. - k = smp[n].sm_leadlen; - if (k > 1) { - if (word[i + 1] != s[1]) - continue; - if (k > 2) { - for (j = 2; j < k; ++j) - if (word[i + j] != s[j]) - break; - if (j < k) - continue; - } - } - - if ((pf = smp[n].sm_oneof) != NULL) { - // Check for match with one of the chars in "sm_oneof". - while (*pf != NUL && *pf != word[i + k]) - ++pf; - if (*pf == NUL) - continue; - ++k; - } - s = smp[n].sm_rules; - pri = 5; // default priority - - p0 = *s; - k0 = k; - while (*s == '-' && k > 1) { - k--; - s++; - } - if (*s == '<') - s++; - if (ascii_isdigit(*s)) { - // determine priority - pri = *s - '0'; - s++; - } - if (*s == '^' && *(s + 1) == '^') - s++; - - if (*s == NUL - || (*s == '^' - && (i == 0 || !(word[i - 1] == ' ' - || spell_iswordp(word + i - 1, curwin))) - && (*(s + 1) != '$' - || (!spell_iswordp(word + i + k0, curwin)))) - || (*s == '$' && i > 0 - && spell_iswordp(word + i - 1, curwin) - && (!spell_iswordp(word + i + k0, curwin)))) { - // search for followup rules, if: - // followup and k > 1 and NO '-' in searchstring - c0 = word[i + k - 1]; - n0 = slang->sl_sal_first[c0]; - - if (slang->sl_followup && k > 1 && n0 >= 0 - && p0 != '-' && word[i + k] != NUL) { - // test follow-up rule for "word[i + k]" - for (; (s = smp[n0].sm_lead)[0] == c0; ++n0) { - // Quickly skip entries that don't match the word. - k0 = smp[n0].sm_leadlen; - if (k0 > 1) { - if (word[i + k] != s[1]) - continue; - if (k0 > 2) { - pf = word + i + k + 1; - for (j = 2; j < k0; ++j) - if (*pf++ != s[j]) - break; - if (j < k0) - continue; - } - } - k0 += k - 1; - - if ((pf = smp[n0].sm_oneof) != NULL) { - // Check for match with one of the chars in - // "sm_oneof". - while (*pf != NUL && *pf != word[i + k0]) - ++pf; - if (*pf == NUL) - continue; - ++k0; - } - - p0 = 5; - s = smp[n0].sm_rules; - while (*s == '-') { - // "k0" gets NOT reduced because - // "if (k0 == k)" - s++; - } - if (*s == '<') - s++; - if (ascii_isdigit(*s)) { - p0 = *s - '0'; - s++; - } - - if (*s == NUL - // *s == '^' cuts - || (*s == '$' - && !spell_iswordp(word + i + k0, - curwin))) { - if (k0 == k) - // this is just a piece of the string - continue; - - if (p0 < pri) - // priority too low - continue; - // rule fits; stop search - break; - } - } - - if (p0 >= pri && smp[n0].sm_lead[0] == c0) - continue; - } - - // replace string - s = smp[n].sm_to; - if (s == NULL) - s = (char_u *)""; - pf = smp[n].sm_rules; - p0 = (vim_strchr(pf, '<') != NULL) ? 1 : 0; - if (p0 == 1 && z == 0) { - // rule with '<' is used - if (reslen > 0 && *s != NUL && (res[reslen - 1] == c - || res[reslen - 1] == *s)) - reslen--; - z0 = 1; - z = 1; - k0 = 0; - while (*s != NUL && word[i + k0] != NUL) { - word[i + k0] = *s; - k0++; - s++; - } - if (k > k0) - STRMOVE(word + i + k0, word + i + k); - - // new "actual letter" - c = word[i]; - } else { - // no '<' rule used - i += k - 1; - z = 0; - while (*s != NUL && s[1] != NUL && reslen < MAXWLEN) { - if (reslen == 0 || res[reslen - 1] != *s) - res[reslen++] = *s; - s++; - } - // new "actual letter" - c = *s; - if (strstr((char *)pf, "^^") != NULL) { - if (c != NUL) - res[reslen++] = c; - STRMOVE(word, word + i + 1); - i = 0; - z0 = 1; - } - } - break; - } - } - } else if (ascii_iswhite(c)) { - c = ' '; - k = 1; - } - - if (z0 == 0) { - if (k && !p0 && reslen < MAXWLEN && c != NUL - && (!slang->sl_collapse || reslen == 0 - || res[reslen - 1] != c)) - // condense only double letters - res[reslen++] = c; - - i++; - z = 0; - k = 0; - } - } - - res[reslen] = NUL; -} - // Turn "inword" into its sound-a-like equivalent in "res[MAXWLEN]". // Multi-byte version of spell_soundfold(). static void spell_soundfold_wsal(slang_T *slang, char_u *inword, char_u *res) -- cgit From 6c7a995c5f585c507ac9aaced3ee859dbd8adab6 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sat, 25 Jan 2020 00:50:56 -0500 Subject: spell: zero-init structs to fix garbage ptrs --- src/nvim/spell.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/spell.c') diff --git a/src/nvim/spell.c b/src/nvim/spell.c index c75a53a777..48c3d42baa 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -848,7 +848,7 @@ static void find_word(matchinf_T *mip, int mode) mip->mi_compflags[mip->mi_complen] = ((unsigned)flags >> 24); mip->mi_compflags[mip->mi_complen + 1] = NUL; if (word_ends) { - char_u fword[MAXWLEN]; + char_u fword[MAXWLEN] = { 0 }; if (slang->sl_compsylmax < MAXWLEN) { // "fword" is only needed for checking syllables. @@ -3603,7 +3603,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so { char_u tword[MAXWLEN]; // good word collected so far trystate_T stack[MAXWLEN]; - char_u preword[MAXWLEN * 3]; // word found with proper case; + char_u preword[MAXWLEN * 3] = { 0 }; // word found with proper case; // concatenation of prefix compound // words and split word. NUL terminated // when going deeper but not when coming -- cgit From 86c1630a1b63d5f5e0eac9235459ec8da10b47ba Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sat, 25 Jan 2020 01:00:20 -0500 Subject: spell: remove enc_utf8 dead code --- src/nvim/spell.c | 43 +++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 22 deletions(-) (limited to 'src/nvim/spell.c') diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 48c3d42baa..5559556489 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -1026,26 +1026,25 @@ match_checkcompoundpattern ( // Returns true if "flags" is a valid sequence of compound flags and "word" // does not have too many syllables. -static bool can_compound(slang_T *slang, char_u *word, char_u *flags) +static bool can_compound(slang_T *slang, const char_u *word, + const char_u *flags) + FUNC_ATTR_NONNULL_ALL { - char_u uflags[MAXWLEN * 2]; - int i; - char_u *p; + char_u uflags[MAXWLEN * 2] = { 0 }; - if (slang->sl_compprog == NULL) + if (slang->sl_compprog == NULL) { return false; - if (enc_utf8) { - // Need to convert the single byte flags to utf8 characters. - p = uflags; - for (i = 0; flags[i] != NUL; i++) { - p += utf_char2bytes(flags[i], p); - } - *p = NUL; - p = uflags; - } else - p = flags; - if (!vim_regexec_prog(&slang->sl_compprog, false, p, 0)) + } + // Need to convert the single byte flags to utf8 characters. + char_u *p = uflags; + for (int i = 0; flags[i] != NUL; i++) { + p += utf_char2bytes(flags[i], p); + } + *p = NUL; + p = uflags; + if (!vim_regexec_prog(&slang->sl_compprog, false, p, 0)) { return false; + } // Count the number of syllables. This may be slow, do it last. If there // are too many syllables AND the number of compound words is above @@ -4268,9 +4267,8 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so // For changing a composing character adjust // the score from SCORE_SUBST to // SCORE_SUBCOMP. - if (enc_utf8 - && utf_iscomposing(utf_ptr2char(tword + sp->ts_twordlen - - sp->ts_tcharlen)) + if (utf_iscomposing(utf_ptr2char(tword + sp->ts_twordlen + - sp->ts_tcharlen)) && utf_iscomposing(utf_ptr2char(fword + sp->ts_fcharstart))) { sp->ts_score -= SCORE_SUBST - SCORE_SUBCOMP; @@ -5855,7 +5853,7 @@ static void spell_soundfold_sofo(slang_T *slang, char_u *inword, char_u *res) // 255, sl_sal the rest. for (s = inword; *s != NUL; ) { c = mb_cptr2char_adv((const char_u **)&s); - if (enc_utf8 ? utf_class(c) == 0 : ascii_iswhite(c)) { + if (utf_class(c) == 0) { c = ' '; } else if (c < 256) { c = slang->sl_sal_first[c]; @@ -5932,9 +5930,10 @@ static void spell_soundfold_wsal(slang_T *slang, char_u *inword, char_u *res) const char_u *t = s; c = mb_cptr2char_adv((const char_u **)&s); if (slang->sl_rem_accents) { - if (enc_utf8 ? utf_class(c) == 0 : ascii_iswhite(c)) { - if (did_white) + if (utf_class(c) == 0) { + if (did_white) { continue; + } c = ' '; did_white = true; } else { -- cgit From 08c5a874ab97d52e215025ccd010d68fcdf14731 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sun, 26 Jan 2020 08:17:08 -0500 Subject: vim-patch:8.1.1143: may pass weird strings to file name expansion Problem: May pass weird strings to file name expansion. Solution: Check for matching characters. Disallow control characters. https://github.com/vim/vim/commit/8f130eda4747e4a4d68353cdb650f359fd01469b --- src/nvim/spell.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/nvim/spell.c') diff --git a/src/nvim/spell.c b/src/nvim/spell.c index c75a53a777..a221f3fd75 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -2008,6 +2008,10 @@ char_u *did_set_spelllang(win_T *wp) region = NULL; len = (int)STRLEN(lang); + if (!valid_spellang(lang)) { + continue; + } + if (STRCMP(lang, "cjk") == 0) { wp->w_s->b_cjk = 1; continue; -- cgit From 351a1cff70a2e2294adb4a90ff35cea38c2accec Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sun, 15 Mar 2020 14:50:36 -0400 Subject: vim-patch:8.2.0387: error for possible NULL argument to qsort() Problem: Error for possible NULL argument to qsort(). Solution: Don't call qsort() when there is nothing to sort. (Dominique Pelle, closes vim/vim#5780) https://github.com/vim/vim/commit/bb65a5690c24ccfce37e210316bf1d0964c91359 --- src/nvim/spell.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'src/nvim/spell.c') diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 6cb8d01f51..545a381bd3 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -5761,19 +5761,22 @@ cleanup_suggestions ( int maxscore, int keep // nr of suggestions to keep ) + FUNC_ATTR_NONNULL_ALL { suggest_T *stp = &SUG(*gap, 0); - // Sort the list. - qsort(gap->ga_data, (size_t)gap->ga_len, sizeof(suggest_T), sug_compare); + if (gap->ga_len > 0) { + // Sort the list. + qsort(gap->ga_data, (size_t)gap->ga_len, sizeof(suggest_T), sug_compare); - // Truncate the list to the number of suggestions that will be displayed. - if (gap->ga_len > keep) { - for (int i = keep; i < gap->ga_len; ++i) { - xfree(stp[i].st_word); + // Truncate the list to the number of suggestions that will be displayed. + if (gap->ga_len > keep) { + for (int i = keep; i < gap->ga_len; i++) { + xfree(stp[i].st_word); + } + gap->ga_len = keep; + return stp[keep - 1].st_score; } - gap->ga_len = keep; - return stp[keep - 1].st_score; } return maxscore; } -- cgit From 5be72756f87f9ecf8931b9c4ff192a5aae4edadd Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sun, 15 Mar 2020 23:26:05 -0400 Subject: vim-patch:8.2.0041: leaking memory when selecting spell suggestion Problem: Leaking memory when selecting spell suggestion. Solution: Free previous value at the right time. https://github.com/vim/vim/commit/6c52f8237199ea09abbecdc5b89847c5889c3de1 --- src/nvim/spell.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/spell.c') diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 545a381bd3..180073ade1 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -2827,9 +2827,6 @@ void spell_suggest(int count) smsg(_("Sorry, only %" PRId64 " suggestions"), (int64_t)sug.su_ga.ga_len); } else { - XFREE_CLEAR(repl_from); - XFREE_CLEAR(repl_to); - // When 'rightleft' is set the list is drawn right-left. cmdmsg_rl = curwin->w_p_rl; if (cmdmsg_rl) @@ -2909,6 +2906,9 @@ void spell_suggest(int count) if (selected > 0 && selected <= sug.su_ga.ga_len && u_save_cursor() == OK) { // Save the from and to text for :spellrepall. + XFREE_CLEAR(repl_from); + XFREE_CLEAR(repl_to); + stp = &SUG(sug.su_ga, selected - 1); if (sug.su_badlen > stp->st_orglen) { // Replacing less than "su_badlen", append the remainder to -- cgit From ee4265285d517d30caee2581accbc656119b019f Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Mon, 8 Jun 2020 19:52:24 -0400 Subject: vim-patch:8.2.0932: missspelling spelllang Problem: Missspelling spelllang. Solution: Add an "l". (Dominique Pelle) https://github.com/vim/vim/commit/f154f3ab2c1eea67afc20140c580ad003752dc72 --- src/nvim/spell.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/spell.c') diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 180073ade1..4d8da1ba14 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -2007,7 +2007,7 @@ char_u *did_set_spelllang(win_T *wp) region = NULL; len = (int)STRLEN(lang); - if (!valid_spellang(lang)) { + if (!valid_spelllang(lang)) { continue; } -- cgit From e84c075ad9a8ce1bf5182bd0d4993cd2304cf9e1 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Tue, 30 Jun 2020 00:11:18 -0400 Subject: vim-patch:8.2.1095: may use pointer after freeing it Problem: May use pointer after freeing it when text properties are used. Solution: Update redo buffer before calling ml_replace(). https://github.com/vim/vim/commit/6b949615edac2dd33d5e865be8328561f296b045 --- src/nvim/spell.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/nvim/spell.c') diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 4d8da1ba14..df29124dea 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -2930,8 +2930,6 @@ void spell_suggest(int count) memmove(p, line, c); STRCPY(p + c, stp->st_word); STRCAT(p, sug.su_badptr + stp->st_orglen); - ml_replace(curwin->w_cursor.lnum, p, false); - curwin->w_cursor.col = c; // For redo we use a change-word command. ResetRedobuff(); @@ -2940,7 +2938,10 @@ void spell_suggest(int count) stp->st_wordlen + sug.su_badlen - stp->st_orglen); AppendCharToRedobuff(ESC); - // After this "p" may be invalid. + // "p" may be freed here + ml_replace(curwin->w_cursor.lnum, p, false); + curwin->w_cursor.col = c; + changed_bytes(curwin->w_cursor.lnum, c); } else curwin->w_cursor = prev_cursor; -- cgit From 37bc089fb9953bf4a82a8a6eaf60fb2f6cea0784 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Wed, 1 Jul 2020 23:47:48 -0400 Subject: vim-patch:8.2.1104: Coverity warnts for possible NULL pointer use Problem: Coverity warnts for possible NULL pointer use. Solution: Check "pbyts" is not NULL. https://github.com/vim/vim/commit/11b6600c88165c70d9ccbbdd4d9c96e8266e365f --- src/nvim/spell.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/nvim/spell.c') diff --git a/src/nvim/spell.c b/src/nvim/spell.c index df29124dea..95948dac78 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -3762,7 +3762,8 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so tword[sp->ts_twordlen] = NUL; if (sp->ts_prefixdepth <= PFD_NOTSPECIAL - && (sp->ts_flags & TSF_PREFIXOK) == 0) { + && (sp->ts_flags & TSF_PREFIXOK) == 0 + && pbyts != NULL) { // There was a prefix before the word. Check that the prefix // can be used with this word. // Count the length of the NULs in the prefix. If there are -- cgit