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.c115
1 files changed, 47 insertions, 68 deletions
diff --git a/src/nvim/spell.c b/src/nvim/spell.c
index 6b229f7498..1fe957d17c 100644
--- a/src/nvim/spell.c
+++ b/src/nvim/spell.c
@@ -2010,7 +2010,7 @@ spell_move_to (
if (buflen < len + MAXWLEN + 2) {
free(buf);
buflen = len + MAXWLEN + 2;
- buf = alloc(buflen);
+ buf = xmalloc(buflen);
}
// In first line check first word for Capital.
@@ -2479,8 +2479,6 @@ spell_load_file (
// Remember the file name, used to reload the file when it's updated.
lp->sl_fname = vim_strsave(fname);
- if (lp->sl_fname == NULL)
- goto endFAIL;
// Check for .add.spl.
lp->sl_add = strstr((char *)path_tail(fname), SPL_FNAME_ADD) != NULL;
@@ -2856,7 +2854,7 @@ static int read_sal_section(FILE *fd, slang_T *slang)
ccnt = getc(fd); // <salfromlen>
if (ccnt < 0)
return SP_TRUNCERROR;
- p = alloc(ccnt + 2);
+ p = xmalloc(ccnt + 2);
smp->sm_lead = p;
// Read up to the first special char into sm_lead.
@@ -2919,7 +2917,7 @@ static int read_sal_section(FILE *fd, slang_T *slang)
// Add one extra entry to mark the end with an empty sm_lead. Avoids
// that we need to check the index every time.
smp = &((salitem_T *)gap->ga_data)[gap->ga_len];
- p = alloc(1);
+ p = xmalloc(1);
p[0] = NUL;
smp->sm_lead = p;
smp->sm_leadlen = 0;
@@ -2996,7 +2994,7 @@ count_common_word (
hash = hash_hash(p);
hi = hash_lookup(&lp->sl_wordcount, p, hash);
if (HASHITEM_EMPTY(hi)) {
- wc = (wordcount_T *)alloc((unsigned)(sizeof(wordcount_T) + STRLEN(p)));
+ wc = xmalloc(sizeof(wordcount_T) + STRLEN(p));
STRCPY(wc->wc_word, p);
wc->wc_count = count;
hash_add_item(&lp->sl_wordcount, hi, wc->wc_word, hash);
@@ -3146,22 +3144,22 @@ static int read_compound(FILE *fd, slang_T *slang, int len)
c = todo * 2 + 7;
if (enc_utf8)
c += todo * 2;
- pat = alloc((unsigned)c);
+ pat = xmalloc(c);
// We also need a list of all flags that can appear at the start and one
// for all flags.
- cp = alloc(todo + 1);
+ cp = xmalloc(todo + 1);
slang->sl_compstartflags = cp;
*cp = NUL;
- ap = alloc(todo + 1);
+ ap = xmalloc(todo + 1);
slang->sl_compallflags = ap;
*ap = NUL;
// And a list of all patterns in their original form, for checking whether
// compounding may work in match_compoundrule(). This is freed when we
// encounter a wildcard, the check doesn't work then.
- crp = alloc(todo + 1);
+ crp = xmalloc(todo + 1);
slang->sl_comprules = crp;
pp = pat;
@@ -3378,7 +3376,7 @@ static int set_sofo(slang_T *lp, char_u *from, char_u *to)
// Allocate the lists.
for (i = 0; i < 256; ++i)
if (lp->sl_sal_first[i] > 0) {
- p = alloc(sizeof(int) * (lp->sl_sal_first[i] * 2 + 1));
+ p = xmalloc(sizeof(int) * (lp->sl_sal_first[i] * 2 + 1));
((int **)gap->ga_data)[i] = (int *)p;
*(int *)p = 0;
}
@@ -3669,8 +3667,6 @@ char_u *did_set_spelllang(win_T *wp)
// Make a copy of 'spelllang', the SpellFileMissing autocommands may change
// it under our fingers.
spl_copy = vim_strsave(wp->w_s->b_p_spl);
- if (spl_copy == NULL)
- goto theend;
wp->w_s->b_cjk = 0;
@@ -3936,11 +3932,9 @@ static void use_midword(slang_T *lp, win_T *wp)
// Append multi-byte chars to "b_spell_ismw_mb".
n = (int)STRLEN(wp->w_s->b_spell_ismw_mb);
bp = vim_strnsave(wp->w_s->b_spell_ismw_mb, n + l);
- if (bp != NULL) {
- free(wp->w_s->b_spell_ismw_mb);
- wp->w_s->b_spell_ismw_mb = bp;
- vim_strncpy(bp + n, p, l);
- }
+ free(wp->w_s->b_spell_ismw_mb);
+ wp->w_s->b_spell_ismw_mb = bp;
+ vim_strncpy(bp + n, p, l);
}
p += l;
} else
@@ -5175,8 +5169,6 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname)
if (HASHITEM_EMPTY(hash_find(&spin->si_commonwords,
items[i]))) {
p = vim_strsave(items[i]);
- if (p == NULL)
- break;
hash_add(&spin->si_commonwords, p);
}
}
@@ -7382,7 +7374,7 @@ static void spell_make_sugfile(spellinfo_T *spin, char_u *wfname)
// Write the .sug file.
// Make the file name by changing ".spl" to ".sug".
- fname = alloc(MAXPATHL);
+ fname = xmalloc(MAXPATHL);
vim_strncpy(fname, wfname, MAXPATHL - 1);
len = (int)STRLEN(fname);
fname[len - 2] = 'u';
@@ -7789,7 +7781,7 @@ mkspell (
innames = &fnames[1];
incount = fcount - 1;
- wfname = alloc(MAXPATHL);
+ wfname = xmalloc(MAXPATHL);
if (fcount >= 1) {
len = (int)STRLEN(fnames[0]);
@@ -7840,7 +7832,7 @@ mkspell (
goto theend;
}
- fname = alloc(MAXPATHL);
+ fname = xmalloc(MAXPATHL);
// Init the aff and dic pointers.
// Get the region names if there are more than 2 arguments.
@@ -8032,7 +8024,7 @@ spell_add_word (
EMSG2(_(e_notset), "spellfile");
return;
}
- fnamebuf = alloc(MAXPATHL);
+ fnamebuf = xmalloc(MAXPATHL);
for (spf = curwin->w_s->b_p_spf, i = 1; *spf != NUL; ++i) {
copy_option_part(&spf, fnamebuf, MAXPATHL, ",");
@@ -8151,7 +8143,7 @@ static void init_spellfile(void)
char_u *lstart = curbuf->b_s.b_p_spl;
if (*curwin->w_s->b_p_spl != NUL && !GA_EMPTY(&curwin->w_s->b_langp)) {
- buf = alloc(MAXPATHL);
+ buf = xmalloc(MAXPATHL);
// Find the end of the language name. Exclude the region. If there
// is a path separator remember the start of the tail.
@@ -8678,8 +8670,6 @@ void spell_suggest(int count)
// Make a copy of current line since autocommands may free the line.
line = vim_strsave(ml_get_curline());
- if (line == NULL)
- goto skip;
// Get the list of suggestions. Limit to 'lines' - 2 or the number in
// 'spellsuggest', whatever is smaller.
@@ -8796,8 +8786,7 @@ void spell_suggest(int count)
}
// Replace the word.
- p = alloc((unsigned)STRLEN(line) - stp->st_orglen
- + stp->st_wordlen + 1);
+ p = xmalloc(STRLEN(line) - stp->st_orglen + stp->st_wordlen + 1);
c = (int)(sug.su_badptr - line);
memmove(p, line, c);
STRCPY(p + c, stp->st_word);
@@ -8818,8 +8807,6 @@ void spell_suggest(int count)
curwin->w_cursor = prev_cursor;
spell_find_cleanup(&sug);
-skip:
- free(line);
}
// Check if the word at line "lnum" column "col" is required to start with a
@@ -8897,7 +8884,7 @@ void ex_spellrepall(exarg_T *eap)
}
addlen = (int)(STRLEN(repl_to) - STRLEN(repl_from));
- frompat = alloc((unsigned)STRLEN(repl_from) + 7);
+ frompat = xmalloc(STRLEN(repl_from) + 7);
sprintf((char *)frompat, "\\V\\<%s\\>", repl_from);
p_ws = FALSE;
@@ -8914,7 +8901,7 @@ void ex_spellrepall(exarg_T *eap)
line = ml_get_curline();
if (addlen <= 0 || STRNCMP(line + curwin->w_cursor.col,
repl_to, STRLEN(repl_to)) != 0) {
- p = alloc((unsigned)STRLEN(line) + addlen + 1);
+ p = xmalloc(STRLEN(line) + addlen + 1);
memmove(p, line, curwin->w_cursor.col);
STRCPY(p + curwin->w_cursor.col, repl_to);
STRCAT(p, line + curwin->w_cursor.col + STRLEN(repl_from));
@@ -8966,8 +8953,8 @@ spell_suggest_list (
// The suggested word may replace only part of "word", add the not
// replaced part.
- wcopy = alloc(stp->st_wordlen
- + (unsigned)STRLEN(sug.su_badptr + stp->st_orglen) + 1);
+ wcopy = xmalloc(stp->st_wordlen
+ + STRLEN(sug.su_badptr + stp->st_orglen) + 1);
STRCPY(wcopy, stp->st_word);
STRCPY(wcopy + stp->st_wordlen, sug.su_badptr + stp->st_orglen);
((char_u **)gap->ga_data)[gap->ga_len++] = wcopy;
@@ -9063,8 +9050,6 @@ spell_find_suggest (
// Make a copy of 'spellsuggest', because the expression may change it.
sps_copy = vim_strsave(p_sps);
- if (sps_copy == NULL)
- return;
// Loop over the items in 'spellsuggest'.
for (p = sps_copy; *p != NUL; ) {
@@ -11024,13 +11009,11 @@ static void score_comp_sal(suginfo_T *su)
// Add the suggestion.
sstp = &SUG(su->su_sga, su->su_sga.ga_len);
sstp->st_word = vim_strsave(stp->st_word);
- if (sstp->st_word != NULL) {
- sstp->st_wordlen = stp->st_wordlen;
- sstp->st_score = score;
- sstp->st_altscore = 0;
- sstp->st_orglen = stp->st_orglen;
- ++su->su_sga.ga_len;
- }
+ sstp->st_wordlen = stp->st_wordlen;
+ sstp->st_score = score;
+ sstp->st_altscore = 0;
+ sstp->st_orglen = stp->st_orglen;
+ ++su->su_sga.ga_len;
}
}
break;
@@ -11313,8 +11296,7 @@ add_sound_suggest (
hash = hash_hash(goodword);
hi = hash_lookup(&slang->sl_sounddone, goodword, hash);
if (HASHITEM_EMPTY(hi)) {
- sft = (sftword_T *)alloc((unsigned)(sizeof(sftword_T)
- + STRLEN(goodword)));
+ sft = xmalloc(sizeof(sftword_T) + STRLEN(goodword));
sft->sft_score = score;
STRCPY(sft->sft_word, goodword);
hash_add_item(&slang->sl_sounddone, hi, sft->sft_word, hash);
@@ -11578,7 +11560,7 @@ static void set_map_str(slang_T *lp, char_u *map)
hash_T hash;
hashitem_T *hi;
- b = alloc((unsigned)(cl + headcl + 2));
+ b = xmalloc(cl + headcl + 2);
mb_char2bytes(c, b);
b[cl] = NUL;
mb_char2bytes(headc, b + cl + 1);
@@ -11730,25 +11712,23 @@ add_suggestion (
// Add a suggestion.
stp = &SUG(*gap, gap->ga_len);
stp->st_word = vim_strnsave(goodword, goodlen);
- if (stp->st_word != NULL) {
- stp->st_wordlen = goodlen;
- stp->st_score = score;
- stp->st_altscore = altscore;
- stp->st_had_bonus = had_bonus;
- stp->st_orglen = badlen;
- stp->st_slang = slang;
- ++gap->ga_len;
-
- // If we have too many suggestions now, sort the list and keep
- // the best suggestions.
- if (gap->ga_len > SUG_MAX_COUNT(su)) {
- if (maxsf)
- su->su_sfmaxscore = cleanup_suggestions(gap,
- su->su_sfmaxscore, SUG_CLEAN_COUNT(su));
- else
- su->su_maxscore = cleanup_suggestions(gap,
- su->su_maxscore, SUG_CLEAN_COUNT(su));
- }
+ stp->st_wordlen = goodlen;
+ stp->st_score = score;
+ stp->st_altscore = altscore;
+ stp->st_had_bonus = had_bonus;
+ stp->st_orglen = badlen;
+ stp->st_slang = slang;
+ ++gap->ga_len;
+
+ // If we have too many suggestions now, sort the list and keep
+ // the best suggestions.
+ if (gap->ga_len > SUG_MAX_COUNT(su)) {
+ if (maxsf)
+ su->su_sfmaxscore = cleanup_suggestions(gap,
+ su->su_sfmaxscore, SUG_CLEAN_COUNT(su));
+ else
+ su->su_maxscore = cleanup_suggestions(gap,
+ su->su_maxscore, SUG_CLEAN_COUNT(su));
}
}
}
@@ -11799,8 +11779,7 @@ static void add_banned(suginfo_T *su, char_u *word)
hi = hash_lookup(&su->su_banned, word, hash);
if (HASHITEM_EMPTY(hi)) {
s = vim_strsave(word);
- if (s != NULL)
- hash_add_item(&su->su_banned, hi, s, hash);
+ hash_add_item(&su->su_banned, hi, s, hash);
}
}