aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/spell.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/spell.c')
-rw-r--r--src/nvim/spell.c40
1 files changed, 21 insertions, 19 deletions
diff --git a/src/nvim/spell.c b/src/nvim/spell.c
index e4805f3c4a..2aadc2258e 100644
--- a/src/nvim/spell.c
+++ b/src/nvim/spell.c
@@ -504,7 +504,7 @@ size_t spell_check(win_T *wp, char_u *ptr, hlf_T *attrp, int *capcol, bool docou
// Check for end of sentence.
regmatch.regprog = wp->w_s->b_cap_prog;
regmatch.rm_ic = false;
- int r = vim_regexec(&regmatch, ptr, 0);
+ int r = vim_regexec(&regmatch, (char *)ptr, 0);
wp->w_s->b_cap_prog = regmatch.regprog;
if (r) {
*capcol = (int)(regmatch.endp[0] - ptr);
@@ -1469,7 +1469,9 @@ size_t spell_move_to(win_T *wp, int dir, bool allwords, bool curline, hlf_T *att
}
// Copy the line into "buf" and append the start of the next line if
- // possible.
+ // possible. Note: this ml_get_buf() may make "line" invalid, check
+ // for empty line first.
+ bool empty_line = *skipwhite((const char *)line) == NUL;
STRCPY(buf, line);
if (lnum < wp->w_buffer->b_ml.ml_line_count) {
spell_cat_line(buf + STRLEN(buf),
@@ -1613,7 +1615,7 @@ size_t spell_move_to(win_T *wp, int dir, bool allwords, bool curline, hlf_T *att
--capcol;
// But after empty line check first word in next line
- if (*skipwhite((char *)line) == NUL) {
+ if (empty_line) {
capcol = 0;
}
}
@@ -1908,12 +1910,11 @@ void count_common_word(slang_T *lp, char_u *word, int len, int count)
/// @param split word was split, less bonus
static int score_wordcount_adj(slang_T *slang, int score, char_u *word, bool split)
{
- hashitem_T *hi;
wordcount_T *wc;
int bonus;
int newscore;
- hi = hash_find(&slang->sl_wordcount, word);
+ hashitem_T *hi = hash_find(&slang->sl_wordcount, (char *)word);
if (!HASHITEM_EMPTY(hi)) {
wc = HI2WC(hi);
if (wc->wc_count < SCORE_THRES2) {
@@ -2083,7 +2084,7 @@ char *did_set_spelllang(win_T *wp)
// Loop over comma separated language names.
for (splp = spl_copy; *splp != NUL;) {
// Get one language name.
- copy_option_part(&splp, lang, MAXWLEN, ",");
+ copy_option_part((char **)&splp, (char *)lang, MAXWLEN, ",");
region = NULL;
len = (int)STRLEN(lang);
@@ -2215,7 +2216,7 @@ char *did_set_spelllang(win_T *wp)
int_wordlist_spl(spf_name);
} else {
// One entry in 'spellfile'.
- copy_option_part(&spf, spf_name, MAXPATHL - 5, ",");
+ copy_option_part((char **)&spf, (char *)spf_name, MAXPATHL - 5, ",");
STRCAT(spf_name, ".spl");
// If it was already found above then skip it.
@@ -2328,11 +2329,11 @@ char *did_set_spelllang(win_T *wp)
}
}
}
+ redraw_later(wp, NOT_VALID);
theend:
xfree(spl_copy);
recursive = false;
- redraw_later(wp, NOT_VALID);
return ret_msg;
}
@@ -2805,12 +2806,12 @@ int spell_check_sps(void)
sps_limit = 9999;
for (p = p_sps; *p != NUL;) {
- copy_option_part(&p, buf, MAXPATHL, ",");
+ copy_option_part((char **)&p, (char *)buf, MAXPATHL, ",");
f = 0;
if (ascii_isdigit(*buf)) {
s = buf;
- sps_limit = getdigits_int(&s, true, 0);
+ sps_limit = getdigits_int((char **)&s, true, 0);
if (*s != NUL && !ascii_isdigit(*s)) {
f = -1;
}
@@ -3121,7 +3122,7 @@ static bool check_need_cap(linenr_T lnum, colnr_T col)
if (p == line || spell_iswordp_nmw(p, curwin)) {
break;
}
- if (vim_regexec(&regmatch, p, 0)
+ if (vim_regexec(&regmatch, (char *)p, 0)
&& regmatch.endp[0] == line + endcol) {
need_cap = true;
break;
@@ -3328,7 +3329,7 @@ static void spell_find_suggest(char_u *badptr, int badlen, suginfo_T *su, int ma
// Loop over the items in 'spellsuggest'.
for (p = sps_copy; *p != NUL;) {
- copy_option_part(&p, buf, MAXPATHL, ",");
+ copy_option_part((char **)&p, (char *)buf, MAXPATHL, ",");
if (STRNCMP(buf, "expr:", 5) == 0) {
// Evaluate an expression. Skip this when called recursively,
@@ -4034,8 +4035,8 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
break;
}
if ((sp->ts_complen == sp->ts_compsplit
- && WAS_BANNED(su, preword + sp->ts_prewordlen))
- || WAS_BANNED(su, preword)) {
+ && WAS_BANNED(su, (char *)preword + sp->ts_prewordlen))
+ || WAS_BANNED(su, (char *)preword)) {
if (slang->sl_compprog == NULL) {
break;
}
@@ -5661,7 +5662,7 @@ static bool similar_chars(slang_T *slang, int c1, int c2)
if (c1 >= 256) {
buf[utf_char2bytes(c1, (char *)buf)] = 0;
- hi = hash_find(&slang->sl_map_hash, (char_u *)buf);
+ hi = hash_find(&slang->sl_map_hash, buf);
if (HASHITEM_EMPTY(hi)) {
m1 = 0;
} else {
@@ -5676,7 +5677,7 @@ static bool similar_chars(slang_T *slang, int c1, int c2)
if (c2 >= 256) {
buf[utf_char2bytes(c2, (char *)buf)] = 0;
- hi = hash_find(&slang->sl_map_hash, (char_u *)buf);
+ hi = hash_find(&slang->sl_map_hash, buf);
if (HASHITEM_EMPTY(hi)) {
m2 = 0;
} else {
@@ -7022,8 +7023,9 @@ void spell_dump_compl(char_u *pat, int ic, Direction *dir, int dumpflags_arg)
n = arridx[depth] + curi[depth];
++curi[depth];
c = byts[n];
- if (c == 0) {
- // End of word, deal with the word.
+ if (c == 0 || depth >= MAXWLEN - 1) {
+ // End of word or reached maximum length, deal with the
+ // word.
// Don't use keep-case words in the fold-case tree,
// they will appear in the keep-case tree.
// Only use the word when the region matches.
@@ -7144,7 +7146,7 @@ static void dump_word(slang_T *slang, char_u *word, char_u *pat, Direction *dir,
hashitem_T *hi;
// Include the word count for ":spelldump!".
- hi = hash_find(&slang->sl_wordcount, tw);
+ hi = hash_find(&slang->sl_wordcount, (char *)tw);
if (!HASHITEM_EMPTY(hi)) {
vim_snprintf((char *)IObuff, IOSIZE, "%s\t%d",
tw, HI2WC(hi)->wc_count);