Remove NULL/non-NULL tests after calls to vim_str(n)save()

This commit is contained in:
Felipe Oliveira Carvalho 2014-05-08 21:34:46 -03:00
parent b63d2626ed
commit a80d7e86c1
34 changed files with 337 additions and 683 deletions

View File

@ -2237,9 +2237,8 @@ setfname (
close_buffer(NULL, obuf, DOBUF_WIPE, FALSE); close_buffer(NULL, obuf, DOBUF_WIPE, FALSE);
} }
sfname = vim_strsave(sfname); sfname = vim_strsave(sfname);
if (ffname == NULL || sfname == NULL) { if (ffname == NULL) {
free(sfname); free(sfname);
free(ffname);
return FAIL; return FAIL;
} }
#ifdef USE_FNAME_CASE #ifdef USE_FNAME_CASE
@ -4116,8 +4115,6 @@ chk_modeline (
while (s[-1] != ':'); while (s[-1] != ':');
s = linecopy = vim_strsave(s); /* copy the line, it will change */ s = linecopy = vim_strsave(s); /* copy the line, it will change */
if (linecopy == NULL)
return FAIL;
save_sourcing_lnum = sourcing_lnum; save_sourcing_lnum = sourcing_lnum;
save_sourcing_name = sourcing_name; save_sourcing_name = sourcing_name;

View File

@ -1911,9 +1911,6 @@ void backslash_halve(char_u *p)
char_u* backslash_halve_save(char_u *p) char_u* backslash_halve_save(char_u *p)
{ {
char_u *res = vim_strsave(p); char_u *res = vim_strsave(p);
if (res == NULL) {
return p;
}
backslash_halve(res); backslash_halve(res);
return res; return res;
} }

View File

@ -519,10 +519,6 @@ static void diff_check_unchanged(tabpage_T *tp, diff_T *dp)
dp->df_lnum[i_org] + off_org, dp->df_lnum[i_org] + off_org,
FALSE)); FALSE));
if (line_org == NULL) {
return;
}
int i_new; int i_new;
for (i_new = i_org + 1; i_new < DB_COUNT; ++i_new) { for (i_new = i_org + 1; i_new < DB_COUNT; ++i_new) {
if (tp->tp_diffbuf[i_new] == NULL) { if (tp->tp_diffbuf[i_new] == NULL) {
@ -972,10 +968,7 @@ void ex_diffpatch(exarg_T *eap)
if (curbuf->b_fname != NULL) { if (curbuf->b_fname != NULL) {
newname = vim_strnsave(curbuf->b_fname, newname = vim_strnsave(curbuf->b_fname,
(int)(STRLEN(curbuf->b_fname) + 4)); (int)(STRLEN(curbuf->b_fname) + 4));
STRCAT(newname, ".new");
if (newname != NULL) {
STRCAT(newname, ".new");
}
} }
// don't use a new tab page, each tab page has its own diffs // don't use a new tab page, each tab page has its own diffs
@ -1580,9 +1573,6 @@ static int diff_equal_entry(diff_T *dp, int idx1, int idx2)
char_u *line = vim_strsave(ml_get_buf(curtab->tp_diffbuf[idx1], char_u *line = vim_strsave(ml_get_buf(curtab->tp_diffbuf[idx1],
dp->df_lnum[idx1] + i, FALSE)); dp->df_lnum[idx1] + i, FALSE));
if (line == NULL) {
return FALSE;
}
int cmp = diff_cmp(line, ml_get_buf(curtab->tp_diffbuf[idx2], int cmp = diff_cmp(line, ml_get_buf(curtab->tp_diffbuf[idx2],
dp->df_lnum[idx2] + i, FALSE)); dp->df_lnum[idx2] + i, FALSE));
free(line); free(line);
@ -1886,9 +1876,6 @@ int diff_find_change(win_T *wp, linenr_T lnum, int *startp, int *endp)
// Make a copy of the line, the next ml_get() will invalidate it. // Make a copy of the line, the next ml_get() will invalidate it.
char_u *line_org = vim_strsave(ml_get_buf(wp->w_buffer, lnum, FALSE)); char_u *line_org = vim_strsave(ml_get_buf(wp->w_buffer, lnum, FALSE));
if (line_org == NULL) {
return FALSE;
}
int idx = diff_buf_idx(wp->w_buffer); int idx = diff_buf_idx(wp->w_buffer);
if (idx == DB_COUNT) { if (idx == DB_COUNT) {
@ -2283,16 +2270,14 @@ void ex_diffgetput(exarg_T *eap)
break; break;
} }
p = vim_strsave(ml_get_buf(curtab->tp_diffbuf[idx_from], nr, FALSE)); p = vim_strsave(ml_get_buf(curtab->tp_diffbuf[idx_from], nr, FALSE));
if (p != NULL) { ml_append(lnum + i - 1, p, 0, FALSE);
ml_append(lnum + i - 1, p, 0, FALSE); free(p);
free(p); added++;
added++; if (buf_empty && (curbuf->b_ml.ml_line_count == 2)) {
if (buf_empty && (curbuf->b_ml.ml_line_count == 2)) { // Added the first line into an empty buffer, need to
// Added the first line into an empty buffer, need to // delete the dummy empty line.
// delete the dummy empty line. buf_empty = FALSE;
buf_empty = FALSE; ml_delete((linenr_T)2, FALSE);
ml_delete((linenr_T)2, FALSE);
}
} }
} }
new_count = dp->df_count[idx_to] + added; new_count = dp->df_count[idx_to] + added;

View File

@ -1818,12 +1818,10 @@ void ex_loadkeymap(exarg_T *eap)
s = skiptowhite(p); s = skiptowhite(p);
kp->to = vim_strnsave(p, (int)(s - p)); kp->to = vim_strnsave(p, (int)(s - p));
if ((kp->from == NULL) if ((STRLEN(kp->from) + STRLEN(kp->to) >= KMAP_LLEN)
|| (kp->to == NULL)
|| (STRLEN(kp->from) + STRLEN(kp->to) >= KMAP_LLEN)
|| (*kp->from == NUL) || (*kp->from == NUL)
|| (*kp->to == NUL)) { || (*kp->to == NUL)) {
if ((kp->to != NULL) && (*kp->to == NUL)) { if (*kp->to == NUL) {
EMSG(_("E791: Empty keymap entry")); EMSG(_("E791: Empty keymap entry"));
} }
free(kp->from); free(kp->from);

View File

@ -1727,8 +1727,6 @@ change_indent (
/* Save new line */ /* Save new line */
new_line = vim_strsave(ml_get_curline()); new_line = vim_strsave(ml_get_curline());
if (new_line == NULL)
return;
/* We only put back the new line up to the cursor */ /* We only put back the new line up to the cursor */
new_line[curwin->w_cursor.col] = NUL; new_line[curwin->w_cursor.col] = NUL;
@ -2128,10 +2126,7 @@ ins_compl_add (
match->cp_number = -1; match->cp_number = -1;
if (flags & ORIGINAL_TEXT) if (flags & ORIGINAL_TEXT)
match->cp_number = 0; match->cp_number = 0;
if ((match->cp_str = vim_strnsave(str, len)) == NULL) { match->cp_str = vim_strnsave(str, len);
free(match);
return FAIL;
}
match->cp_icase = icase; match->cp_icase = icase;
/* match-fname is: /* match-fname is:
@ -2210,18 +2205,16 @@ static void ins_compl_longest_match(compl_T *match)
if (compl_leader == NULL) { if (compl_leader == NULL) {
/* First match, use it as a whole. */ /* First match, use it as a whole. */
compl_leader = vim_strsave(match->cp_str); compl_leader = vim_strsave(match->cp_str);
if (compl_leader != NULL) { had_match = (curwin->w_cursor.col > compl_col);
had_match = (curwin->w_cursor.col > compl_col); ins_compl_delete();
ins_compl_delete(); ins_bytes(compl_leader + ins_compl_len());
ins_bytes(compl_leader + ins_compl_len()); ins_redraw(FALSE);
ins_redraw(FALSE);
/* When the match isn't there (to avoid matching itself) remove it /* When the match isn't there (to avoid matching itself) remove it
* again after redrawing. */ * again after redrawing. */
if (!had_match) if (!had_match)
ins_compl_delete(); ins_compl_delete();
compl_used_match = FALSE; compl_used_match = FALSE;
}
} else { } else {
/* Reduce the text if this match differs from compl_leader. */ /* Reduce the text if this match differs from compl_leader. */
p = compl_leader; p = compl_leader;
@ -2328,9 +2321,10 @@ void set_completion(colnr_T startcol, list_T *list)
compl_length = (int)curwin->w_cursor.col - (int)startcol; compl_length = (int)curwin->w_cursor.col - (int)startcol;
/* compl_pattern doesn't need to be set */ /* compl_pattern doesn't need to be set */
compl_orig_text = vim_strnsave(ml_get_curline() + compl_col, compl_length); compl_orig_text = vim_strnsave(ml_get_curline() + compl_col, compl_length);
if (compl_orig_text == NULL || ins_compl_add(compl_orig_text, if (ins_compl_add(compl_orig_text, -1, p_ic, NULL, NULL, 0,
-1, p_ic, NULL, NULL, 0, ORIGINAL_TEXT, FALSE) != OK) ORIGINAL_TEXT, FALSE) != OK) {
return; return;
}
/* Handle like dictionary completion. */ /* Handle like dictionary completion. */
ctrl_x_mode = CTRL_X_WHOLE_LINE; ctrl_x_mode = CTRL_X_WHOLE_LINE;
@ -2873,14 +2867,12 @@ static int ins_compl_bs(void)
free(compl_leader); free(compl_leader);
compl_leader = vim_strnsave(line + compl_col, (int)(p - line) - compl_col); compl_leader = vim_strnsave(line + compl_col, (int)(p - line) - compl_col);
if (compl_leader != NULL) { ins_compl_new_leader();
ins_compl_new_leader(); if (compl_shown_match != NULL)
if (compl_shown_match != NULL) /* Make sure current match is not a hidden item. */
/* Make sure current match is not a hidden item. */ compl_curr_match = compl_shown_match;
compl_curr_match = compl_shown_match;
return NUL; return NUL;
}
return K_BS;
} }
/* /*
@ -2980,8 +2972,7 @@ static void ins_compl_addleader(int c)
free(compl_leader); free(compl_leader);
compl_leader = vim_strnsave(ml_get_curline() + compl_col, compl_leader = vim_strnsave(ml_get_curline() + compl_col,
(int)(curwin->w_cursor.col - compl_col)); (int)(curwin->w_cursor.col - compl_col));
if (compl_leader != NULL) ins_compl_new_leader();
ins_compl_new_leader();
} }
} }
@ -3003,15 +2994,10 @@ static void ins_compl_restart(void)
*/ */
static void ins_compl_set_original_text(char_u *str) static void ins_compl_set_original_text(char_u *str)
{ {
char_u *p;
/* Replace the original text entry. */ /* Replace the original text entry. */
if (compl_first_match->cp_flags & ORIGINAL_TEXT) { /* safety check */ if (compl_first_match->cp_flags & ORIGINAL_TEXT) { /* safety check */
p = vim_strsave(str); free(compl_first_match->cp_str);
if (p != NULL) { compl_first_match->cp_str = vim_strsave(str);
free(compl_first_match->cp_str);
compl_first_match->cp_str = p;
}
} }
} }
@ -4356,8 +4342,6 @@ static int ins_complete(int c)
) { ) {
/* Match any word of at least two chars */ /* Match any word of at least two chars */
compl_pattern = vim_strsave((char_u *)"\\<\\k\\k"); compl_pattern = vim_strsave((char_u *)"\\<\\k\\k");
if (compl_pattern == NULL)
return FAIL;
compl_col += curs_col; compl_col += curs_col;
compl_length = 0; compl_length = 0;
} else { } else {
@ -4432,8 +4416,6 @@ static int ins_complete(int c)
return FAIL; return FAIL;
} else if (ctrl_x_mode == CTRL_X_CMDLINE) { } else if (ctrl_x_mode == CTRL_X_CMDLINE) {
compl_pattern = vim_strnsave(line, curs_col); compl_pattern = vim_strnsave(line, curs_col);
if (compl_pattern == NULL)
return FAIL;
set_cmd_context(&compl_xp, compl_pattern, set_cmd_context(&compl_xp, compl_pattern,
(int)STRLEN(compl_pattern), curs_col); (int)STRLEN(compl_pattern), curs_col);
if (compl_xp.xp_context == EXPAND_UNSUCCESSFUL if (compl_xp.xp_context == EXPAND_UNSUCCESSFUL
@ -4513,8 +4495,6 @@ static int ins_complete(int c)
line = ml_get(curwin->w_cursor.lnum); line = ml_get(curwin->w_cursor.lnum);
compl_length = curs_col - compl_col; compl_length = curs_col - compl_col;
compl_pattern = vim_strnsave(line + compl_col, compl_length); compl_pattern = vim_strnsave(line + compl_col, compl_length);
if (compl_pattern == NULL)
return FAIL;
} else if (ctrl_x_mode == CTRL_X_SPELL) { } else if (ctrl_x_mode == CTRL_X_SPELL) {
if (spell_bad_len > 0) if (spell_bad_len > 0)
compl_col = curs_col - spell_bad_len; compl_col = curs_col - spell_bad_len;
@ -4530,8 +4510,6 @@ static int ins_complete(int c)
/* Need to obtain "line" again, it may have become invalid. */ /* Need to obtain "line" again, it may have become invalid. */
line = ml_get(curwin->w_cursor.lnum); line = ml_get(curwin->w_cursor.lnum);
compl_pattern = vim_strnsave(line + compl_col, compl_length); compl_pattern = vim_strnsave(line + compl_col, compl_length);
if (compl_pattern == NULL)
return FAIL;
} else { } else {
EMSG2(_(e_intern2), "ins_complete()"); EMSG2(_(e_intern2), "ins_complete()");
return FAIL; return FAIL;
@ -4568,8 +4546,8 @@ static int ins_complete(int c)
/* Always add completion for the original text. */ /* Always add completion for the original text. */
free(compl_orig_text); free(compl_orig_text);
compl_orig_text = vim_strnsave(line + compl_col, compl_length); compl_orig_text = vim_strnsave(line + compl_col, compl_length);
if (compl_orig_text == NULL || ins_compl_add(compl_orig_text, if (ins_compl_add(compl_orig_text, -1, p_ic, NULL, NULL, 0,
-1, p_ic, NULL, NULL, 0, ORIGINAL_TEXT, FALSE) != OK) { ORIGINAL_TEXT, FALSE) != OK) {
free(compl_pattern); free(compl_pattern);
compl_pattern = NULL; compl_pattern = NULL;
free(compl_orig_text); free(compl_orig_text);
@ -6227,11 +6205,10 @@ char_u *get_last_insert_save(void)
if (last_insert == NULL) if (last_insert == NULL)
return NULL; return NULL;
s = vim_strsave(last_insert + last_insert_skip); s = vim_strsave(last_insert + last_insert_skip);
if (s != NULL) { len = (int)STRLEN(s);
len = (int)STRLEN(s); if (len > 0 && s[len - 1] == ESC) /* remove trailing ESC */
if (len > 0 && s[len - 1] == ESC) /* remove trailing ESC */ s[len - 1] = NUL;
s[len - 1] = NUL;
}
return s; return s;
} }
@ -8006,8 +7983,6 @@ static int ins_tab(void)
pos = curwin->w_cursor; pos = curwin->w_cursor;
cursor = &pos; cursor = &pos;
saved_line = vim_strsave(ml_get_curline()); saved_line = vim_strsave(ml_get_curline());
if (saved_line == NULL)
return FALSE;
ptr = saved_line + pos.col; ptr = saved_line + pos.col;
} else { } else {
ptr = ml_get_cursor(); ptr = ml_get_cursor();
@ -8411,7 +8386,6 @@ static colnr_T get_nolist_virtcol(void)
*/ */
static char_u *do_insert_char_pre(int c) static char_u *do_insert_char_pre(int c)
{ {
char_u *res;
char_u buf[MB_MAXBYTES + 1]; char_u buf[MB_MAXBYTES + 1];
/* Return quickly when there is nothing to do. */ /* Return quickly when there is nothing to do. */
@ -8429,7 +8403,7 @@ static char_u *do_insert_char_pre(int c)
++textlock; ++textlock;
set_vim_var_string(VV_CHAR, buf, -1); /* set v:char */ set_vim_var_string(VV_CHAR, buf, -1); /* set v:char */
res = NULL; char_u *res = NULL;
if (apply_autocmds(EVENT_INSERTCHARPRE, NULL, NULL, FALSE, curbuf)) { if (apply_autocmds(EVENT_INSERTCHARPRE, NULL, NULL, FALSE, curbuf)) {
/* Get the value of v:char. It may be empty or more than one /* Get the value of v:char. It may be empty or more than one
* character. Only use it when changed, otherwise continue with the * character. Only use it when changed, otherwise continue with the

View File

@ -1041,8 +1041,6 @@ var_redir_start (
/* Make a copy of the name, it is used in redir_lval until redir ends. */ /* Make a copy of the name, it is used in redir_lval until redir ends. */
redir_varname = vim_strsave(name); redir_varname = vim_strsave(name);
if (redir_varname == NULL)
return FAIL;
redir_lval = xcalloc(1, sizeof(lval_T)); redir_lval = xcalloc(1, sizeof(lval_T));
@ -2542,8 +2540,6 @@ get_lval (
lp->ll_newkey = vim_strnsave(key, len); lp->ll_newkey = vim_strnsave(key, len);
if (len == -1) if (len == -1)
clear_tv(&var1); clear_tv(&var1);
if (lp->ll_newkey == NULL)
p = NULL;
break; break;
} }
/* existing variable, need to check if it can be changed */ /* existing variable, need to check if it can be changed */
@ -6353,8 +6349,6 @@ dictitem_T *dict_find(dict_T *d, char_u *key, int len)
akey = key; akey = key;
else if (len >= AKEYLEN) { else if (len >= AKEYLEN) {
tofree = akey = vim_strnsave(key, len); tofree = akey = vim_strnsave(key, len);
if (akey == NULL)
return NULL;
} else { } else {
/* Avoid a malloc/free by using buf[]. */ /* Avoid a malloc/free by using buf[]. */
vim_strncpy(buf, key, len); vim_strncpy(buf, key, len);
@ -7264,8 +7258,6 @@ call_func (
/* Make a copy of the name, if it comes from a funcref variable it could /* Make a copy of the name, if it comes from a funcref variable it could
* be changed or deleted in the called function. */ * be changed or deleted in the called function. */
name = vim_strnsave(funcname, len); name = vim_strnsave(funcname, len);
if (name == NULL)
return ret;
/* /*
* In a script change <SID>name() and s:name() to K_SNR 123_name(). * In a script change <SID>name() and s:name() to K_SNR 123_name().
@ -9677,11 +9669,9 @@ static void f_getfperm(typval_T *argvars, typval_T *rettv)
int32_t file_perm = os_getperm(filename); int32_t file_perm = os_getperm(filename);
if (file_perm >= 0) { if (file_perm >= 0) {
perm = vim_strsave((char_u *)"---------"); perm = vim_strsave((char_u *)"---------");
if (perm != NULL) { for (int i = 0; i < 9; i++) {
for (int i = 0; i < 9; i++) { if (file_perm & (1 << (8 - i)))
if (file_perm & (1 << (8 - i))) perm[i] = flags[i % 3];
perm[i] = flags[i % 3];
}
} }
} }
rettv->v_type = VAR_STRING; rettv->v_type = VAR_STRING;
@ -11761,8 +11751,6 @@ static int mkdir_recurse(char_u *dir, int prot)
/* If the directory exists we're done. Otherwise: create it.*/ /* If the directory exists we're done. Otherwise: create it.*/
updir = vim_strnsave(dir, (int)(p - dir)); updir = vim_strnsave(dir, (int)(p - dir));
if (updir == NULL)
return FAIL;
if (os_isdir(updir)) if (os_isdir(updir))
r = OK; r = OK;
else if (mkdir_recurse(updir, prot) == OK) else if (mkdir_recurse(updir, prot) == OK)
@ -12107,17 +12095,11 @@ static void f_readfile(typval_T *argvars, typval_T *rettv)
/* Change "prev" buffer to be the right size. This way /* Change "prev" buffer to be the right size. This way
* the bytes are only copied once, and very long lines are * the bytes are only copied once, and very long lines are
* allocated only once. */ * allocated only once. */
if ((s = xrealloc(prev, prevlen + len + 1)) != NULL) { s = xrealloc(prev, prevlen + len + 1);
memmove(s + prevlen, start, len); memcpy(s + prevlen, start, len);
s[prevlen + len] = NUL; s[prevlen + len] = NUL;
prev = NULL; /* the list will own the string */ prev = NULL; /* the list will own the string */
prevlen = prevsize = 0; prevlen = prevsize = 0;
}
}
if (s == NULL) {
do_outofmem_msg((long_u) prevlen + len + 1);
failed = TRUE;
break;
} }
if ((li = listitem_alloc()) == NULL) { if ((li = listitem_alloc()) == NULL) {
@ -12592,11 +12574,10 @@ static void f_resolve(typval_T *argvars, typval_T *rettv)
q = path_next_component(remain + 1); q = path_next_component(remain + 1);
len = q - remain - (*q != NUL); len = q - remain - (*q != NUL);
cpy = vim_strnsave(p, STRLEN(p) + len); cpy = vim_strnsave(p, STRLEN(p) + len);
if (cpy != NULL) { STRNCAT(cpy, remain, len);
STRNCAT(cpy, remain, len); free(p);
free(p); p = cpy;
p = cpy;
}
/* Shorten "remain". */ /* Shorten "remain". */
if (*q != NUL) if (*q != NUL)
STRMOVE(remain, q - 1); STRMOVE(remain, q - 1);
@ -14940,33 +14921,30 @@ static void f_tanh(typval_T *argvars, typval_T *rettv)
*/ */
static void f_tolower(typval_T *argvars, typval_T *rettv) static void f_tolower(typval_T *argvars, typval_T *rettv)
{ {
char_u *p; char_u *p = vim_strsave(get_tv_string(&argvars[0]));
p = vim_strsave(get_tv_string(&argvars[0]));
rettv->v_type = VAR_STRING; rettv->v_type = VAR_STRING;
rettv->vval.v_string = p; rettv->vval.v_string = p;
if (p != NULL) while (*p != NUL) {
while (*p != NUL) { int l;
int l;
if (enc_utf8) { if (enc_utf8) {
int c, lc; int c, lc;
c = utf_ptr2char(p); c = utf_ptr2char(p);
lc = utf_tolower(c); lc = utf_tolower(c);
l = utf_ptr2len(p); l = utf_ptr2len(p);
/* TODO: reallocate string when byte count changes. */ /* TODO: reallocate string when byte count changes. */
if (utf_char2len(lc) == l) if (utf_char2len(lc) == l)
utf_char2bytes(lc, p); utf_char2bytes(lc, p);
p += l; p += l;
} else if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1) } else if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1)
p += l; /* skip multi-byte character */ p += l; /* skip multi-byte character */
else { else {
*p = TOLOWER_LOC(*p); /* note that tolower() can be a macro */ *p = TOLOWER_LOC(*p); /* note that tolower() can be a macro */
++p; ++p;
}
} }
}
} }
/* /*
@ -17428,8 +17406,6 @@ void ex_function(exarg_T *eap)
c = *p; c = *p;
*p = NUL; *p = NUL;
arg = vim_strsave(arg); arg = vim_strsave(arg);
if (arg == NULL)
goto erret;
/* Check for duplicate argument name. */ /* Check for duplicate argument name. */
for (i = 0; i < newargs.ga_len; ++i) for (i = 0; i < newargs.ga_len; ++i)
@ -17621,11 +17597,9 @@ void ex_function(exarg_T *eap)
* allocates 250 bytes per line, this saves 80% on average. The cost * allocates 250 bytes per line, this saves 80% on average. The cost
* is an extra alloc/free. */ * is an extra alloc/free. */
p = vim_strsave(theline); p = vim_strsave(theline);
if (p != NULL) { if (line_arg == NULL)
if (line_arg == NULL) free(theline);
free(theline); theline = p;
theline = p;
}
((char_u **)(newlines.ga_data))[newlines.ga_len++] = theline; ((char_u **)(newlines.ga_data))[newlines.ga_len++] = theline;
@ -17694,8 +17668,6 @@ void ex_function(exarg_T *eap)
free(name); free(name);
sprintf(numbuf, "%d", ++func_nr); sprintf(numbuf, "%d", ++func_nr);
name = vim_strsave((char_u *)numbuf); name = vim_strsave((char_u *)numbuf);
if (name == NULL)
goto erret;
} }
if (fp == NULL) { if (fp == NULL) {
@ -19538,11 +19510,9 @@ repeat:
/* Only replace it when it starts with '~' */ /* Only replace it when it starts with '~' */
if (*dirname == '~') { if (*dirname == '~') {
s = vim_strsave(dirname); s = vim_strsave(dirname);
if (s != NULL) { *fnamep = s;
*fnamep = s; free(*bufp);
free(*bufp); *bufp = s;
*bufp = s;
}
} }
} }
free(pbuf); free(pbuf);
@ -19563,11 +19533,8 @@ repeat:
*fnamelen = (int)(tail - *fnamep); *fnamelen = (int)(tail - *fnamep);
if (*fnamelen == 0) { if (*fnamelen == 0) {
/* Result is empty. Turn it into "." to make ":cd %:h" work. */ /* Result is empty. Turn it into "." to make ":cd %:h" work. */
p = vim_strsave((char_u *)".");
if (p == NULL)
return -1;
free(*bufp); free(*bufp);
*bufp = *fnamep = tail = p; *bufp = *fnamep = tail = vim_strsave((char_u *)".");
*fnamelen = 1; *fnamelen = 1;
} else { } else {
while (tail > s && !after_pathsep(s, tail)) while (tail > s && !after_pathsep(s, tail))
@ -19645,23 +19612,19 @@ repeat:
s = p + 1; s = p + 1;
/* find end of substitution */ /* find end of substitution */
p = vim_strchr(s, sep); p = vim_strchr(s, sep);
if (p != NULL) { sub = vim_strnsave(s, (int)(p - s));
sub = vim_strnsave(s, (int)(p - s)); str = vim_strnsave(*fnamep, *fnamelen);
str = vim_strnsave(*fnamep, *fnamelen); *usedlen = (int)(p + 1 - src);
if (sub != NULL && str != NULL) { s = do_string_sub(str, pat, sub, flags);
*usedlen = (int)(p + 1 - src); if (s != NULL) {
s = do_string_sub(str, pat, sub, flags); *fnamep = s;
if (s != NULL) { *fnamelen = (int)STRLEN(s);
*fnamep = s; free(*bufp);
*fnamelen = (int)STRLEN(s); *bufp = s;
free(*bufp); didit = TRUE;
*bufp = s;
didit = TRUE;
}
}
free(sub);
free(str);
} }
free(sub);
free(str);
free(pat); free(pat);
} }
} }

View File

@ -695,12 +695,10 @@ int do_move(linenr_T line1, linenr_T line2, linenr_T dest)
return FAIL; return FAIL;
for (extra = 0, l = line1; l <= line2; l++) { for (extra = 0, l = line1; l <= line2; l++) {
str = vim_strsave(ml_get(l + extra)); str = vim_strsave(ml_get(l + extra));
if (str != NULL) { ml_append(dest + l - line1, str, (colnr_T)0, FALSE);
ml_append(dest + l - line1, str, (colnr_T)0, FALSE); free(str);
free(str); if (dest < line1)
if (dest < line1) extra++;
extra++;
}
} }
/* /*
@ -803,10 +801,9 @@ void ex_copy(linenr_T line1, linenr_T line2, linenr_T n)
/* need to use vim_strsave() because the line will be unlocked within /* need to use vim_strsave() because the line will be unlocked within
* ml_append() */ * ml_append() */
p = vim_strsave(ml_get(line1)); p = vim_strsave(ml_get(line1));
if (p != NULL) { ml_append(curwin->w_cursor.lnum, p, (colnr_T)0, FALSE);
ml_append(curwin->w_cursor.lnum, p, (colnr_T)0, FALSE); free(p);
free(p);
}
/* situation 2: skip already copied lines */ /* situation 2: skip already copied lines */
if (line1 == n) if (line1 == n)
line1 = curwin->w_cursor.lnum; line1 = curwin->w_cursor.lnum;
@ -1886,8 +1883,6 @@ viminfo_readstring (
s = retval + 1; /* Skip the leading '<' */ s = retval + 1; /* Skip the leading '<' */
} else { } else {
retval = vim_strsave(virp->vir_line + off); retval = vim_strsave(virp->vir_line + off);
if (retval == NULL)
return NULL;
s = retval; s = retval;
} }
@ -3937,17 +3932,14 @@ void do_sub(exarg_T *eap)
* what matches. Temporarily replace the line * what matches. Temporarily replace the line
* and change it back afterwards. */ * and change it back afterwards. */
orig_line = vim_strsave(ml_get(lnum)); orig_line = vim_strsave(ml_get(lnum));
if (orig_line != NULL) { char_u *new_line = concat_str(new_start, sub_firstline + copycol);
char_u *new_line = concat_str(new_start,
sub_firstline + copycol);
// Position the cursor relative to the end of the line, the // Position the cursor relative to the end of the line, the
// previous substitute may have inserted or deleted characters // previous substitute may have inserted or deleted characters
// before the cursor. // before the cursor.
len_change = (int)STRLEN(new_line) - (int)STRLEN(orig_line); len_change = (int)STRLEN(new_line) - (int)STRLEN(orig_line);
curwin->w_cursor.col += len_change; curwin->w_cursor.col += len_change;
ml_replace(lnum, new_line, FALSE); ml_replace(lnum, new_line, FALSE);
}
} }
search_match_lines = regmatch.endpos[0].lnum search_match_lines = regmatch.endpos[0].lnum
@ -5769,11 +5761,6 @@ void ex_sign(exarg_T *eap)
next_sign_typenr = 1; /* wrap around */ next_sign_typenr = 1; /* wrap around */
sp->sn_name = vim_strsave(arg); sp->sn_name = vim_strsave(arg);
if (sp->sn_name == NULL) /* out of memory */
{
free(sp);
return;
}
/* add the new sign to the list of signs */ /* add the new sign to the list of signs */
if (sp_prev == NULL) if (sp_prev == NULL)
@ -5837,7 +5824,7 @@ void ex_sign(exarg_T *eap)
len = (int)(p - arg + ((cells == 1) ? 1 : 0)); len = (int)(p - arg + ((cells == 1) ? 1 : 0));
sp->sn_text = vim_strnsave(arg, len); sp->sn_text = vim_strnsave(arg, len);
if (sp->sn_text != NULL && cells == 1) if (cells == 1)
STRCPY(sp->sn_text + len - 1, " "); STRCPY(sp->sn_text + len - 1, " ");
} }
else if (STRNCMP(arg, "linehl=", 7) == 0) else if (STRNCMP(arg, "linehl=", 7) == 0)

View File

@ -1920,8 +1920,6 @@ void ex_argedit(exarg_T *eap)
if (i == ARGCOUNT) { if (i == ARGCOUNT) {
/* Can't find it, add it to the argument list. */ /* Can't find it, add it to the argument list. */
s = vim_strsave(eap->arg); s = vim_strsave(eap->arg);
if (s == NULL)
return;
i = alist_add_list(1, &s, i = alist_add_list(1, &s,
eap->addr_count > 0 ? (int)eap->line2 : curwin->w_arg_idx + 1); eap->addr_count > 0 ? (int)eap->line2 : curwin->w_arg_idx + 1);
curwin->w_arg_idx = i; curwin->w_arg_idx = i;
@ -2252,8 +2250,8 @@ void *cookie;
/* Make a copy of 'runtimepath'. Invoking the callback may change the /* Make a copy of 'runtimepath'. Invoking the callback may change the
* value. */ * value. */
rtp_copy = vim_strsave(p_rtp); rtp_copy = vim_strsave(p_rtp);
buf = xmalloc(MAXPATHL); buf = xmallocz(MAXPATHL);
if (rtp_copy != NULL) { {
if (p_verbose > 1 && name != NULL) { if (p_verbose > 1 && name != NULL) {
verbose_enter(); verbose_enter();
smsg((char_u *)_("Searching for \"%s\" in \"%s\""), smsg((char_u *)_("Searching for \"%s\" in \"%s\""),
@ -2594,10 +2592,8 @@ do_source (
p = string_convert(&cookie.conv, firstline + 3, NULL); p = string_convert(&cookie.conv, firstline + 3, NULL);
if (p == NULL) if (p == NULL)
p = vim_strsave(firstline + 3); p = vim_strsave(firstline + 3);
if (p != NULL) { free(firstline);
free(firstline); firstline = p;
firstline = p;
}
} }
#ifdef STARTUPTIME #ifdef STARTUPTIME
@ -3483,8 +3479,6 @@ static char_u **find_locales(void)
while (loc != NULL) { while (loc != NULL) {
ga_grow(&locales_ga, 1); ga_grow(&locales_ga, 1);
loc = vim_strsave(loc); loc = vim_strsave(loc);
if (loc == NULL)
break;
((char_u **)locales_ga.ga_data)[locales_ga.ga_len++] = loc; ((char_u **)locales_ga.ga_data)[locales_ga.ga_len++] = loc;
loc = (char_u *)strtok(NULL, "\n"); loc = (char_u *)strtok(NULL, "\n");

View File

@ -721,11 +721,6 @@ int flags;
/* 3. Make a copy of the command so we can mess with it. */ /* 3. Make a copy of the command so we can mess with it. */
else if (cmdline_copy == NULL) { else if (cmdline_copy == NULL) {
next_cmdline = vim_strsave(next_cmdline); next_cmdline = vim_strsave(next_cmdline);
if (next_cmdline == NULL) {
EMSG(_(e_outofmem));
retval = FAIL;
break;
}
} }
cmdline_copy = next_cmdline; cmdline_copy = next_cmdline;
@ -4299,10 +4294,6 @@ static int uc_add_command(char_u *name, size_t name_len, char_u *rep, long argt,
if (rep_buf == NULL) { if (rep_buf == NULL) {
/* Can't replace termcodes - try using the string as is */ /* Can't replace termcodes - try using the string as is */
rep_buf = vim_strsave(rep); rep_buf = vim_strsave(rep);
/* Give up if out of memory */
if (rep_buf == NULL)
return FAIL;
} }
/* get address of growarray: global or in curbuf */ /* get address of growarray: global or in curbuf */
@ -4349,8 +4340,7 @@ static int uc_add_command(char_u *name, size_t name_len, char_u *rep, long argt,
if (cmp != 0) { if (cmp != 0) {
ga_grow(gap, 1); ga_grow(gap, 1);
if ((p = vim_strnsave(name, (int)name_len)) == NULL) p = vim_strnsave(name, (int)name_len);
goto fail;
cmd = USER_CMD_GA(gap, i); cmd = USER_CMD_GA(gap, i);
memmove(cmd + 1, cmd, (gap->ga_len - i) * sizeof(ucmd_T)); memmove(cmd + 1, cmd, (gap->ga_len - i) * sizeof(ucmd_T));
@ -5256,12 +5246,11 @@ static void ex_colorscheme(exarg_T *eap)
char_u *expr = vim_strsave((char_u *)"g:colors_name"); char_u *expr = vim_strsave((char_u *)"g:colors_name");
char_u *p = NULL; char_u *p = NULL;
if (expr != NULL) { ++emsg_off;
++emsg_off; p = eval_to_string(expr, NULL, FALSE);
p = eval_to_string(expr, NULL, FALSE); --emsg_off;
--emsg_off; free(expr);
free(expr);
}
if (p != NULL) { if (p != NULL) {
MSG(p); MSG(p);
free(p); free(p);
@ -7994,8 +7983,6 @@ char_u *expand_sfile(char_u *arg)
char_u *p; char_u *p;
result = vim_strsave(arg); result = vim_strsave(arg);
if (result == NULL)
return NULL;
for (p = result; *p; ) { for (p = result; *p; ) {
if (STRNCMP(p, "<sfile>", 7) != 0) if (STRNCMP(p, "<sfile>", 7) != 0)

View File

@ -250,11 +250,7 @@ int cause_errthrow(char_u *mesg, int severe, int *ignore)
EMSG(_(e_outofmem)); EMSG(_(e_outofmem));
} else { } else {
elem->msg = vim_strsave(mesg); elem->msg = vim_strsave(mesg);
if (elem->msg == NULL) { {
free(elem);
suppress_errthrow = TRUE;
EMSG(_(e_outofmem));
} else {
elem->next = NULL; elem->next = NULL;
elem->throw_msg = NULL; elem->throw_msg = NULL;
*plist = elem; *plist = elem;
@ -402,15 +398,11 @@ char_u *get_exception_string(void *value, int type, char_u *cmdname, int *should
cmdlen = (int)STRLEN(cmdname); cmdlen = (int)STRLEN(cmdname);
ret = vim_strnsave((char_u *)"Vim(", ret = vim_strnsave((char_u *)"Vim(",
4 + cmdlen + 2 + (int)STRLEN(mesg)); 4 + cmdlen + 2 + (int)STRLEN(mesg));
if (ret == NULL)
return ret;
STRCPY(&ret[4], cmdname); STRCPY(&ret[4], cmdname);
STRCPY(&ret[4 + cmdlen], "):"); STRCPY(&ret[4 + cmdlen], "):");
val = ret + 4 + cmdlen + 2; val = ret + 4 + cmdlen + 2;
} else { } else {
ret = vim_strnsave((char_u *)"Vim:", 4 + (int)STRLEN(mesg)); ret = vim_strnsave((char_u *)"Vim:", 4 + (int)STRLEN(mesg));
if (ret == NULL)
return ret;
val = ret + 4; val = ret + 4;
} }
@ -493,11 +485,6 @@ static int throw_exception(void *value, int type, char_u *cmdname)
excp->type = type; excp->type = type;
excp->throw_name = vim_strsave(sourcing_name == NULL excp->throw_name = vim_strsave(sourcing_name == NULL
? (char_u *)"" : sourcing_name); ? (char_u *)"" : sourcing_name);
if (excp->throw_name == NULL) {
if (should_free)
free(excp->value);
goto nomem;
}
excp->throw_lnum = sourcing_lnum; excp->throw_lnum = sourcing_lnum;
if (p_verbose >= 13 || debug_break_level > 0) { if (p_verbose >= 13 || debug_break_level > 0) {

View File

@ -1196,8 +1196,7 @@ getcmdline (
/* save current command string so it can be restored later */ /* save current command string so it can be restored later */
if (lookfor == NULL) { if (lookfor == NULL) {
if ((lookfor = vim_strsave(ccline.cmdbuff)) == NULL) lookfor = vim_strsave(ccline.cmdbuff);
goto cmdline_not_changed;
lookfor[ccline.cmdpos] = NUL; lookfor[ccline.cmdpos] = NUL;
} }
@ -4510,8 +4509,7 @@ add_to_history (
/* Store the separator after the NUL of the string. */ /* Store the separator after the NUL of the string. */
len = (int)STRLEN(new_entry); len = (int)STRLEN(new_entry);
hisptr->hisstr = vim_strnsave(new_entry, len + 2); hisptr->hisstr = vim_strnsave(new_entry, len + 2);
if (hisptr->hisstr != NULL) hisptr->hisstr[len + 1] = sep;
hisptr->hisstr[len + 1] = sep;
hisptr->hisnum = ++hisnum[histype]; hisptr->hisnum = ++hisnum[histype];
hisptr->viminfo = FALSE; hisptr->viminfo = FALSE;

View File

@ -322,8 +322,6 @@ vim_findfile_init (
search_ctx->ffsc_start_dir = FullName_save(ff_expand_buffer, FALSE); search_ctx->ffsc_start_dir = FullName_save(ff_expand_buffer, FALSE);
} else } else
search_ctx->ffsc_start_dir = vim_strnsave(rel_fname, len); search_ctx->ffsc_start_dir = vim_strnsave(rel_fname, len);
if (search_ctx->ffsc_start_dir == NULL)
goto error_return;
if (*++path != NUL) if (*++path != NUL)
++path; ++path;
} else if (*path == NUL || !vim_isAbsName(path)) { } else if (*path == NUL || !vim_isAbsName(path)) {
@ -344,8 +342,6 @@ vim_findfile_init (
goto error_return; goto error_return;
search_ctx->ffsc_start_dir = vim_strsave(ff_expand_buffer); search_ctx->ffsc_start_dir = vim_strsave(ff_expand_buffer);
if (search_ctx->ffsc_start_dir == NULL)
goto error_return;
#ifdef BACKSLASH_IN_FILENAME #ifdef BACKSLASH_IN_FILENAME
/* A path that starts with "/dir" is relative to the drive, not to the /* A path that starts with "/dir" is relative to the drive, not to the
@ -458,9 +454,6 @@ vim_findfile_init (
} }
ff_expand_buffer[len] = NUL; ff_expand_buffer[len] = NUL;
search_ctx->ffsc_wc_path = vim_strsave(ff_expand_buffer); search_ctx->ffsc_wc_path = vim_strsave(ff_expand_buffer);
if (search_ctx->ffsc_wc_path == NULL)
goto error_return;
} else } else
search_ctx->ffsc_fix_path = vim_strsave(path); search_ctx->ffsc_fix_path = vim_strsave(path);
@ -469,8 +462,6 @@ vim_findfile_init (
* This is needed if the parameter path is fully qualified. * This is needed if the parameter path is fully qualified.
*/ */
search_ctx->ffsc_start_dir = vim_strsave(search_ctx->ffsc_fix_path); search_ctx->ffsc_start_dir = vim_strsave(search_ctx->ffsc_fix_path);
if (search_ctx->ffsc_start_dir == NULL)
goto error_return;
search_ctx->ffsc_fix_path[0] = NUL; search_ctx->ffsc_fix_path[0] = NUL;
} }
@ -536,11 +527,7 @@ vim_findfile_init (
goto error_return; goto error_return;
ff_push(search_ctx, sptr); ff_push(search_ctx, sptr);
search_ctx->ffsc_file_to_search = vim_strsave(filename); search_ctx->ffsc_file_to_search = vim_strsave(filename);
if (search_ctx->ffsc_file_to_search == NULL)
goto error_return;
return search_ctx; return search_ctx;
error_return: error_return:
@ -1070,10 +1057,6 @@ static ff_visited_list_hdr_T *ff_get_visited_list(char_u *filename, ff_visited_l
retptr->ffvl_visited_list = NULL; retptr->ffvl_visited_list = NULL;
retptr->ffvl_filename = vim_strsave(filename); retptr->ffvl_filename = vim_strsave(filename);
if (retptr->ffvl_filename == NULL) {
free(retptr);
return NULL;
}
retptr->ffvl_next = *list_headp; retptr->ffvl_next = *list_headp;
*list_headp = retptr; *list_headp = retptr;
@ -1185,9 +1168,7 @@ static int ff_check_visited(ff_visited_T **visited_list, char_u *fname, char_u *
*/ */
static ff_stack_T *ff_create_stack_element(char_u *fix_part, char_u *wc_part, int level, int star_star_empty) static ff_stack_T *ff_create_stack_element(char_u *fix_part, char_u *wc_part, int level, int star_star_empty)
{ {
ff_stack_T *new; ff_stack_T *new = xmalloc(sizeof(ff_stack_T));
new = (ff_stack_T *)alloc((unsigned)sizeof(ff_stack_T));
new->ffs_prev = NULL; new->ffs_prev = NULL;
new->ffs_filearray = NULL; new->ffs_filearray = NULL;
@ -1206,13 +1187,6 @@ static ff_stack_T *ff_create_stack_element(char_u *fix_part, char_u *wc_part, in
wc_part = (char_u *)""; wc_part = (char_u *)"";
new->ffs_wc_path = vim_strsave(wc_part); new->ffs_wc_path = vim_strsave(wc_part);
if (new->ffs_fix_path == NULL
|| new->ffs_wc_path == NULL
) {
ff_free_stack_element(new);
new = NULL;
}
return new; return new;
} }
@ -1429,10 +1403,6 @@ find_file_in_path_option (
free(ff_file_to_find); free(ff_file_to_find);
ff_file_to_find = vim_strsave(NameBuff); ff_file_to_find = vim_strsave(NameBuff);
if (ff_file_to_find == NULL) { /* out of memory */
file_name = NULL;
goto theend;
}
} }
rel_to_curdir = (ff_file_to_find[0] == '.' rel_to_curdir = (ff_file_to_find[0] == '.'

View File

@ -2138,11 +2138,9 @@ static char_u *next_fenc(char_u **pp)
} else { } else {
r = vim_strnsave(*pp, (int)(p - *pp)); r = vim_strnsave(*pp, (int)(p - *pp));
*pp = p + 1; *pp = p + 1;
if (r != NULL) { p = enc_canonize(r);
p = enc_canonize(r); free(r);
free(r); r = p;
r = p;
}
} }
if (r == NULL) { /* out of memory */ if (r == NULL) { /* out of memory */
r = (char_u *)""; r = (char_u *)"";
@ -5037,7 +5035,7 @@ static int move_lines(buf_T *frombuf, buf_T *tobuf)
curbuf = tobuf; curbuf = tobuf;
for (lnum = 1; lnum <= frombuf->b_ml.ml_line_count; ++lnum) { for (lnum = 1; lnum <= frombuf->b_ml.ml_line_count; ++lnum) {
p = vim_strsave(ml_get_buf(frombuf, lnum, FALSE)); p = vim_strsave(ml_get_buf(frombuf, lnum, FALSE));
if (p == NULL || ml_append(lnum - 1, p, 0, FALSE) == FAIL) { if (ml_append(lnum - 1, p, 0, FALSE) == FAIL) {
free(p); free(p);
retval = FAIL; retval = FAIL;
break; break;
@ -6037,8 +6035,6 @@ static int au_new_group(char_u *name)
} }
AUGROUP_NAME(i) = vim_strsave(name); AUGROUP_NAME(i) = vim_strsave(name);
if (AUGROUP_NAME(i) == NULL)
return AUGROUP_ERROR;
if (i == augroups.ga_len) if (i == augroups.ga_len)
++augroups.ga_len; ++augroups.ga_len;
} }
@ -6242,18 +6238,14 @@ char_u *au_event_disable(char *what)
char_u *save_ei; char_u *save_ei;
save_ei = vim_strsave(p_ei); save_ei = vim_strsave(p_ei);
if (save_ei != NULL) { new_ei = vim_strnsave(p_ei, (int)(STRLEN(p_ei) + STRLEN(what)));
new_ei = vim_strnsave(p_ei, (int)(STRLEN(p_ei) + STRLEN(what))); if (*what == ',' && *p_ei == NUL)
if (new_ei != NULL) { STRCPY(new_ei, what + 1);
if (*what == ',' && *p_ei == NUL) else
STRCPY(new_ei, what + 1); STRCAT(new_ei, what);
else set_string_option_direct((char_u *)"ei", -1, new_ei, OPT_FREE, SID_NONE);
STRCAT(new_ei, what); free(new_ei);
set_string_option_direct((char_u *)"ei", -1, new_ei,
OPT_FREE, SID_NONE);
free(new_ei);
}
}
return save_ei; return save_ei;
} }
@ -6404,7 +6396,7 @@ void do_autocmd(char_u *arg, int forceit)
* Find the group ID in a ":autocmd" or ":doautocmd" argument. * Find the group ID in a ":autocmd" or ":doautocmd" argument.
* The "argp" argument is advanced to the following argument. * The "argp" argument is advanced to the following argument.
* *
* Returns the group ID, AUGROUP_ERROR for error (out of memory). * Returns the group ID or AUGROUP_ALL.
*/ */
static int au_get_grouparg(char_u **argp) static int au_get_grouparg(char_u **argp)
{ {
@ -6416,8 +6408,6 @@ static int au_get_grouparg(char_u **argp)
p = skiptowhite(arg); p = skiptowhite(arg);
if (p > arg) { if (p > arg) {
group_name = vim_strnsave(arg, (int)(p - arg)); group_name = vim_strnsave(arg, (int)(p - arg));
if (group_name == NULL) /* out of memory */
return AUGROUP_ERROR;
group = au_find_group(group_name); group = au_find_group(group_name);
if (group == AUGROUP_ERROR) if (group == AUGROUP_ERROR)
group = AUGROUP_ALL; /* no match, use all groups */ group = AUGROUP_ALL; /* no match, use all groups */
@ -6587,10 +6577,6 @@ static int do_autocmd_event(event_T event, char_u *pat, int nested, char_u *cmd,
ap = (AutoPat *)alloc((unsigned)sizeof(AutoPat)); ap = (AutoPat *)alloc((unsigned)sizeof(AutoPat));
ap->pat = vim_strnsave(pat, patlen); ap->pat = vim_strnsave(pat, patlen);
ap->patlen = patlen; ap->patlen = patlen;
if (ap->pat == NULL) {
free(ap);
return FAIL;
}
if (is_buflocal) { if (is_buflocal) {
ap->buflocal_nr = buflocal_nr; ap->buflocal_nr = buflocal_nr;
@ -6628,10 +6614,6 @@ static int do_autocmd_event(event_T event, char_u *pat, int nested, char_u *cmd,
ac = (AutoCmd *)alloc((unsigned)sizeof(AutoCmd)); ac = (AutoCmd *)alloc((unsigned)sizeof(AutoCmd));
ac->cmd = vim_strsave(cmd); ac->cmd = vim_strsave(cmd);
ac->scriptID = current_SID; ac->scriptID = current_SID;
if (ac->cmd == NULL) {
free(ac);
return FAIL;
}
ac->next = NULL; ac->next = NULL;
*prev_ac = ac; *prev_ac = ac;
ac->nested = nested; ac->nested = nested;
@ -7542,8 +7524,7 @@ int has_autocmd(event_T event, char_u *sfname, buf_T *buf)
* autocommand patterns portable between Unix and MS-DOS. * autocommand patterns portable between Unix and MS-DOS.
*/ */
sfname = vim_strsave(sfname); sfname = vim_strsave(sfname);
if (sfname != NULL) forward_slash(sfname);
forward_slash(sfname);
forward_slash(fname); forward_slash(fname);
#endif #endif
@ -7681,8 +7662,6 @@ int au_exists(char_u *arg)
/* Make a copy so that we can change the '#' chars to a NUL. */ /* Make a copy so that we can change the '#' chars to a NUL. */
arg_save = vim_strsave(arg); arg_save = vim_strsave(arg);
if (arg_save == NULL)
return FALSE;
p = vim_strchr(arg_save, '#'); p = vim_strchr(arg_save, '#');
if (p != NULL) if (p != NULL)
*p++ = NUL; *p++ = NUL;

View File

@ -2636,7 +2636,6 @@ do_map (
char_u *p; char_u *p;
int n; int n;
int len = 0; /* init for GCC */ int len = 0; /* init for GCC */
char_u *newstr;
int hasarg; int hasarg;
int haskey; int haskey;
int did_it = FALSE; int did_it = FALSE;
@ -2979,13 +2978,8 @@ do_map (
} else { /* new rhs for existing entry */ } else { /* new rhs for existing entry */
mp->m_mode &= ~mode; /* remove mode bits */ mp->m_mode &= ~mode; /* remove mode bits */
if (mp->m_mode == 0 && !did_it) { /* reuse entry */ if (mp->m_mode == 0 && !did_it) { /* reuse entry */
newstr = vim_strsave(rhs);
if (newstr == NULL) {
retval = 4; /* no mem */
goto theend;
}
free(mp->m_str); free(mp->m_str);
mp->m_str = newstr; mp->m_str = vim_strsave(rhs);
free(mp->m_orig_str); free(mp->m_orig_str);
mp->m_orig_str = vim_strsave(orig_rhs); mp->m_orig_str = vim_strsave(orig_rhs);
mp->m_noremap = noremap; mp->m_noremap = noremap;
@ -3057,14 +3051,6 @@ do_map (
mp->m_keys = vim_strsave(keys); mp->m_keys = vim_strsave(keys);
mp->m_str = vim_strsave(rhs); mp->m_str = vim_strsave(rhs);
mp->m_orig_str = vim_strsave(orig_rhs); mp->m_orig_str = vim_strsave(orig_rhs);
if (mp->m_keys == NULL || mp->m_str == NULL) {
free(mp->m_keys);
free(mp->m_str);
free(mp->m_orig_str);
free(mp);
retval = 4; /* no mem */
goto theend;
}
mp->m_keylen = (int)STRLEN(mp->m_keys); mp->m_keylen = (int)STRLEN(mp->m_keys);
mp->m_noremap = noremap; mp->m_noremap = noremap;
mp->m_nowait = nowait; mp->m_nowait = nowait;
@ -3328,11 +3314,9 @@ showmap (
/* Remove escaping of CSI, because "m_str" is in a format to be used /* Remove escaping of CSI, because "m_str" is in a format to be used
* as typeahead. */ * as typeahead. */
char_u *s = vim_strsave(mp->m_str); char_u *s = vim_strsave(mp->m_str);
if (s != NULL) { vim_unescape_csi(s);
vim_unescape_csi(s); msg_outtrans_special(s, FALSE);
msg_outtrans_special(s, FALSE); free(s);
free(s);
}
} }
if (p_verbose > 0) if (p_verbose > 0)
last_set_msg(mp->m_script_ID); last_set_msg(mp->m_script_ID);
@ -3778,8 +3762,6 @@ eval_map_expr (
/* Remove escaping of CSI, because "str" is in a format to be used as /* Remove escaping of CSI, because "str" is in a format to be used as
* typeahead. */ * typeahead. */
expr = vim_strsave(str); expr = vim_strsave(str);
if (expr == NULL)
return NULL;
vim_unescape_csi(expr); vim_unescape_csi(expr);
save_cmd = save_cmdline_alloc(); save_cmd = save_cmdline_alloc();
@ -4325,10 +4307,8 @@ void add_map(char_u *map, int mode)
p_cpo = (char_u *)""; /* Allow <> notation */ p_cpo = (char_u *)""; /* Allow <> notation */
s = vim_strsave(map); s = vim_strsave(map);
if (s != NULL) { (void)do_map(0, s, mode, FALSE);
(void)do_map(0, s, mode, FALSE); free(s);
free(s);
}
p_cpo = cpo_save; p_cpo = cpo_save;
} }
#endif #endif

View File

@ -1633,10 +1633,7 @@ static void cs_fill_results(char *tagstr, int totmatches, int *nummatches_a, cha
if (strcmp(cntx, "<global>") == 0) if (strcmp(cntx, "<global>") == 0)
cntxts[totsofar] = NULL; cntxts[totsofar] = NULL;
else { else {
/* note: if vim_strsave returns NULL, then the context cntxts[totsofar] = xstrdup(cntx);
* will be "<global>", which is misleading.
*/
cntxts[totsofar] = (char *)vim_strsave((char_u *)cntx);
} }
totsofar++; totsofar++;
@ -2110,7 +2107,7 @@ static char *cs_resolve_file(int i, char *name)
* cscope output. */ * cscope output. */
fullname = (char *)concat_fnames(csdir, (char_u *)name, TRUE); fullname = (char *)concat_fnames(csdir, (char_u *)name, TRUE);
} else { } else {
fullname = (char *)vim_strsave((char_u *)name); fullname = xstrdup(name);
} }
free(csdir); free(csdir);

View File

@ -1428,8 +1428,8 @@ scripterror:
/* Add the file to the global argument list. */ /* Add the file to the global argument list. */
ga_grow(&global_alist.al_ga, 1); ga_grow(&global_alist.al_ga, 1);
if ((p = vim_strsave((char_u *)argv[0])) == NULL) p = vim_strsave((char_u *)argv[0]);
mch_exit(2);
if (parmp->diff_mode && os_isdir(p) && GARGCOUNT > 0 if (parmp->diff_mode && os_isdir(p) && GARGCOUNT > 0
&& !os_isdir(alist_name(&GARGLIST[0]))) { && !os_isdir(alist_name(&GARGLIST[0]))) {
char_u *r; char_u *r;

View File

@ -606,8 +606,7 @@ static char_u *mark_line(pos_T *mp, int lead_len)
if (mp->lnum == 0 || mp->lnum > curbuf->b_ml.ml_line_count) if (mp->lnum == 0 || mp->lnum > curbuf->b_ml.ml_line_count)
return vim_strsave((char_u *)"-invalid-"); return vim_strsave((char_u *)"-invalid-");
s = vim_strnsave(skipwhite(ml_get(mp->lnum)), (int)Columns); s = vim_strnsave(skipwhite(ml_get(mp->lnum)), (int)Columns);
if (s == NULL)
return NULL;
/* Truncate the line to fit it in the window */ /* Truncate the line to fit it in the window */
len = 0; len = 0;
for (p = s; *p != NUL; mb_ptr_adv(p)) { for (p = s; *p != NUL; mb_ptr_adv(p)) {

View File

@ -2607,8 +2607,8 @@ int ml_replace(linenr_T lnum, char_u *line, int copy)
if (curbuf->b_ml.ml_mfp == NULL && open_buffer(FALSE, NULL, 0) == FAIL) if (curbuf->b_ml.ml_mfp == NULL && open_buffer(FALSE, NULL, 0) == FAIL)
return FAIL; return FAIL;
if (copy && (line = vim_strsave(line)) == NULL) /* allocate memory */ if (copy)
return FAIL; line = vim_strsave(line);
if (curbuf->b_ml.ml_line_lnum != lnum) /* other line buffered */ if (curbuf->b_ml.ml_line_lnum != lnum) /* other line buffered */
ml_flush_line(curbuf); /* flush it */ ml_flush_line(curbuf); /* flush it */
else if (curbuf->b_ml.ml_flags & ML_LINE_DIRTY) /* same line allocated */ else if (curbuf->b_ml.ml_flags & ML_LINE_DIRTY) /* same line allocated */

View File

@ -192,7 +192,7 @@ char *xstpncpy(char *restrict dst, const char *restrict src, size_t maxlen)
} }
} }
char * xstrdup(const char *str) char *xstrdup(const char *str)
{ {
char *ret = strdup(str); char *ret = strdup(str);

View File

@ -308,8 +308,6 @@ add_menu_path (
/* Make a copy so we can stuff around with it, since it could be const */ /* Make a copy so we can stuff around with it, since it could be const */
path_name = vim_strsave(menu_path); path_name = vim_strsave(menu_path);
if (path_name == NULL)
return FAIL;
menup = &root_menu; menup = &root_menu;
parent = NULL; parent = NULL;
name = path_name; name = path_name;
@ -728,8 +726,6 @@ static int show_menus(char_u *path_name, int modes)
menu = root_menu; menu = root_menu;
name = path_name = vim_strsave(path_name); name = path_name = vim_strsave(path_name);
if (path_name == NULL)
return FAIL;
/* First, find the (sub)menu with the given name */ /* First, find the (sub)menu with the given name */
while (*name) { while (*name) {
@ -1168,7 +1164,7 @@ get_menu_cmd_modes (
/* /*
* Modify a menu name starting with "PopUp" to include the mode character. * Modify a menu name starting with "PopUp" to include the mode character.
* Returns the name in allocated memory (NULL for failure). * Returns the name in allocated memory.
*/ */
static char_u *popup_mode_name(char_u *name, int idx) static char_u *popup_mode_name(char_u *name, int idx)
{ {
@ -1176,10 +1172,9 @@ static char_u *popup_mode_name(char_u *name, int idx)
int len = (int)STRLEN(name); int len = (int)STRLEN(name);
p = vim_strnsave(name, len + 1); p = vim_strnsave(name, len + 1);
if (p != NULL) { memmove(p + 6, p + 5, (size_t)(len - 4));
memmove(p + 6, p + 5, (size_t)(len - 4)); p[5] = menu_mode_chars[idx];
p[5] = menu_mode_chars[idx];
}
return p; return p;
} }
@ -1305,8 +1300,6 @@ void ex_emenu(exarg_T *eap)
char_u *mode; char_u *mode;
saved_name = vim_strsave(eap->arg); saved_name = vim_strsave(eap->arg);
if (saved_name == NULL)
return;
menu = root_menu; menu = root_menu;
name = saved_name; name = saved_name;
@ -1419,8 +1412,6 @@ vimmenu_T *gui_find_menu(char_u *path_name)
menu = root_menu; menu = root_menu;
saved_name = vim_strsave(path_name); saved_name = vim_strsave(path_name);
if (saved_name == NULL)
return NULL;
name = saved_name; name = saved_name;
while (*name) { while (*name) {
@ -1513,23 +1504,21 @@ void ex_menutranslate(exarg_T *eap)
ga_grow(&menutrans_ga, 1); ga_grow(&menutrans_ga, 1);
tp = (menutrans_T *)menutrans_ga.ga_data; tp = (menutrans_T *)menutrans_ga.ga_data;
from = vim_strsave(from); from = vim_strsave(from);
if (from != NULL) { from_noamp = menu_text(from, NULL, NULL);
from_noamp = menu_text(from, NULL, NULL); to = vim_strnsave(to, (int)(arg - to));
to = vim_strnsave(to, (int)(arg - to)); if (from_noamp != NULL) {
if (from_noamp != NULL && to != NULL) { menu_translate_tab_and_shift(from);
menu_translate_tab_and_shift(from); menu_translate_tab_and_shift(to);
menu_translate_tab_and_shift(to); menu_unescape_name(from);
menu_unescape_name(from); menu_unescape_name(to);
menu_unescape_name(to); tp[menutrans_ga.ga_len].from = from;
tp[menutrans_ga.ga_len].from = from; tp[menutrans_ga.ga_len].from_noamp = from_noamp;
tp[menutrans_ga.ga_len].from_noamp = from_noamp; tp[menutrans_ga.ga_len].to = to;
tp[menutrans_ga.ga_len].to = to; ++menutrans_ga.ga_len;
++menutrans_ga.ga_len; } else {
} else { free(from);
free(from); free(from_noamp);
free(from_noamp); free(to);
free(to);
}
} }
} }
} }

View File

@ -120,8 +120,6 @@ open_line (
* make a copy of the current line so we can mess with it * make a copy of the current line so we can mess with it
*/ */
saved_line = vim_strsave(ml_get_curline()); saved_line = vim_strsave(ml_get_curline());
if (saved_line == NULL) /* out of memory! */
return FALSE;
if (State & VREPLACE_FLAG) { if (State & VREPLACE_FLAG) {
/* /*
@ -137,8 +135,6 @@ open_line (
next_line = vim_strsave(ml_get(curwin->w_cursor.lnum + 1)); next_line = vim_strsave(ml_get(curwin->w_cursor.lnum + 1));
else else
next_line = vim_strsave((char_u *)""); next_line = vim_strsave((char_u *)"");
if (next_line == NULL) /* out of memory! */
goto theend;
/* /*
* In VREPLACE mode, a NL replaces the rest of the line, and starts * In VREPLACE mode, a NL replaces the rest of the line, and starts
@ -918,8 +914,6 @@ open_line (
if (State & VREPLACE_FLAG) { if (State & VREPLACE_FLAG) {
/* Put new line in p_extra */ /* Put new line in p_extra */
p_extra = vim_strsave(ml_get_curline()); p_extra = vim_strsave(ml_get_curline());
if (p_extra == NULL)
goto theend;
/* Put back original line */ /* Put back original line */
ml_replace(curwin->w_cursor.lnum, next_line, FALSE); ml_replace(curwin->w_cursor.lnum, next_line, FALSE);
@ -1743,9 +1737,6 @@ truncate_line (
else else
newp = vim_strnsave(ml_get(lnum), col); newp = vim_strnsave(ml_get(lnum), col);
if (newp == NULL)
return FAIL;
ml_replace(lnum, newp, FALSE); ml_replace(lnum, newp, FALSE);
/* mark the buffer as changed and prepare for displaying */ /* mark the buffer as changed and prepare for displaying */
@ -2874,13 +2865,11 @@ expand_env_esc (
if (p_ssl && var != NULL && vim_strchr(var, '\\') != NULL) { if (p_ssl && var != NULL && vim_strchr(var, '\\') != NULL) {
char_u *p = vim_strsave(var); char_u *p = vim_strsave(var);
if (p != NULL) { if (mustfree)
if (mustfree) free(var);
free(var); var = p;
var = p; mustfree = TRUE;
mustfree = TRUE; forward_slash(var);
forward_slash(var);
}
} }
#endif #endif
@ -3033,7 +3022,7 @@ char_u *vim_getenv(char_u *name, int *mustfree)
/* check that the result is a directory name */ /* check that the result is a directory name */
p = vim_strnsave(p, (int)(pend - p)); p = vim_strnsave(p, (int)(pend - p));
if (p != NULL && !os_isdir(p)) { if (!os_isdir(p)) {
free(p); free(p);
p = NULL; p = NULL;
} else { } else {

View File

@ -689,8 +689,6 @@ char_u *get_expr_line(void)
/* Make a copy of the expression, because evaluating it may cause it to be /* Make a copy of the expression, because evaluating it may cause it to be
* changed. */ * changed. */
expr_copy = vim_strsave(expr_line); expr_copy = vim_strsave(expr_line);
if (expr_copy == NULL)
return NULL;
/* When we are invoked recursively limit the evaluation to 10 levels. /* When we are invoked recursively limit the evaluation to 10 levels.
* Then return the string as-is. */ * Then return the string as-is. */
@ -2154,17 +2152,15 @@ void op_insert(oparg_T *oap, long count1)
if (pre_textlen >= 0 if (pre_textlen >= 0
&& (ins_len = (long)STRLEN(firstline) - pre_textlen) > 0) { && (ins_len = (long)STRLEN(firstline) - pre_textlen) > 0) {
ins_text = vim_strnsave(firstline, (int)ins_len); ins_text = vim_strnsave(firstline, (int)ins_len);
if (ins_text != NULL) { /* block handled here */
/* block handled here */ if (u_save(oap->start.lnum,
if (u_save(oap->start.lnum, (linenr_T)(oap->end.lnum + 1)) == OK)
(linenr_T)(oap->end.lnum + 1)) == OK) block_insert(oap, ins_text, (oap->op_type == OP_INSERT),
block_insert(oap, ins_text, (oap->op_type == OP_INSERT), &bd);
&bd);
curwin->w_cursor.col = oap->start.col; curwin->w_cursor.col = oap->start.col;
check_cursor(); check_cursor();
free(ins_text); free(ins_text);
}
} }
} }
} }
@ -2414,9 +2410,7 @@ int op_yank(oparg_T *oap, int deleting, int mess)
break; break;
case MLINE: case MLINE:
if ((y_current->y_array[y_idx] = y_current->y_array[y_idx] = vim_strsave(ml_get(lnum));
vim_strsave(ml_get(lnum))) == NULL)
goto fail;
break; break;
case MCHAR: case MCHAR:
@ -2547,13 +2541,7 @@ int op_yank(oparg_T *oap, int deleting, int mess)
curbuf->b_op_end.col = MAXCOL; curbuf->b_op_end.col = MAXCOL;
} }
return OK; return OK;
fail: /* free the allocated lines */
free_yank(y_idx + 1);
y_current = curr;
return FAIL;
} }
static void yank_copy_line(struct block_def *bd, long y_idx) static void yank_copy_line(struct block_def *bd, long y_idx)
@ -2699,14 +2687,10 @@ do_put (
if (u_save_cursor() == FAIL) if (u_save_cursor() == FAIL)
goto end; goto end;
ptr = vim_strsave(ml_get_cursor()); ptr = vim_strsave(ml_get_cursor());
if (ptr == NULL)
goto end;
ml_append(curwin->w_cursor.lnum, ptr, (colnr_T)0, FALSE); ml_append(curwin->w_cursor.lnum, ptr, (colnr_T)0, FALSE);
free(ptr); free(ptr);
ptr = vim_strnsave(ml_get_curline(), curwin->w_cursor.col); ptr = vim_strnsave(ml_get_curline(), curwin->w_cursor.col);
if (ptr == NULL)
goto end;
ml_replace(curwin->w_cursor.lnum, ptr, FALSE); ml_replace(curwin->w_cursor.lnum, ptr, FALSE);
++nr_lines; ++nr_lines;
dir = FORWARD; dir = FORWARD;
@ -3628,20 +3612,19 @@ static int same_leader(linenr_T lnum, int leader1_len, char_u *leader1_flags, in
* The first line has to be saved, only one line can be locked at a time. * The first line has to be saved, only one line can be locked at a time.
*/ */
line1 = vim_strsave(ml_get(lnum)); line1 = vim_strsave(ml_get(lnum));
if (line1 != NULL) { for (idx1 = 0; vim_iswhite(line1[idx1]); ++idx1)
for (idx1 = 0; vim_iswhite(line1[idx1]); ++idx1) ;
; line2 = ml_get(lnum + 1);
line2 = ml_get(lnum + 1); for (idx2 = 0; idx2 < leader2_len; ++idx2) {
for (idx2 = 0; idx2 < leader2_len; ++idx2) { if (!vim_iswhite(line2[idx2])) {
if (!vim_iswhite(line2[idx2])) { if (line1[idx1++] != line2[idx2])
if (line1[idx1++] != line2[idx2]) break;
break; } else
} else while (vim_iswhite(line1[idx1]))
while (vim_iswhite(line1[idx1])) ++idx1;
++idx1;
}
free(line1);
} }
free(line1);
return idx2 == leader2_len && idx1 == leader1_len; return idx2 == leader2_len && idx1 == leader1_len;
} }
@ -4773,8 +4756,7 @@ void write_reg_contents_ex(int name, char_u *str, int maxlen, int must_append, i
char_u *p, *s; char_u *p, *s;
p = vim_strnsave(str, (int)len); p = vim_strnsave(str, (int)len);
if (p == NULL)
return;
if (must_append) { if (must_append) {
s = concat_str(get_expr_line_src(), p); s = concat_str(get_expr_line_src(), p);
free(p); free(p);

View File

@ -2102,7 +2102,8 @@ void set_init_1(void)
p = (char_u *)_(*(char **)options[opt_idx].var); p = (char_u *)_(*(char **)options[opt_idx].var);
else else
p = option_expand(opt_idx, NULL); p = option_expand(opt_idx, NULL);
if (p != NULL && (p = vim_strsave(p)) != NULL) { if (p != NULL) {
p = vim_strsave(p);
*(char_u **)options[opt_idx].var = p; *(char_u **)options[opt_idx].var = p;
/* VIMEXP /* VIMEXP
* Defaults for all expanded options are currently the same for Vi * Defaults for all expanded options are currently the same for Vi
@ -2291,14 +2292,12 @@ void set_string_default(char *name, char_u *val)
int opt_idx; int opt_idx;
p = vim_strsave(val); p = vim_strsave(val);
if (p != NULL) { /* we don't want a NULL */ opt_idx = findoption((char_u *)name);
opt_idx = findoption((char_u *)name); if (opt_idx >= 0) {
if (opt_idx >= 0) { if (options[opt_idx].flags & P_DEF_ALLOCED)
if (options[opt_idx].flags & P_DEF_ALLOCED) free(options[opt_idx].def_val[VI_DEFAULT]);
free(options[opt_idx].def_val[VI_DEFAULT]); options[opt_idx].def_val[VI_DEFAULT] = p;
options[opt_idx].def_val[VI_DEFAULT] = p; options[opt_idx].flags |= P_DEF_ALLOCED;
options[opt_idx].flags |= P_DEF_ALLOCED;
}
} }
} }
@ -2463,7 +2462,7 @@ void set_init_3(void)
p1 = p2 + 1; p1 = p2 + 1;
p = vim_strnsave(p1, (int)(p - p1)); p = vim_strnsave(p1, (int)(p - p1));
} }
if (p != NULL) { {
/* /*
* Default for p_sp is "| tee", for p_srr is ">". * Default for p_sp is "| tee", for p_srr is ">".
* For known shells it is changed here to include stderr. * For known shells it is changed here to include stderr.
@ -2519,16 +2518,12 @@ void set_helplang_default(char_u *lang)
if (options[idx].flags & P_ALLOCED) if (options[idx].flags & P_ALLOCED)
free_string_option(p_hlg); free_string_option(p_hlg);
p_hlg = vim_strsave(lang); p_hlg = vim_strsave(lang);
if (p_hlg == NULL) /* zh_CN becomes "cn", zh_TW becomes "tw". */
p_hlg = empty_option; if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5) {
else { p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
/* zh_CN becomes "cn", zh_TW becomes "tw". */ p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5) {
p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
}
p_hlg[2] = NUL;
} }
p_hlg[2] = NUL;
options[idx].flags |= P_ALLOCED; options[idx].flags |= P_ALLOCED;
} }
} }
@ -3754,7 +3749,7 @@ set_string_option_direct (
return; return;
s = vim_strsave(val); s = vim_strsave(val);
if (s != NULL) { {
varp = (char_u **)get_varp_scope(&(options[idx]), varp = (char_u **)get_varp_scope(&(options[idx]),
both ? OPT_LOCAL : opt_flags); both ? OPT_LOCAL : opt_flags);
if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED)) if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
@ -3795,9 +3790,8 @@ set_string_option_global (
p = (char_u **)GLOBAL_WO(varp); p = (char_u **)GLOBAL_WO(varp);
else else
p = (char_u **)options[opt_idx].var; p = (char_u **)options[opt_idx].var;
if (options[opt_idx].indir != PV_NONE if (options[opt_idx].indir != PV_NONE && p != varp) {
&& p != varp s = vim_strsave(*varp);
&& (s = vim_strsave(*varp)) != NULL) {
free_string_option(*p); free_string_option(*p);
*p = s; *p = s;
} }
@ -3824,18 +3818,17 @@ set_string_option (
return NULL; return NULL;
s = vim_strsave(value); s = vim_strsave(value);
if (s != NULL) { varp = (char_u **)get_varp_scope(&(options[opt_idx]),
varp = (char_u **)get_varp_scope(&(options[opt_idx]), (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
(opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0 ? (((int)options[opt_idx].indir & PV_BOTH)
? (((int)options[opt_idx].indir & PV_BOTH) ? OPT_GLOBAL : OPT_LOCAL)
? OPT_GLOBAL : OPT_LOCAL) : opt_flags);
: opt_flags); oldval = *varp;
oldval = *varp; *varp = s;
*varp = s; if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL, opt_flags)) == NULL)
opt_flags)) == NULL) did_set_option(opt_idx, opt_flags, TRUE);
did_set_option(opt_idx, opt_flags, TRUE);
}
return r; return r;
} }

View File

@ -28,10 +28,7 @@ int os_get_usernames(garray_T *users)
// pw->pw_name shouldn't be NULL but just in case... // pw->pw_name shouldn't be NULL but just in case...
if (pw->pw_name != NULL) { if (pw->pw_name != NULL) {
ga_grow(users, 1); ga_grow(users, 1);
user = (char *)vim_strsave((char_u*)pw->pw_name); user = xstrdup(pw->pw_name);
if (user == NULL) {
return FAIL;
}
((char **)(users->ga_data))[users->ga_len++] = user; ((char **)(users->ga_data))[users->ga_len++] = user;
} }
} }
@ -79,8 +76,7 @@ char *os_get_user_directory(const char *name)
pw = getpwnam(name); pw = getpwnam(name);
if (pw != NULL) { if (pw != NULL) {
// save the string from the static passwd entry into malloced memory // save the string from the static passwd entry into malloced memory
char *user_directory = (char *)vim_strsave((char_u *)pw->pw_dir); return vim_strsave(pw->pw_dir);
return user_directory;
} }
#endif #endif
return NULL; return NULL;

View File

@ -1437,10 +1437,9 @@ char_u ***file;
for (i = 0; i < num_pat; i++) { for (i = 0; i < num_pat; i++) {
s = vim_strsave(pat[i]); s = vim_strsave(pat[i]);
if (s != NULL) /* Be compatible with expand_filename(): halve the number of
/* Be compatible with expand_filename(): halve the number of * backslashes. */
* backslashes. */ backslash_halve(s);
backslash_halve(s);
(*file)[i] = s; (*file)[i] = s;
} }
*num_file = num_pat; *num_file = num_pat;

View File

@ -296,7 +296,7 @@ void add_pathsep(char_u *p)
/* /*
* FullName_save - Make an allocated copy of a full file name. * FullName_save - Make an allocated copy of a full file name.
* Returns NULL when out of memory. * Returns NULL when fname is NULL.
*/ */
char_u * char_u *
FullName_save ( FullName_save (
@ -305,20 +305,19 @@ FullName_save (
* like a full path name */ * like a full path name */
) )
{ {
char_u *buf;
char_u *new_fname = NULL; char_u *new_fname = NULL;
if (fname == NULL) if (fname == NULL)
return NULL; return NULL;
buf = alloc((unsigned)MAXPATHL); char_u *buf = xmalloc(MAXPATHL);
if (buf != NULL) {
if (vim_FullName(fname, buf, MAXPATHL, force) != FAIL) if (vim_FullName(fname, buf, MAXPATHL, force) != FAIL)
new_fname = vim_strsave(buf); new_fname = vim_strsave(buf);
else else
new_fname = vim_strsave(fname); new_fname = vim_strsave(fname);
free(buf); free(buf);
}
return new_fname; return new_fname;
} }
@ -650,8 +649,6 @@ static void expand_path_option(char_u *curdir, garray_T *gap)
ga_grow(gap, 1); ga_grow(gap, 1);
p = vim_strsave(buf); p = vim_strsave(buf);
if (p == NULL)
break;
((char_u **)gap->ga_data)[gap->ga_len++] = p; ((char_u **)gap->ga_data)[gap->ga_len++] = p;
} }
@ -1137,8 +1134,6 @@ expand_backtick (
/* Create the command: lop off the backticks. */ /* Create the command: lop off the backticks. */
cmd = vim_strnsave(pat + 1, (int)STRLEN(pat) - 2); cmd = vim_strnsave(pat + 1, (int)STRLEN(pat) - 2);
if (cmd == NULL)
return 0;
if (*cmd == '=') /* `={expr}`: Expand expression */ if (*cmd == '=') /* `={expr}`: Expand expression */
buffer = eval_to_string(cmd + 1, &p, TRUE); buffer = eval_to_string(cmd + 1, &p, TRUE);
@ -1563,9 +1558,7 @@ char_u *fix_fname(char_u *fname)
fname = vim_strsave(fname); fname = vim_strsave(fname);
# ifdef USE_FNAME_CASE # ifdef USE_FNAME_CASE
if (fname != NULL) { fname_case(fname, 0); // set correct case for file name
fname_case(fname, 0); /* set correct case for file name */
}
# endif # endif
return fname; return fname;

View File

@ -929,19 +929,14 @@ qf_add_entry (
qfp->qf_fnum = bufnum; qfp->qf_fnum = bufnum;
else else
qfp->qf_fnum = qf_get_fnum(dir, fname); qfp->qf_fnum = qf_get_fnum(dir, fname);
if ((qfp->qf_text = vim_strsave(mesg)) == NULL) { qfp->qf_text = vim_strsave(mesg);
free(qfp);
return FAIL;
}
qfp->qf_lnum = lnum; qfp->qf_lnum = lnum;
qfp->qf_col = col; qfp->qf_col = col;
qfp->qf_viscol = vis_col; qfp->qf_viscol = vis_col;
if (pattern == NULL || *pattern == NUL) if (pattern == NULL || *pattern == NUL) {
qfp->qf_pattern = NULL; qfp->qf_pattern = NULL;
else if ((qfp->qf_pattern = vim_strsave(pattern)) == NULL) { } else {
free(qfp->qf_text); qfp->qf_pattern = vim_strsave(pattern);
free(qfp);
return FAIL;
} }
qfp->qf_nr = nr; qfp->qf_nr = nr;
if (type != 1 && !vim_isprintc(type)) /* only printable chars allowed */ if (type != 1 && !vim_isprintc(type)) /* only printable chars allowed */

View File

@ -1141,8 +1141,7 @@ char_u *skip_regexp(char_u *startp, int dirc, int magic, char_u **newp)
/* change "\?" to "?", make a copy first. */ /* change "\?" to "?", make a copy first. */
if (*newp == NULL) { if (*newp == NULL) {
*newp = vim_strsave(startp); *newp = vim_strsave(startp);
if (*newp != NULL) p = *newp + (p - startp);
p = *newp + (p - startp);
} }
if (*newp != NULL) if (*newp != NULL)
STRMOVE(p, p + 1); STRMOVE(p, p + 1);

View File

@ -2479,8 +2479,6 @@ spell_load_file (
// Remember the file name, used to reload the file when it's updated. // Remember the file name, used to reload the file when it's updated.
lp->sl_fname = vim_strsave(fname); lp->sl_fname = vim_strsave(fname);
if (lp->sl_fname == NULL)
goto endFAIL;
// Check for .add.spl. // Check for .add.spl.
lp->sl_add = strstr((char *)path_tail(fname), SPL_FNAME_ADD) != NULL; lp->sl_add = strstr((char *)path_tail(fname), SPL_FNAME_ADD) != NULL;
@ -3669,8 +3667,6 @@ char_u *did_set_spelllang(win_T *wp)
// Make a copy of 'spelllang', the SpellFileMissing autocommands may change // Make a copy of 'spelllang', the SpellFileMissing autocommands may change
// it under our fingers. // it under our fingers.
spl_copy = vim_strsave(wp->w_s->b_p_spl); spl_copy = vim_strsave(wp->w_s->b_p_spl);
if (spl_copy == NULL)
goto theend;
wp->w_s->b_cjk = 0; 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". // Append multi-byte chars to "b_spell_ismw_mb".
n = (int)STRLEN(wp->w_s->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); bp = vim_strnsave(wp->w_s->b_spell_ismw_mb, n + l);
if (bp != NULL) { free(wp->w_s->b_spell_ismw_mb);
free(wp->w_s->b_spell_ismw_mb); wp->w_s->b_spell_ismw_mb = bp;
wp->w_s->b_spell_ismw_mb = bp; vim_strncpy(bp + n, p, l);
vim_strncpy(bp + n, p, l);
}
} }
p += l; p += l;
} else } 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, if (HASHITEM_EMPTY(hash_find(&spin->si_commonwords,
items[i]))) { items[i]))) {
p = vim_strsave(items[i]); p = vim_strsave(items[i]);
if (p == NULL)
break;
hash_add(&spin->si_commonwords, p); hash_add(&spin->si_commonwords, p);
} }
} }
@ -8679,8 +8671,6 @@ void spell_suggest(int count)
// Make a copy of current line since autocommands may free the line. // Make a copy of current line since autocommands may free the line.
line = vim_strsave(ml_get_curline()); line = vim_strsave(ml_get_curline());
if (line == NULL)
goto skip;
// Get the list of suggestions. Limit to 'lines' - 2 or the number in // Get the list of suggestions. Limit to 'lines' - 2 or the number in
// 'spellsuggest', whatever is smaller. // 'spellsuggest', whatever is smaller.
@ -8819,8 +8809,6 @@ void spell_suggest(int count)
curwin->w_cursor = prev_cursor; curwin->w_cursor = prev_cursor;
spell_find_cleanup(&sug); spell_find_cleanup(&sug);
skip:
free(line);
} }
// Check if the word at line "lnum" column "col" is required to start with a // Check if the word at line "lnum" column "col" is required to start with a
@ -9064,8 +9052,6 @@ spell_find_suggest (
// Make a copy of 'spellsuggest', because the expression may change it. // Make a copy of 'spellsuggest', because the expression may change it.
sps_copy = vim_strsave(p_sps); sps_copy = vim_strsave(p_sps);
if (sps_copy == NULL)
return;
// Loop over the items in 'spellsuggest'. // Loop over the items in 'spellsuggest'.
for (p = sps_copy; *p != NUL; ) { for (p = sps_copy; *p != NUL; ) {
@ -11025,13 +11011,11 @@ static void score_comp_sal(suginfo_T *su)
// Add the suggestion. // Add the suggestion.
sstp = &SUG(su->su_sga, su->su_sga.ga_len); sstp = &SUG(su->su_sga, su->su_sga.ga_len);
sstp->st_word = vim_strsave(stp->st_word); sstp->st_word = vim_strsave(stp->st_word);
if (sstp->st_word != NULL) { sstp->st_wordlen = stp->st_wordlen;
sstp->st_wordlen = stp->st_wordlen; sstp->st_score = score;
sstp->st_score = score; sstp->st_altscore = 0;
sstp->st_altscore = 0; sstp->st_orglen = stp->st_orglen;
sstp->st_orglen = stp->st_orglen; ++su->su_sga.ga_len;
++su->su_sga.ga_len;
}
} }
} }
break; break;
@ -11731,25 +11715,23 @@ add_suggestion (
// Add a suggestion. // Add a suggestion.
stp = &SUG(*gap, gap->ga_len); stp = &SUG(*gap, gap->ga_len);
stp->st_word = vim_strnsave(goodword, goodlen); stp->st_word = vim_strnsave(goodword, goodlen);
if (stp->st_word != NULL) { stp->st_wordlen = goodlen;
stp->st_wordlen = goodlen; stp->st_score = score;
stp->st_score = score; stp->st_altscore = altscore;
stp->st_altscore = altscore; stp->st_had_bonus = had_bonus;
stp->st_had_bonus = had_bonus; stp->st_orglen = badlen;
stp->st_orglen = badlen; stp->st_slang = slang;
stp->st_slang = slang; ++gap->ga_len;
++gap->ga_len;
// If we have too many suggestions now, sort the list and keep // If we have too many suggestions now, sort the list and keep
// the best suggestions. // the best suggestions.
if (gap->ga_len > SUG_MAX_COUNT(su)) { if (gap->ga_len > SUG_MAX_COUNT(su)) {
if (maxsf) if (maxsf)
su->su_sfmaxscore = cleanup_suggestions(gap, su->su_sfmaxscore = cleanup_suggestions(gap,
su->su_sfmaxscore, SUG_CLEAN_COUNT(su)); su->su_sfmaxscore, SUG_CLEAN_COUNT(su));
else else
su->su_maxscore = cleanup_suggestions(gap, su->su_maxscore = cleanup_suggestions(gap,
su->su_maxscore, SUG_CLEAN_COUNT(su)); su->su_maxscore, SUG_CLEAN_COUNT(su));
}
} }
} }
} }
@ -11800,8 +11782,7 @@ static void add_banned(suginfo_T *su, char_u *word)
hi = hash_lookup(&su->su_banned, word, hash); hi = hash_lookup(&su->su_banned, word, hash);
if (HASHITEM_EMPTY(hi)) { if (HASHITEM_EMPTY(hi)) {
s = vim_strsave(word); 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);
} }
} }

View File

@ -242,49 +242,45 @@ void vim_strup(char_u *p)
/* /*
* Make string "s" all upper-case and return it in allocated memory. * Make string "s" all upper-case and return it in allocated memory.
* Handles multi-byte characters as well as possible. * Handles multi-byte characters as well as possible.
* Returns NULL when out of memory.
*/ */
char_u *strup_save(char_u *orig) char_u *strup_save(char_u *orig)
{ {
char_u *p; char_u *res = vim_strsave(orig);
char_u *res;
res = p = vim_strsave(orig); char_u *p = res;
while (*p != NUL) {
int l;
if (res != NULL) if (enc_utf8) {
while (*p != NUL) { int c, uc;
int l; int newl;
char_u *s;
if (enc_utf8) { c = utf_ptr2char(p);
int c, uc; uc = utf_toupper(c);
int newl;
char_u *s;
c = utf_ptr2char(p); /* Reallocate string when byte count changes. This is rare,
uc = utf_toupper(c); * thus it's OK to do another malloc()/free(). */
l = utf_ptr2len(p);
/* Reallocate string when byte count changes. This is rare, newl = utf_char2len(uc);
* thus it's OK to do another malloc()/free(). */ if (newl != l) {
l = utf_ptr2len(p); s = alloc((unsigned)STRLEN(res) + 1 + newl - l);
newl = utf_char2len(uc); memmove(s, res, p - res);
if (newl != l) { STRCPY(s + (p - res) + newl, p + l);
s = alloc((unsigned)STRLEN(res) + 1 + newl - l); p = s + (p - res);
memmove(s, res, p - res); free(res);
STRCPY(s + (p - res) + newl, p + l); res = s;
p = s + (p - res);
free(res);
res = s;
}
utf_char2bytes(uc, p);
p += newl;
} else if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1)
p += l; /* skip multi-byte character */
else {
*p = TOUPPER_LOC(*p); /* note that toupper() can be a macro */
p++;
} }
utf_char2bytes(uc, p);
p += newl;
} else if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1)
p += l; /* skip multi-byte character */
else {
*p = TOUPPER_LOC(*p); /* note that toupper() can be a macro */
p++;
} }
}
return res; return res;
} }

View File

@ -4113,8 +4113,6 @@ get_syn_options (
if (gname_start == arg) if (gname_start == arg)
return NULL; return NULL;
gname = vim_strnsave(gname_start, (int)(arg - gname_start)); gname = vim_strnsave(gname_start, (int)(arg - gname_start));
if (gname == NULL)
return NULL;
if (STRCMP(gname, "NONE") == 0) if (STRCMP(gname, "NONE") == 0)
*opt->sync_idx = NONE_IDX; *opt->sync_idx = NONE_IDX;
else { else {
@ -4823,14 +4821,10 @@ static int syn_scl_name2id(char_u *name)
*/ */
static int syn_scl_namen2id(char_u *linep, int len) static int syn_scl_namen2id(char_u *linep, int len)
{ {
char_u *name; char_u *name = vim_strnsave(linep, len);
int id = 0; int id = syn_scl_name2id(name);
free(name);
name = vim_strnsave(linep, len);
if (name != NULL) {
id = syn_scl_name2id(name);
free(name);
}
return id; return id;
} }
@ -4846,8 +4840,6 @@ static int syn_check_cluster(char_u *pp, int len)
char_u *name; char_u *name;
name = vim_strnsave(pp, len); name = vim_strnsave(pp, len);
if (name == NULL)
return 0;
id = syn_scl_name2id(name); id = syn_scl_name2id(name);
if (id == 0) /* doesn't exist yet */ if (id == 0) /* doesn't exist yet */
@ -4996,8 +4988,7 @@ static char_u *get_syn_pattern(char_u *arg, synpat_T *ci)
return NULL; return NULL;
} }
/* store the pattern and compiled regexp program */ /* store the pattern and compiled regexp program */
if ((ci->sp_pattern = vim_strnsave(arg + 1, (int)(end - arg - 1))) == NULL) ci->sp_pattern = vim_strnsave(arg + 1, (int)(end - arg - 1));
return NULL;
/* Make 'cpoptions' empty, to avoid the 'l' flag */ /* Make 'cpoptions' empty, to avoid the 'l' flag */
cpo_save = p_cpo; cpo_save = p_cpo;
@ -5139,11 +5130,8 @@ static void syn_cmd_sync(exarg_T *eap, int syncing)
if (!eap->skip) { if (!eap->skip) {
/* store the pattern and compiled regexp program */ /* store the pattern and compiled regexp program */
if ((curwin->w_s->b_syn_linecont_pat = vim_strnsave(next_arg + 1, curwin->w_s->b_syn_linecont_pat =
(int)(arg_end - next_arg - 1))) == NULL) { vim_strnsave(next_arg + 1, (int)(arg_end - next_arg - 1));
finished = TRUE;
break;
}
curwin->w_s->b_syn_linecont_ic = curwin->w_s->b_syn_ic; curwin->w_s->b_syn_linecont_ic = curwin->w_s->b_syn_ic;
/* Make 'cpoptions' empty, to avoid the 'l' flag */ /* Make 'cpoptions' empty, to avoid the 'l' flag */
@ -5518,24 +5506,22 @@ void ex_syntax(exarg_T *eap)
for (subcmd_end = arg; ASCII_ISALPHA(*subcmd_end); ++subcmd_end) for (subcmd_end = arg; ASCII_ISALPHA(*subcmd_end); ++subcmd_end)
; ;
subcmd_name = vim_strnsave(arg, (int)(subcmd_end - arg)); subcmd_name = vim_strnsave(arg, (int)(subcmd_end - arg));
if (subcmd_name != NULL) { if (eap->skip) /* skip error messages for all subcommands */
if (eap->skip) /* skip error messages for all subcommands */ ++emsg_skip;
++emsg_skip; for (i = 0;; ++i) {
for (i = 0;; ++i) { if (subcommands[i].name == NULL) {
if (subcommands[i].name == NULL) { EMSG2(_("E410: Invalid :syntax subcommand: %s"), subcmd_name);
EMSG2(_("E410: Invalid :syntax subcommand: %s"), subcmd_name); break;
break; }
} if (STRCMP(subcmd_name, (char_u *)subcommands[i].name) == 0) {
if (STRCMP(subcmd_name, (char_u *)subcommands[i].name) == 0) { eap->arg = skipwhite(subcmd_end);
eap->arg = skipwhite(subcmd_end); (subcommands[i].func)(eap, FALSE);
(subcommands[i].func)(eap, FALSE); break;
break;
}
} }
free(subcmd_name);
if (eap->skip)
--emsg_skip;
} }
free(subcmd_name);
if (eap->skip)
--emsg_skip;
} }
void ex_ownsyntax(exarg_T *eap) void ex_ownsyntax(exarg_T *eap)
@ -6392,10 +6378,6 @@ do_highlight (
++linep; ++linep;
free(key); free(key);
key = vim_strnsave_up(key_start, (int)(linep - key_start)); key = vim_strnsave_up(key_start, (int)(linep - key_start));
if (key == NULL) {
error = TRUE;
break;
}
linep = skipwhite(linep); linep = skipwhite(linep);
if (STRCMP(key, "NONE") == 0) { if (STRCMP(key, "NONE") == 0) {
@ -6440,10 +6422,7 @@ do_highlight (
} }
free(arg); free(arg);
arg = vim_strnsave(arg_start, (int)(linep - arg_start)); arg = vim_strnsave(arg_start, (int)(linep - arg_start));
if (arg == NULL) {
error = TRUE;
break;
}
if (*linep == '\'') if (*linep == '\'')
++linep; ++linep;
@ -6725,10 +6704,6 @@ do_highlight (
arg[off + len] != ','; ++len) arg[off + len] != ','; ++len)
; ;
tname = vim_strnsave(arg + off, len); tname = vim_strnsave(arg + off, len);
if (tname == NULL) { /* out of memory */
error = TRUE;
break;
}
/* lookup the escape sequence for the item */ /* lookup the escape sequence for the item */
p = get_term_code(tname); p = get_term_code(tname);
free(tname); free(tname);
@ -7410,14 +7385,10 @@ char_u *syn_id2name(int id)
*/ */
int syn_namen2id(char_u *linep, int len) int syn_namen2id(char_u *linep, int len)
{ {
char_u *name; char_u *name = vim_strnsave(linep, len);
int id = 0; int id = syn_name2id(name);
free(name);
name = vim_strnsave(linep, len);
if (name != NULL) {
id = syn_name2id(name);
free(name);
}
return id; return id;
} }
@ -7433,8 +7404,6 @@ int syn_check_group(char_u *pp, int len)
char_u *name; char_u *name;
name = vim_strnsave(pp, len); name = vim_strnsave(pp, len);
if (name == NULL)
return 0;
id = syn_name2id(name); id = syn_name2id(name);
if (id == 0) /* doesn't exist yet */ if (id == 0) /* doesn't exist yet */

View File

@ -236,8 +236,7 @@ do_tag (
cur_fnum = ptag_entry.cur_fnum; cur_fnum = ptag_entry.cur_fnum;
} else { } else {
free(ptag_entry.tagname); free(ptag_entry.tagname);
if ((ptag_entry.tagname = vim_strsave(tag)) == NULL) ptag_entry.tagname = vim_strsave(tag);
goto end_do_tag;
} }
} else { } else {
/* /*
@ -256,13 +255,9 @@ do_tag (
--tagstackidx; --tagstackidx;
} }
/* // put the tag name in the tag stack
* put the tag name in the tag stack tagstack[tagstackidx].tagname = vim_strsave(tag);
*/
if ((tagstack[tagstackidx].tagname = vim_strsave(tag)) == NULL) {
curwin->w_tagstacklen = tagstacklen - 1;
goto end_do_tag;
}
curwin->w_tagstacklen = tagstacklen; curwin->w_tagstacklen = tagstacklen;
save_pos = TRUE; /* save the cursor position below */ save_pos = TRUE; /* save the cursor position below */
@ -1211,11 +1206,9 @@ find_tags (
&& ASCII_ISALPHA(pat[orgpat.len - 2]) && ASCII_ISALPHA(pat[orgpat.len - 2])
&& ASCII_ISALPHA(pat[orgpat.len - 1])) { && ASCII_ISALPHA(pat[orgpat.len - 1])) {
saved_pat = vim_strnsave(pat, orgpat.len - 3); saved_pat = vim_strnsave(pat, orgpat.len - 3);
if (saved_pat != NULL) { help_lang_find = &pat[orgpat.len - 2];
help_lang_find = &pat[orgpat.len - 2]; orgpat.pat = saved_pat;
orgpat.pat = saved_pat; orgpat.len -= 3;
orgpat.len -= 3;
}
} }
} }
if (p_tl != 0 && orgpat.len > p_tl) /* adjust for 'taglength' */ if (p_tl != 0 && orgpat.len > p_tl) /* adjust for 'taglength' */
@ -2099,8 +2092,6 @@ get_tagfname (
* the value without notifying us. */ * the value without notifying us. */
tnp->tn_tags = vim_strsave((*curbuf->b_p_tags != NUL) tnp->tn_tags = vim_strsave((*curbuf->b_p_tags != NUL)
? curbuf->b_p_tags : p_tags); ? curbuf->b_p_tags : p_tags);
if (tnp->tn_tags == NULL)
return FAIL;
tnp->tn_np = tnp->tn_tags; tnp->tn_np = tnp->tn_tags;
} }
@ -2435,8 +2426,6 @@ jumpto_tag (
retval = NOTAGFILE; retval = NOTAGFILE;
free(nofile_fname); free(nofile_fname);
nofile_fname = vim_strsave(fname); nofile_fname = vim_strsave(fname);
if (nofile_fname == NULL)
nofile_fname = empty_option;
goto erret; goto erret;
} }

View File

@ -1198,15 +1198,13 @@ static void parse_builtin_tcap(char_u *term)
char_u *s, *t; char_u *s, *t;
s = vim_strsave((char_u *)p->bt_string); s = vim_strsave((char_u *)p->bt_string);
if (s != NULL) { for (t = s; *t; ++t)
for (t = s; *t; ++t) if (term_7to8bit(t)) {
if (term_7to8bit(t)) { *t = term_7to8bit(t);
*t = term_7to8bit(t); STRCPY(t + 1, t + 2);
STRCPY(t + 1, t + 2); }
} term_strings[p->bt_entry] = s;
term_strings[p->bt_entry] = s; set_term_option_alloced(&term_strings[p->bt_entry]);
set_term_option_alloced(&term_strings[p->bt_entry]);
}
} else } else
term_strings[p->bt_entry] = (char_u *)p->bt_string; term_strings[p->bt_entry] = (char_u *)p->bt_string;
} }
@ -2970,8 +2968,6 @@ void add_termcode(char_u *name, char_u *string, int flags)
} }
s = vim_strsave(string); s = vim_strsave(string);
if (s == NULL)
return;
/* Change leading <Esc>[ to CSI, change <Esc>O to <M-O>. */ /* Change leading <Esc>[ to CSI, change <Esc>O to <M-O>. */
if (flags != 0 && flags != ATC_FROM_TERM && term_7to8bit(string) != 0) { if (flags != 0 && flags != ATC_FROM_TERM && term_7to8bit(string) != 0) {
@ -4313,8 +4309,8 @@ replace_termcodes (
* Copy the new string to allocated memory. * Copy the new string to allocated memory.
* If this fails, just return from. * If this fails, just return from.
*/ */
if ((*bufp = vim_strsave(result)) != NULL) *bufp = vim_strsave(result);
from = *bufp; from = *bufp;
free(result); free(result);
return from; return from;
} }

View File

@ -700,8 +700,6 @@ char_u *u_get_undo_file_name(char_u *buf_ffname, int reading)
/* Use same directory as the ffname, /* Use same directory as the ffname,
* "dir/name" -> "dir/.name.un~" */ * "dir/name" -> "dir/.name.un~" */
undo_file_name = vim_strnsave(ffname, (int)(STRLEN(ffname) + 5)); undo_file_name = vim_strnsave(ffname, (int)(STRLEN(ffname) + 5));
if (undo_file_name == NULL)
break;
p = path_tail(undo_file_name); p = path_tail(undo_file_name);
memmove(p + 1, p, STRLEN(p) + 1); memmove(p + 1, p, STRLEN(p) + 1);
*p = '.'; *p = '.';
@ -711,8 +709,6 @@ char_u *u_get_undo_file_name(char_u *buf_ffname, int reading)
if (os_isdir(dir_name)) { if (os_isdir(dir_name)) {
if (munged_name == NULL) { if (munged_name == NULL) {
munged_name = vim_strsave(ffname); munged_name = vim_strsave(ffname);
if (munged_name == NULL)
return NULL;
for (p = munged_name; *p != NUL; mb_ptr_adv(p)) for (p = munged_name; *p != NUL; mb_ptr_adv(p))
if (vim_ispathsep(*p)) if (vim_ispathsep(*p))
*p = '%'; *p = '%';