Merge #708 'Remove NULL/non-NULL tests after vim_str(n)save'

- replace alloc with xmalloc
This commit is contained in:
Justin M. Keyes 2014-05-22 12:50:59 -04:00
commit e2e47803bd
55 changed files with 937 additions and 1643 deletions

View File

@ -2235,9 +2235,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
@ -4114,8 +4113,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

@ -1910,10 +1910,8 @@ void backslash_halve(char_u *p)
/// @return String with the number of backslashes halved. /// @return String with the number of backslashes halved.
char_u* backslash_halve_save(char_u *p) char_u* backslash_halve_save(char_u *p)
{ {
// TODO(philix): simplify and improve backslash_halve_save algorithm
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,11 +968,8 @@ 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));
if (newname != NULL) {
STRCAT(newname, ".new"); 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
cmdmod.tab = 0; cmdmod.tab = 0;
@ -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,7 +2270,6 @@ 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++;
@ -2294,7 +2280,6 @@ void ex_diffgetput(exarg_T *eap)
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;
dp->df_count[idx_to] = new_count; dp->df_count[idx_to] = new_count;

View File

@ -1738,28 +1738,24 @@ char_u* keymap_init(void)
keymap_unload(); keymap_unload();
do_cmdline_cmd((char_u *)"unlet! b:keymap_name"); do_cmdline_cmd((char_u *)"unlet! b:keymap_name");
} else { } else {
char_u *buf; char *buf;
size_t buflen; size_t buflen;
// Source the keymap file. It will contain a ":loadkeymap" command // Source the keymap file. It will contain a ":loadkeymap" command
// which will call ex_loadkeymap() below. // which will call ex_loadkeymap() below.
buflen = STRLEN(curbuf->b_p_keymap) + STRLEN(p_enc) + 14; buflen = STRLEN(curbuf->b_p_keymap) + STRLEN(p_enc) + 14;
buf = alloc((unsigned)buflen); buf = xmalloc(buflen);
if (buf == NULL) {
return e_outofmem;
}
// try finding "keymap/'keymap'_'encoding'.vim" in 'runtimepath' // try finding "keymap/'keymap'_'encoding'.vim" in 'runtimepath'
vim_snprintf((char *)buf, buflen, "keymap/%s_%s.vim", vim_snprintf(buf, buflen, "keymap/%s_%s.vim",
curbuf->b_p_keymap, p_enc); curbuf->b_p_keymap, p_enc);
if (source_runtime(buf, FALSE) == FAIL) { if (source_runtime((char_u *)buf, FALSE) == FAIL) {
// try finding "keymap/'keymap'.vim" in 'runtimepath' // try finding "keymap/'keymap'.vim" in 'runtimepath'
vim_snprintf((char *)buf, buflen, "keymap/%s.vim", vim_snprintf(buf, buflen, "keymap/%s.vim",
curbuf->b_p_keymap); curbuf->b_p_keymap);
if (source_runtime(buf, FALSE) == FAIL) { if (source_runtime((char_u *)buf, FALSE) == FAIL) {
free(buf); free(buf);
return (char_u *)N_("E544: Keymap file not found"); return (char_u *)N_("E544: Keymap file not found");
} }
@ -1818,12 +1814,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,7 +2205,6 @@ 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());
@ -2221,7 +2215,6 @@ static void ins_compl_longest_match(compl_T *match)
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,15 +2867,13 @@ 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;
}
/* /*
* Return TRUE when we need to find matches again, ins_compl_restart() is to * Return TRUE when we need to find matches again, ins_compl_restart() is to
@ -2980,7 +2972,6 @@ 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);
if (p != NULL) {
free(compl_first_match->cp_str); free(compl_first_match->cp_str);
compl_first_match->cp_str = p; compl_first_match->cp_str = vim_strsave(str);
}
} }
} }
@ -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

@ -1040,8 +1040,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));
@ -1457,12 +1455,11 @@ int get_spellword(list_T *list, char_u **pp)
*/ */
typval_T *eval_expr(char_u *arg, char_u **nextcmd) typval_T *eval_expr(char_u *arg, char_u **nextcmd)
{ {
typval_T *tv; typval_T *tv = xmalloc(sizeof(typval_T));
tv = (typval_T *)alloc(sizeof(typval_T)); if (eval0(arg, tv, nextcmd, TRUE) == FAIL) {
if (tv != NULL && eval0(arg, tv, nextcmd, TRUE) == FAIL) {
free(tv); free(tv);
tv = NULL; return NULL;
} }
return tv; return tv;
@ -1485,7 +1482,6 @@ call_vim_function (
typval_T *rettv typval_T *rettv
) )
{ {
typval_T *argvars;
long n; long n;
int len; int len;
int i; int i;
@ -1493,9 +1489,7 @@ call_vim_function (
void *save_funccalp = NULL; void *save_funccalp = NULL;
int ret; int ret;
argvars = (typval_T *)alloc((unsigned)((argc + 1) * sizeof(typval_T))); typval_T *argvars = xmalloc((argc + 1) * sizeof(typval_T));
if (argvars == NULL)
return FAIL;
for (i = 0; i < argc; i++) { for (i = 0; i < argc; i++) {
/* Pass a NULL or empty argument as an empty string */ /* Pass a NULL or empty argument as an empty string */
@ -2541,8 +2535,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 */
@ -3429,20 +3421,19 @@ void del_menutrans_vars(void)
static char_u *cat_prefix_varname(int prefix, char_u *name); static char_u *cat_prefix_varname(int prefix, char_u *name);
static char_u *varnamebuf = NULL; static char_u *varnamebuf = NULL;
static int varnamebuflen = 0; static size_t varnamebuflen = 0;
/* /*
* Function to concatenate a prefix and a variable name. * Function to concatenate a prefix and a variable name.
*/ */
static char_u *cat_prefix_varname(int prefix, char_u *name) static char_u *cat_prefix_varname(int prefix, char_u *name)
{ {
int len; size_t len = STRLEN(name) + 3;
len = (int)STRLEN(name) + 3;
if (len > varnamebuflen) { if (len > varnamebuflen) {
free(varnamebuf); free(varnamebuf);
len += 10; /* some additional space */ len += 10; /* some additional space */
varnamebuf = alloc(len); varnamebuf = xmalloc(len);
if (varnamebuf == NULL) { if (varnamebuf == NULL) {
varnamebuflen = 0; varnamebuflen = 0;
return NULL; return NULL;
@ -4924,9 +4915,7 @@ static int get_string_tv(char_u **arg, typval_T *rettv, int evaluate)
* Copy the string into allocated memory, handling backslashed * Copy the string into allocated memory, handling backslashed
* characters. * characters.
*/ */
name = alloc((unsigned)(p - *arg + extra)); name = xmalloc(p - *arg + extra);
if (name == NULL)
return FAIL;
rettv->v_type = VAR_STRING; rettv->v_type = VAR_STRING;
rettv->vval.v_string = name; rettv->vval.v_string = name;
@ -5041,9 +5030,7 @@ static int get_lit_string_tv(char_u **arg, typval_T *rettv, int evaluate)
/* /*
* Copy the string into allocated memory, handling '' to ' reduction. * Copy the string into allocated memory, handling '' to ' reduction.
*/ */
str = alloc((unsigned)((p - *arg) - reduce)); str = xmalloc((p - *arg) - reduce);
if (str == NULL)
return FAIL;
rettv->v_type = VAR_STRING; rettv->v_type = VAR_STRING;
rettv->vval.v_string = str; rettv->vval.v_string = str;
@ -5192,7 +5179,7 @@ list_free (
*/ */
listitem_T *listitem_alloc(void) listitem_T *listitem_alloc(void)
{ {
return (listitem_T *)alloc(sizeof(listitem_T)); return xmalloc(sizeof(listitem_T));
} }
/* /*
@ -6157,17 +6144,12 @@ dict_free (
* Allocate a Dictionary item. * Allocate a Dictionary item.
* The "key" is copied to the new item. * The "key" is copied to the new item.
* Note that the value of the item "di_tv" still needs to be initialized! * Note that the value of the item "di_tv" still needs to be initialized!
* Returns NULL when out of memory.
*/ */
dictitem_T *dictitem_alloc(char_u *key) dictitem_T *dictitem_alloc(char_u *key)
{ {
dictitem_T *di; dictitem_T *di = xmalloc(sizeof(dictitem_T) + STRLEN(key));
di = (dictitem_T *)alloc((unsigned)(sizeof(dictitem_T) + STRLEN(key)));
if (di != NULL) {
STRCPY(di->di_key, key); STRCPY(di->di_key, key);
di->di_flags = 0; di->di_flags = 0;
}
return di; return di;
} }
@ -6176,15 +6158,12 @@ dictitem_T *dictitem_alloc(char_u *key)
*/ */
static dictitem_T *dictitem_copy(dictitem_T *org) static dictitem_T *dictitem_copy(dictitem_T *org)
{ {
dictitem_T *di; dictitem_T *di = xmalloc(sizeof(dictitem_T) + STRLEN(org->di_key));
di = (dictitem_T *)alloc((unsigned)(sizeof(dictitem_T)
+ STRLEN(org->di_key)));
if (di != NULL) {
STRCPY(di->di_key, org->di_key); STRCPY(di->di_key, org->di_key);
di->di_flags = 0; di->di_flags = 0;
copy_tv(&org->di_tv, &di->di_tv); copy_tv(&org->di_tv, &di->di_tv);
}
return di; return di;
} }
@ -6352,8 +6331,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);
@ -6673,18 +6650,17 @@ static char_u *tv2string(typval_T *tv, char_u **tofree, char_u *numbuf, int copy
*/ */
static char_u *string_quote(char_u *str, int function) static char_u *string_quote(char_u *str, int function)
{ {
unsigned len;
char_u *p, *r, *s; char_u *p, *r, *s;
len = (function ? 13 : 3); size_t len = (function ? 13 : 3);
if (str != NULL) { if (str != NULL) {
len += (unsigned)STRLEN(str); len += STRLEN(str);
for (p = str; *p != NUL; mb_ptr_adv(p)) for (p = str; *p != NUL; mb_ptr_adv(p))
if (*p == '\'') if (*p == '\'')
++len; ++len;
} }
s = r = alloc(len); s = r = xmalloc(len);
if (r != NULL) {
if (function) { if (function) {
STRCPY(r, "function('"); STRCPY(r, "function('");
r += 10; r += 10;
@ -6700,7 +6676,7 @@ static char_u *string_quote(char_u *str, int function)
if (function) if (function)
*r++ = ')'; *r++ = ')';
*r++ = NUL; *r++ = NUL;
}
return s; return s;
} }
@ -7262,8 +7238,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().
@ -7288,14 +7262,10 @@ call_func (
STRCPY(fname_buf + i, name + llen); STRCPY(fname_buf + i, name + llen);
fname = fname_buf; fname = fname_buf;
} else { } else {
fname = alloc((unsigned)(i + STRLEN(name + llen) + 1)); fname = xmalloc(i + STRLEN(name + llen) + 1);
if (fname == NULL)
error = ERROR_OTHER;
else {
memmove(fname, fname_buf, (size_t)i); memmove(fname, fname_buf, (size_t)i);
STRCPY(fname + i, name + llen); STRCPY(fname + i, name + llen);
} }
}
} else } else
fname = name; fname = name;
@ -9257,11 +9227,10 @@ static void f_foldtext(typval_T *argvars, typval_T *rettv)
} }
} }
txt = _("+-%s%3ld lines: "); txt = _("+-%s%3ld lines: ");
r = alloc((unsigned)(STRLEN(txt) r = xmalloc(STRLEN(txt)
+ STRLEN(vimvars[VV_FOLDDASHES].vv_str) /* for %s */ + STRLEN(vimvars[VV_FOLDDASHES].vv_str) // for %s
+ 20 /* for %3ld */ + 20 // for %3ld
+ STRLEN(s))); /* concatenated */ + STRLEN(s)); // concatenated
if (r != NULL) {
sprintf((char *)r, txt, vimvars[VV_FOLDDASHES].vv_str, sprintf((char *)r, txt, vimvars[VV_FOLDDASHES].vv_str,
(long)((linenr_T)vimvars[VV_FOLDEND].vv_nr (long)((linenr_T)vimvars[VV_FOLDEND].vv_nr
- (linenr_T)vimvars[VV_FOLDSTART].vv_nr + 1)); - (linenr_T)vimvars[VV_FOLDSTART].vv_nr + 1));
@ -9272,7 +9241,6 @@ static void f_foldtext(typval_T *argvars, typval_T *rettv)
rettv->vval.v_string = r; rettv->vval.v_string = r;
} }
} }
}
/* /*
* "foldtextresult(lnum)" function * "foldtextresult(lnum)" function
@ -9331,12 +9299,9 @@ static void f_function(typval_T *argvars, typval_T *rettv)
* would also work, but some plugins depend on the name being * would also work, but some plugins depend on the name being
* printable text. */ * printable text. */
sprintf(sid_buf, "<SNR>%" PRId64 "_", (int64_t)current_SID); sprintf(sid_buf, "<SNR>%" PRId64 "_", (int64_t)current_SID);
rettv->vval.v_string = rettv->vval.v_string = xmalloc(STRLEN(sid_buf) + STRLEN(s + off) + 1);
alloc((int)(STRLEN(sid_buf) + STRLEN(s + off) + 1));
if (rettv->vval.v_string != NULL) {
STRCPY(rettv->vval.v_string, sid_buf); STRCPY(rettv->vval.v_string, sid_buf);
STRCAT(rettv->vval.v_string, s + off); STRCAT(rettv->vval.v_string, s + off);
}
} else } else
rettv->vval.v_string = vim_strsave(s); rettv->vval.v_string = vim_strsave(s);
rettv->v_type = VAR_FUNC; rettv->v_type = VAR_FUNC;
@ -9625,11 +9590,8 @@ static void f_getcmdpos(typval_T *argvars, typval_T *rettv)
static void f_getcmdtype(typval_T *argvars, typval_T *rettv) static void f_getcmdtype(typval_T *argvars, typval_T *rettv)
{ {
rettv->v_type = VAR_STRING; rettv->v_type = VAR_STRING;
rettv->vval.v_string = alloc(2); rettv->vval.v_string = xmallocz(1);
if (rettv->vval.v_string != NULL) {
rettv->vval.v_string[0] = get_cmdline_type(); rettv->vval.v_string[0] = get_cmdline_type();
rettv->vval.v_string[1] = NUL;
}
} }
/* /*
@ -9641,18 +9603,15 @@ static void f_getcwd(typval_T *argvars, typval_T *rettv)
rettv->v_type = VAR_STRING; rettv->v_type = VAR_STRING;
rettv->vval.v_string = NULL; rettv->vval.v_string = NULL;
cwd = alloc(MAXPATHL); cwd = xmalloc(MAXPATHL);
if (cwd != NULL) {
if (os_dirname(cwd, MAXPATHL) != FAIL) { if (os_dirname(cwd, MAXPATHL) != FAIL) {
rettv->vval.v_string = vim_strsave(cwd); rettv->vval.v_string = vim_strsave(cwd);
#ifdef BACKSLASH_IN_FILENAME #ifdef BACKSLASH_IN_FILENAME
if (rettv->vval.v_string != NULL)
slash_adjust(rettv->vval.v_string); slash_adjust(rettv->vval.v_string);
#endif #endif
} }
free(cwd); free(cwd);
} }
}
/* /*
* "getfontname()" function * "getfontname()" function
@ -9675,13 +9634,11 @@ 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;
rettv->vval.v_string = perm; rettv->vval.v_string = perm;
} }
@ -11758,8 +11715,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)
@ -11971,7 +11926,6 @@ static void f_printf(typval_T *argvars, typval_T *rettv)
{ {
char_u buf[NUMBUFLEN]; char_u buf[NUMBUFLEN];
int len; int len;
char_u *s;
int saved_did_emsg = did_emsg; int saved_did_emsg = did_emsg;
char *fmt; char *fmt;
@ -11980,11 +11934,9 @@ static void f_printf(typval_T *argvars, typval_T *rettv)
fmt = (char *)get_tv_string_buf(&argvars[0], buf); fmt = (char *)get_tv_string_buf(&argvars[0], buf);
len = vim_vsnprintf(NULL, 0, fmt, ap, argvars + 1); len = vim_vsnprintf(NULL, 0, fmt, ap, argvars + 1);
if (!did_emsg) { if (!did_emsg) {
s = alloc(len + 1); char *s = xmalloc(len + 1);
if (s != NULL) { rettv->vval.v_string = (char_u *)s;
rettv->vval.v_string = s; (void)vim_vsnprintf(s, len + 1, fmt, ap, argvars + 1);
(void)vim_vsnprintf((char *)s, len + 1, fmt, ap, argvars + 1);
}
} }
did_emsg |= saved_did_emsg; did_emsg |= saved_did_emsg;
} }
@ -12104,18 +12056,12 @@ 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) {
free(s); free(s);
@ -12174,8 +12120,6 @@ static void f_readfile(typval_T *argvars, typval_T *rettv)
if (start < p) { if (start < p) {
/* There's part of a line in buf, store it in "prev". */ /* There's part of a line in buf, store it in "prev". */
if (p - start + prevlen >= prevsize) { if (p - start + prevlen >= prevsize) {
/* need bigger "prev" buffer */
char_u *newprev;
/* A common use case is ordinary text files and "prev" gets a /* A common use case is ordinary text files and "prev" gets a
* fragment of a line, so the first allocation is made * fragment of a line, so the first allocation is made
@ -12188,14 +12132,7 @@ static void f_readfile(typval_T *argvars, typval_T *rettv)
long growmin = (long)((p - start) * 2 + prevlen); long growmin = (long)((p - start) * 2 + prevlen);
prevsize = grow50pc > growmin ? grow50pc : growmin; prevsize = grow50pc > growmin ? grow50pc : growmin;
} }
newprev = prev == NULL ? alloc(prevsize) prev = xrealloc(prev, prevsize);
: xrealloc(prev, prevsize);
if (newprev == NULL) {
do_outofmem_msg((long_u)prevsize);
failed = TRUE;
break;
}
prev = newprev;
} }
/* Add the line part to end of "prev". */ /* Add the line part to end of "prev". */
memmove(prev + prevlen, start, p - start); memmove(prev + prevlen, start, p - start);
@ -12432,10 +12369,6 @@ static void f_repeat(typval_T *argvars, typval_T *rettv)
{ {
char_u *p; char_u *p;
int n; int n;
int slen;
int len;
char_u *r;
int i;
n = get_tv_number(&argvars[1]); n = get_tv_number(&argvars[1]);
if (argvars[0].v_type == VAR_LIST) { if (argvars[0].v_type == VAR_LIST) {
@ -12453,17 +12386,14 @@ static void f_repeat(typval_T *argvars, typval_T *rettv)
rettv->v_type = VAR_STRING; rettv->v_type = VAR_STRING;
rettv->vval.v_string = NULL; rettv->vval.v_string = NULL;
slen = (int)STRLEN(p); int slen = (int)STRLEN(p);
len = slen * n; int len = slen * n;
if (len <= 0) if (len <= 0)
return; return;
r = alloc(len + 1); char_u *r = xmallocz(len);
if (r != NULL) { for (int i = 0; i < n; i++)
for (i = 0; i < n; i++)
memmove(r + i * slen, p, (size_t)slen); memmove(r + i * slen, p, (size_t)slen);
r[len] = NUL;
}
rettv->vval.v_string = r; rettv->vval.v_string = r;
} }
@ -12521,9 +12451,7 @@ static void f_resolve(typval_T *argvars, typval_T *rettv)
q[-1] = NUL; q[-1] = NUL;
} }
buf = alloc(MAXPATHL + 1); buf = xmallocz(MAXPATHL);
if (buf == NULL)
goto fail;
for (;; ) { for (;; ) {
for (;; ) { for (;; ) {
@ -12569,13 +12497,11 @@ static void f_resolve(typval_T *argvars, typval_T *rettv)
} }
if (q > p && !path_is_absolute_path(buf)) { if (q > p && !path_is_absolute_path(buf)) {
/* symlink is relative to directory of argument */ /* symlink is relative to directory of argument */
cpy = alloc((unsigned)(STRLEN(p) + STRLEN(buf) + 1)); cpy = xmalloc(STRLEN(p) + STRLEN(buf) + 1);
if (cpy != NULL) {
STRCPY(cpy, p); STRCPY(cpy, p);
STRCPY(path_tail(cpy), buf); STRCPY(path_tail(cpy), buf);
free(p); free(p);
p = cpy; p = cpy;
}
} else { } else {
free(p); free(p);
p = vim_strsave(buf); p = vim_strsave(buf);
@ -12589,11 +12515,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);
@ -13083,10 +13008,8 @@ do_searchpair (
/* Make two search patterns: start/end (pat2, for in nested pairs) and /* Make two search patterns: start/end (pat2, for in nested pairs) and
* start/middle/end (pat3, for the top pair). */ * start/middle/end (pat3, for the top pair). */
pat2 = alloc((unsigned)(STRLEN(spat) + STRLEN(epat) + 15)); pat2 = xmalloc(STRLEN(spat) + STRLEN(epat) + 15);
pat3 = alloc((unsigned)(STRLEN(spat) + STRLEN(mpat) + STRLEN(epat) + 23)); pat3 = xmalloc(STRLEN(spat) + STRLEN(mpat) + STRLEN(epat) + 23);
if (pat2 == NULL || pat3 == NULL)
goto theend;
sprintf((char *)pat2, "\\(%s\\m\\)\\|\\(%s\\m\\)", spat, epat); sprintf((char *)pat2, "\\(%s\\m\\)\\|\\(%s\\m\\)", spat, epat);
if (*mpat == NUL) if (*mpat == NUL)
STRCPY(pat3, pat2); STRCPY(pat3, pat2);
@ -13177,7 +13100,6 @@ do_searchpair (
if ((flags & SP_NOMOVE) || retval == 0) if ((flags & SP_NOMOVE) || retval == 0)
curwin->w_cursor = save_cursor; curwin->w_cursor = save_cursor;
theend:
free(pat2); free(pat2);
free(pat3); free(pat3);
if (p_cpo == empty_option) if (p_cpo == empty_option)
@ -13261,14 +13183,12 @@ static void f_setbufvar(typval_T *argvars, typval_T *rettv)
if (!error && strval != NULL) if (!error && strval != NULL)
set_option_value(varname, numval, strval, OPT_LOCAL); set_option_value(varname, numval, strval, OPT_LOCAL);
} else { } else {
bufvarname = alloc((unsigned)STRLEN(varname) + 3); bufvarname = xmalloc(STRLEN(varname) + 3);
if (bufvarname != NULL) {
STRCPY(bufvarname, "b:"); STRCPY(bufvarname, "b:");
STRCPY(bufvarname + 2, varname); STRCPY(bufvarname + 2, varname);
set_var(bufvarname, varp, TRUE); set_var(bufvarname, varp, TRUE);
free(bufvarname); free(bufvarname);
} }
}
/* reset notion of buffer */ /* reset notion of buffer */
aucmd_restbuf(&aco); aucmd_restbuf(&aco);
@ -13573,13 +13493,11 @@ static void f_settabvar(typval_T *argvars, typval_T *rettv)
save_curtab = curtab; save_curtab = curtab;
goto_tabpage_tp(tp, FALSE, FALSE); goto_tabpage_tp(tp, FALSE, FALSE);
tabvarname = alloc((unsigned)STRLEN(varname) + 3); tabvarname = xmalloc(STRLEN(varname) + 3);
if (tabvarname != NULL) {
STRCPY(tabvarname, "t:"); STRCPY(tabvarname, "t:");
STRCPY(tabvarname + 2, varname); STRCPY(tabvarname + 2, varname);
set_var(tabvarname, varp, TRUE); set_var(tabvarname, varp, TRUE);
free(tabvarname); free(tabvarname);
}
/* Restore current tabpage */ /* Restore current tabpage */
if (valid_tabpage(save_curtab)) if (valid_tabpage(save_curtab))
@ -13643,14 +13561,12 @@ static void setwinvar(typval_T *argvars, typval_T *rettv, int off)
if (!error && strval != NULL) if (!error && strval != NULL)
set_option_value(varname, numval, strval, OPT_LOCAL); set_option_value(varname, numval, strval, OPT_LOCAL);
} else { } else {
winvarname = alloc((unsigned)STRLEN(varname) + 3); winvarname = xmalloc(STRLEN(varname) + 3);
if (winvarname != NULL) {
STRCPY(winvarname, "w:"); STRCPY(winvarname, "w:");
STRCPY(winvarname + 2, varname); STRCPY(winvarname + 2, varname);
set_var(winvarname, varp, TRUE); set_var(winvarname, varp, TRUE);
free(winvarname); free(winvarname);
} }
}
restore_win(save_curwin, save_curtab, TRUE); restore_win(save_curwin, save_curtab, TRUE);
} }
@ -14831,7 +14747,7 @@ static void f_tagfiles(typval_T *argvars, typval_T *rettv)
tagname_T tn; tagname_T tn;
rettv_list_alloc(rettv); rettv_list_alloc(rettv);
fname = alloc(MAXPATHL); fname = xmalloc(MAXPATHL);
int first = TRUE; int first = TRUE;
while (get_tagfname(&tn, first, fname) == OK) { while (get_tagfname(&tn, first, fname) == OK) {
@ -14924,13 +14840,10 @@ 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;
@ -15773,14 +15686,12 @@ static char_u *make_expanded_name(char_u *in_start, char_u *expr_start, char_u *
temp_result = eval_to_string(expr_start + 1, &nextcmd, FALSE); temp_result = eval_to_string(expr_start + 1, &nextcmd, FALSE);
if (temp_result != NULL && nextcmd == NULL) { if (temp_result != NULL && nextcmd == NULL) {
retval = alloc((unsigned)(STRLEN(temp_result) + (expr_start - in_start) retval = xmalloc(STRLEN(temp_result) + (expr_start - in_start)
+ (in_end - expr_end) + 1)); + (in_end - expr_end) + 1);
if (retval != NULL) {
STRCPY(retval, in_start); STRCPY(retval, in_start);
STRCAT(retval, temp_result); STRCAT(retval, temp_result);
STRCAT(retval, expr_end + 1); STRCAT(retval, expr_end + 1);
} }
}
free(temp_result); free(temp_result);
*in_end = c1; /* put char back for error messages */ *in_end = c1; /* put char back for error messages */
@ -15970,7 +15881,6 @@ char_u *set_cmdarg(exarg_T *eap, char_u *oldarg)
{ {
char_u *oldval; char_u *oldval;
char_u *newval; char_u *newval;
unsigned len;
oldval = vimvars[VV_CMDARG].vv_str; oldval = vimvars[VV_CMDARG].vv_str;
if (eap == NULL) { if (eap == NULL) {
@ -15979,26 +15889,23 @@ char_u *set_cmdarg(exarg_T *eap, char_u *oldarg)
return NULL; return NULL;
} }
size_t len = 0;
if (eap->force_bin == FORCE_BIN) if (eap->force_bin == FORCE_BIN)
len = 6; len = 6;
else if (eap->force_bin == FORCE_NOBIN) else if (eap->force_bin == FORCE_NOBIN)
len = 8; len = 8;
else
len = 0;
if (eap->read_edit) if (eap->read_edit)
len += 7; len += 7;
if (eap->force_ff != 0) if (eap->force_ff != 0)
len += (unsigned)STRLEN(eap->cmd + eap->force_ff) + 6; len += STRLEN(eap->cmd + eap->force_ff) + 6;
if (eap->force_enc != 0) if (eap->force_enc != 0)
len += (unsigned)STRLEN(eap->cmd + eap->force_enc) + 7; len += STRLEN(eap->cmd + eap->force_enc) + 7;
if (eap->bad_char != 0) if (eap->bad_char != 0)
len += 7 + 4; /* " ++bad=" + "keep" or "drop" */ len += 7 + 4; /* " ++bad=" + "keep" or "drop" */
newval = alloc(len + 1); newval = xmalloc(len + 1);
if (newval == NULL)
return NULL;
if (eap->force_bin == FORCE_BIN) if (eap->force_bin == FORCE_BIN)
sprintf((char *)newval, " ++bin"); sprintf((char *)newval, " ++bin");
@ -16753,10 +16660,7 @@ set_var (
if (!valid_varname(varname)) if (!valid_varname(varname))
return; return;
v = (dictitem_T *)alloc((unsigned)(sizeof(dictitem_T) v = xmalloc(sizeof(dictitem_T) + STRLEN(varname));
+ STRLEN(varname)));
if (v == NULL)
return;
STRCPY(v->di_key, varname); STRCPY(v->di_key, varname);
if (hash_add(ht, DI2HIKEY(v)) == FAIL) { if (hash_add(ht, DI2HIKEY(v)) == FAIL) {
free(v); free(v);
@ -17412,8 +17316,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)
@ -17605,11 +17507,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;
@ -17678,8 +17578,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) {
@ -17709,9 +17607,7 @@ void ex_function(exarg_T *eap)
} }
} }
fp = (ufunc_T *)alloc((unsigned)(sizeof(ufunc_T) + STRLEN(name))); fp = xmalloc(sizeof(ufunc_T) + STRLEN(name));
if (fp == NULL)
goto erret;
if (fudi.fd_dict != NULL) { if (fudi.fd_dict != NULL) {
if (fudi.fd_di == NULL) { if (fudi.fd_di == NULL) {
@ -17939,8 +17835,7 @@ trans_function_name (
} }
} }
name = alloc((unsigned)(len + lead + 1)); name = xmalloc(len + lead + 1);
if (name != NULL) {
if (lead > 0){ if (lead > 0){
name[0] = K_SPECIAL; name[0] = K_SPECIAL;
name[1] = KS_EXTRA; name[1] = KS_EXTRA;
@ -17950,7 +17845,6 @@ trans_function_name (
} }
memmove(name + lead, lv.ll_name, (size_t)len); memmove(name + lead, lv.ll_name, (size_t)len);
name[lead + len] = NUL; name[lead + len] = NUL;
}
*pp = end; *pp = end;
theend: theend:
@ -18160,7 +18054,7 @@ void func_dump_profile(FILE *fd)
if (todo == 0) if (todo == 0)
return; /* nothing to dump */ return; /* nothing to dump */
sorttab = (ufunc_T **)alloc((unsigned)(sizeof(ufunc_T) * todo)); sorttab = xmalloc(sizeof(ufunc_T) * todo);
for (hi = func_hashtab.ht_array; todo > 0; ++hi) { for (hi = func_hashtab.ht_array; todo > 0; ++hi) {
if (!HASHITEM_EMPTY(hi)) { if (!HASHITEM_EMPTY(hi)) {
@ -18338,9 +18232,7 @@ static char_u *autoload_name(char_u *name)
char_u *scriptname; char_u *scriptname;
/* Get the script file name: replace '#' with '/', append ".vim". */ /* Get the script file name: replace '#' with '/', append ".vim". */
scriptname = alloc((unsigned)(STRLEN(name) + 14)); scriptname = xmalloc(STRLEN(name) + 14);
if (scriptname == NULL)
return FALSE;
STRCPY(scriptname, "autoload/"); STRCPY(scriptname, "autoload/");
STRCAT(scriptname, name); STRCAT(scriptname, name);
*vim_strrchr(scriptname, AUTOLOAD_CHAR) = NUL; *vim_strrchr(scriptname, AUTOLOAD_CHAR) = NUL;
@ -18555,7 +18447,7 @@ call_user_func (
line_breakcheck(); /* check for CTRL-C hit */ line_breakcheck(); /* check for CTRL-C hit */
fc = (funccall_T *)alloc(sizeof(funccall_T)); fc = xmalloc(sizeof(funccall_T));
fc->caller = current_funccal; fc->caller = current_funccal;
current_funccal = fc; current_funccal = fc;
fc->func = fp; fc->func = fp;
@ -18636,10 +18528,7 @@ call_user_func (
v = &fc->fixvar[fixvar_idx++].var; v = &fc->fixvar[fixvar_idx++].var;
v->di_flags = DI_FLAGS_RO | DI_FLAGS_FIX; v->di_flags = DI_FLAGS_RO | DI_FLAGS_FIX;
} else { } else {
v = (dictitem_T *)alloc((unsigned)(sizeof(dictitem_T) v = xmalloc(sizeof(dictitem_T) + STRLEN(name));
+ STRLEN(name)));
if (v == NULL)
break;
v->di_flags = DI_FLAGS_RO; v->di_flags = DI_FLAGS_RO;
} }
STRCPY(v->di_key, name); STRCPY(v->di_key, name);
@ -18662,10 +18551,9 @@ call_user_func (
save_sourcing_name = sourcing_name; save_sourcing_name = sourcing_name;
save_sourcing_lnum = sourcing_lnum; save_sourcing_lnum = sourcing_lnum;
sourcing_lnum = 1; sourcing_lnum = 1;
sourcing_name = alloc((unsigned)((save_sourcing_name == NULL ? 0 sourcing_name = xmalloc((save_sourcing_name == NULL ? 0 : STRLEN(save_sourcing_name))
: STRLEN(save_sourcing_name)) + + STRLEN(fp->uf_name) + 13);
STRLEN(fp->uf_name) + 13)); {
if (sourcing_name != NULL) {
if (save_sourcing_name != NULL if (save_sourcing_name != NULL
&& STRNCMP(save_sourcing_name, "function ", 9) == 0) && STRNCMP(save_sourcing_name, "function ", 9) == 0)
sprintf((char *)sourcing_name, "%s..", save_sourcing_name); sprintf((char *)sourcing_name, "%s..", save_sourcing_name);
@ -19522,13 +19410,11 @@ 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);
} }
} }
@ -19547,11 +19433,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))
@ -19625,30 +19508,24 @@ repeat:
p = vim_strchr(s, sep); p = vim_strchr(s, sep);
if (p != NULL) { if (p != NULL) {
pat = vim_strnsave(s, (int)(p - s)); pat = vim_strnsave(s, (int)(p - s));
if (pat != NULL) {
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) { 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);
if (sub != NULL && str != NULL) {
*usedlen = (int)(p + 1 - src); *usedlen = (int)(p + 1 - src);
s = do_string_sub(str, pat, sub, flags); s = do_string_sub(str, pat, sub, flags);
if (s != NULL) {
*fnamep = s; *fnamep = s;
*fnamelen = (int)STRLEN(s); *fnamelen = (int)STRLEN(s);
free(*bufp); free(*bufp);
*bufp = s; *bufp = s;
didit = TRUE; didit = TRUE;
}
}
free(sub); free(sub);
free(str); free(str);
} }
free(pat); free(pat);
} }
}
/* after using ":s", repeat all the modifiers */ /* after using ":s", repeat all the modifiers */
if (didit) if (didit)
goto repeat; goto repeat;
@ -19679,7 +19556,6 @@ char_u *do_string_sub(char_u *str, char_u *pat, char_u *sub, char_u *flags)
int do_all; int do_all;
char_u *tail; char_u *tail;
garray_T ga; garray_T ga;
char_u *ret;
char_u *save_cpo; char_u *save_cpo;
char_u *zero_width = NULL; char_u *zero_width = NULL;
@ -19738,7 +19614,7 @@ char_u *do_string_sub(char_u *str, char_u *pat, char_u *sub, char_u *flags)
vim_regfree(regmatch.regprog); vim_regfree(regmatch.regprog);
} }
ret = vim_strsave(ga.ga_data == NULL ? str : (char_u *)ga.ga_data); char_u *ret = vim_strsave(ga.ga_data == NULL ? str : (char_u *)ga.ga_data);
ga_clear(&ga); ga_clear(&ga);
if (p_cpo == empty_option) if (p_cpo == empty_option)
p_cpo = save_cpo; p_cpo = save_cpo;

View File

@ -695,13 +695,11 @@ 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++;
} }
}
/* /*
* Now we must be careful adjusting our marks so that we don't overlap our * Now we must be careful adjusting our marks so that we don't overlap our
@ -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;
@ -1454,8 +1451,6 @@ read_viminfo (
return FAIL; return FAIL;
fname = viminfo_filename(file); /* get file name in allocated buffer */ fname = viminfo_filename(file); /* get file name in allocated buffer */
if (fname == NULL)
return FAIL;
fp = mch_fopen((char *)fname, READBIN); fp = mch_fopen((char *)fname, READBIN);
if (p_verbose > 0) { if (p_verbose > 0) {
@ -1502,8 +1497,6 @@ void write_viminfo(char_u *file, int forceit)
return; return;
fname = viminfo_filename(file); /* may set to default if NULL */ fname = viminfo_filename(file); /* may set to default if NULL */
if (fname == NULL)
return;
fp_in = mch_fopen((char *)fname, READBIN); fp_in = mch_fopen((char *)fname, READBIN);
if (fp_in == NULL) { if (fp_in == NULL) {
@ -1670,7 +1663,7 @@ end:
* cmdline functions). * cmdline functions).
* Otherwise use "-i file_name", value from 'viminfo' or the default, and * Otherwise use "-i file_name", value from 'viminfo' or the default, and
* expand environment variables. * expand environment variables.
* Returns an allocated string. NULL when out of memory. * Returns an allocated string.
*/ */
static char_u *viminfo_filename(char_u *file) static char_u *viminfo_filename(char_u *file)
{ {
@ -1886,8 +1879,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,9 +3928,7 @@ 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
@ -3948,7 +3937,6 @@ void do_sub(exarg_T *eap)
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
- regmatch.startpos[0].lnum; - regmatch.startpos[0].lnum;
@ -5769,11 +5757,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 +5820,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,11 +2592,9 @@ 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
if (time_fd != NULL) if (time_fd != NULL)
@ -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

@ -718,11 +718,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;
@ -4296,10 +4291,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 */
@ -4346,8 +4337,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));
@ -5253,12 +5243,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);
@ -7388,6 +7377,7 @@ static void ex_normal(exarg_T *eap)
* ends with half a command. * ends with half a command.
*/ */
save_typeahead(&tabuf); save_typeahead(&tabuf);
// TODO(philix): after save_typeahead() this is always TRUE
if (tabuf.typebuf_valid) { if (tabuf.typebuf_valid) {
/* /*
* Repeat the :normal command for each line in the range. When no * Repeat the :normal command for each line in the range. When no
@ -7991,8 +7981,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

@ -244,17 +244,10 @@ int cause_errthrow(char_u *mesg, int severe, int *ignore)
while (*plist != NULL) while (*plist != NULL)
plist = &(*plist)->next; plist = &(*plist)->next;
elem = (struct msglist *)alloc((unsigned)sizeof(struct msglist)); elem = xmalloc(sizeof(struct msglist));
if (elem == NULL) { {
suppress_errthrow = TRUE;
EMSG(_(e_outofmem));
} 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 +395,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;
} }
@ -477,9 +466,7 @@ static int throw_exception(void *value, int type, char_u *cmdname)
} }
} }
excp = (except_T *)alloc((unsigned)sizeof(except_T)); excp = xmalloc(sizeof(except_T));
if (excp == NULL)
goto nomem;
if (type == ET_ERROR) if (type == ET_ERROR)
/* Store the original message and prefix the exception value with /* Store the original message and prefix the exception value with
@ -493,11 +480,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) {
@ -1302,12 +1284,7 @@ void ex_try(exarg_T *eap)
* to save the value. * to save the value.
*/ */
if (emsg_silent) { if (emsg_silent) {
eslist_T *elem; eslist_T *elem = xmalloc(sizeof(struct eslist_elem));
elem = (eslist_T *)alloc((unsigned)sizeof(struct eslist_elem));
if (elem == NULL)
EMSG(_(e_outofmem));
else {
elem->saved_emsg_silent = emsg_silent; elem->saved_emsg_silent = emsg_silent;
elem->next = cstack->cs_emsg_silent_list; elem->next = cstack->cs_emsg_silent_list;
cstack->cs_emsg_silent_list = elem; cstack->cs_emsg_silent_list = elem;
@ -1315,7 +1292,6 @@ void ex_try(exarg_T *eap)
emsg_silent = 0; emsg_silent = 0;
} }
} }
}
} }
} }

View File

@ -118,7 +118,7 @@ static void set_cmdspos(void);
static void set_cmdspos_cursor(void); static void set_cmdspos_cursor(void);
static void correct_cmdspos(int idx, int cells); static void correct_cmdspos(int idx, int cells);
static void alloc_cmdbuff(int len); static void alloc_cmdbuff(int len);
static int realloc_cmdbuff(int len); static void realloc_cmdbuff(int len);
static void draw_cmdline(int start, int len); static void draw_cmdline(int start, int len);
static void save_cmdline(struct cmdline_info *ccp); static void save_cmdline(struct cmdline_info *ccp);
static void restore_cmdline(struct cmdline_info *ccp); static void restore_cmdline(struct cmdline_info *ccp);
@ -232,8 +232,6 @@ getcmdline (
/* alloc initial ccline.cmdbuff */ /* alloc initial ccline.cmdbuff */
alloc_cmdbuff(exmode_active ? 250 : indent + 1); alloc_cmdbuff(exmode_active ? 250 : indent + 1);
if (ccline.cmdbuff == NULL)
return NULL; /* out of memory */
ccline.cmdlen = ccline.cmdpos = 0; ccline.cmdlen = ccline.cmdpos = 0;
ccline.cmdbuff[0] = NUL; ccline.cmdbuff[0] = NUL;
@ -616,7 +614,7 @@ getcmdline (
if (p != NULL) { if (p != NULL) {
len = (int)STRLEN(p); len = (int)STRLEN(p);
if (realloc_cmdbuff(len + 1) == OK) { realloc_cmdbuff(len + 1);
ccline.cmdlen = len; ccline.cmdlen = len;
STRCPY(ccline.cmdbuff, p); STRCPY(ccline.cmdbuff, p);
free(p); free(p);
@ -633,7 +631,6 @@ getcmdline (
goto cmdline_changed; goto cmdline_changed;
} }
} }
}
beep_flush(); beep_flush();
got_int = FALSE; /* don't abandon the command line */ got_int = FALSE; /* don't abandon the command line */
did_emsg = FALSE; did_emsg = FALSE;
@ -1196,8 +1193,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;
} }
@ -1286,15 +1282,11 @@ getcmdline (
} }
if (i == 0) { if (i == 0) {
alloc_cmdbuff(len); alloc_cmdbuff(len);
if (ccline.cmdbuff == NULL)
goto returncmd;
} }
} }
ccline.cmdbuff[len] = NUL; ccline.cmdbuff[len] = NUL;
} else { } else {
alloc_cmdbuff((int)STRLEN(p)); alloc_cmdbuff((int)STRLEN(p));
if (ccline.cmdbuff == NULL)
goto returncmd;
STRCPY(ccline.cmdbuff, p); STRCPY(ccline.cmdbuff, p);
} }
@ -1994,27 +1986,21 @@ static void alloc_cmdbuff(int len)
else else
len += 20; len += 20;
ccline.cmdbuff = alloc(len); /* caller should check for out-of-memory */ ccline.cmdbuff = xmalloc(len);
ccline.cmdbufflen = len; ccline.cmdbufflen = len;
} }
/* /*
* Re-allocate the command line to length len + something extra. * Re-allocate the command line to length len + something extra.
* return FAIL for failure, OK otherwise
*/ */
static int realloc_cmdbuff(int len) static void realloc_cmdbuff(int len)
{ {
char_u *p; if (len < ccline.cmdbufflen) {
return; // no need to resize
if (len < ccline.cmdbufflen)
return OK; /* no need to resize */
p = ccline.cmdbuff;
alloc_cmdbuff(len); /* will get some more */
if (ccline.cmdbuff == NULL) { /* out of memory */
ccline.cmdbuff = p; /* keep the old one */
return FAIL;
} }
char_u *p = ccline.cmdbuff;
alloc_cmdbuff(len); /* will get some more */
/* There isn't always a NUL after the command, but it may need to be /* There isn't always a NUL after the command, but it may need to be
* there, thus copy up to the NUL and add a NUL. */ * there, thus copy up to the NUL and add a NUL. */
memmove(ccline.cmdbuff, p, (size_t)ccline.cmdlen); memmove(ccline.cmdbuff, p, (size_t)ccline.cmdlen);
@ -2032,8 +2018,6 @@ static int realloc_cmdbuff(int len)
if (i >= 0 && i <= ccline.cmdlen) if (i >= 0 && i <= ccline.cmdlen)
ccline.xpc->xp_pattern = ccline.cmdbuff + i; ccline.xpc->xp_pattern = ccline.cmdbuff + i;
} }
return OK;
} }
static char_u *arshape_buf = NULL; static char_u *arshape_buf = NULL;
@ -2082,9 +2066,7 @@ static void draw_cmdline(int start, int len)
* alloc()/free() calls. */ * alloc()/free() calls. */
free(arshape_buf); free(arshape_buf);
buflen = len * 2 + 2; buflen = len * 2 + 2;
arshape_buf = alloc(buflen); arshape_buf = xmalloc(buflen);
if (arshape_buf == NULL)
return; /* out of memory */
} }
if (utf_iscomposing(utf_ptr2char(ccline.cmdbuff + start))) { if (utf_iscomposing(utf_ptr2char(ccline.cmdbuff + start))) {
@ -2188,9 +2170,8 @@ void unputcmdline(void)
* twice in a row, then 'redraw' should be FALSE and redrawcmd() should be * twice in a row, then 'redraw' should be FALSE and redrawcmd() should be
* called afterwards. * called afterwards.
*/ */
int put_on_cmdline(char_u *str, int len, int redraw) void put_on_cmdline(char_u *str, int len, int redraw)
{ {
int retval;
int i; int i;
int m; int m;
int c; int c;
@ -2198,12 +2179,8 @@ int put_on_cmdline(char_u *str, int len, int redraw)
if (len < 0) if (len < 0)
len = (int)STRLEN(str); len = (int)STRLEN(str);
/* Check if ccline.cmdbuff needs to be longer */ realloc_cmdbuff(ccline.cmdlen + len + 1);
if (ccline.cmdlen + len + 1 >= ccline.cmdbufflen)
retval = realloc_cmdbuff(ccline.cmdlen + len + 1);
else
retval = OK;
if (retval == OK) {
if (!ccline.overstrike) { if (!ccline.overstrike) {
memmove(ccline.cmdbuff + ccline.cmdpos + len, memmove(ccline.cmdbuff + ccline.cmdpos + len,
ccline.cmdbuff + ccline.cmdpos, ccline.cmdbuff + ccline.cmdpos,
@ -2309,10 +2286,9 @@ int put_on_cmdline(char_u *str, int len, int redraw)
++ccline.cmdpos; ++ccline.cmdpos;
} }
} }
}
if (redraw) if (redraw)
msg_check(); msg_check();
return retval;
} }
static struct cmdline_info prev_ccline; static struct cmdline_info prev_ccline;
@ -2348,14 +2324,10 @@ static void restore_cmdline(struct cmdline_info *ccp)
/* /*
* Save the command line into allocated memory. Returns a pointer to be * Save the command line into allocated memory. Returns a pointer to be
* passed to restore_cmdline_alloc() later. * passed to restore_cmdline_alloc() later.
* Returns NULL when failed.
*/ */
char_u *save_cmdline_alloc(void) char_u *save_cmdline_alloc(void)
{ {
struct cmdline_info *p; struct cmdline_info *p = xmalloc(sizeof(struct cmdline_info));
p = (struct cmdline_info *)alloc((unsigned)sizeof(struct cmdline_info));
if (p != NULL)
save_cmdline(p); save_cmdline(p);
return (char_u *)p; return (char_u *)p;
} }
@ -2649,7 +2621,6 @@ nextwild (
char_u *p1; char_u *p1;
char_u *p2; char_u *p2;
int difflen; int difflen;
int v;
if (xp->xp_numfiles == -1) { if (xp->xp_numfiles == -1) {
set_expand_context(xp); set_expand_context(xp);
@ -2712,11 +2683,9 @@ nextwild (
if (p2 != NULL && !got_int) { if (p2 != NULL && !got_int) {
difflen = (int)STRLEN(p2) - xp->xp_pattern_len; difflen = (int)STRLEN(p2) - xp->xp_pattern_len;
if (ccline.cmdlen + difflen + 4 > ccline.cmdbufflen) { if (ccline.cmdlen + difflen + 4 > ccline.cmdbufflen) {
v = realloc_cmdbuff(ccline.cmdlen + difflen + 4); realloc_cmdbuff(ccline.cmdlen + difflen + 4);
xp->xp_pattern = ccline.cmdbuff + i; xp->xp_pattern = ccline.cmdbuff + i;
} else }
v = OK;
if (v == OK) {
memmove(&ccline.cmdbuff[ccline.cmdpos + difflen], memmove(&ccline.cmdbuff[ccline.cmdpos + difflen],
&ccline.cmdbuff[ccline.cmdpos], &ccline.cmdbuff[ccline.cmdpos],
(size_t)(ccline.cmdlen - ccline.cmdpos + 1)); (size_t)(ccline.cmdlen - ccline.cmdpos + 1));
@ -2724,7 +2693,6 @@ nextwild (
ccline.cmdlen += difflen; ccline.cmdlen += difflen;
ccline.cmdpos += difflen; ccline.cmdpos += difflen;
} }
}
free(p2); free(p2);
redrawcmd(); redrawcmd();
@ -3104,16 +3072,12 @@ char_u *vim_strsave_fnameescape(char_u *fname, int shell)
*/ */
static void escape_fname(char_u **pp) static void escape_fname(char_u **pp)
{ {
char_u *p; char_u *p = xmalloc(STRLEN(*pp) + 2);
p = alloc((unsigned)(STRLEN(*pp) + 2));
if (p != NULL) {
p[0] = '\\'; p[0] = '\\';
STRCPY(p + 1, *pp); STRCPY(p + 1, *pp);
free(*pp); free(*pp);
*pp = p; *pp = p;
} }
}
/* /*
* For each file name in files[num_files]: * For each file name in files[num_files]:
@ -3246,8 +3210,7 @@ static int showmatches(expand_T *xp, int wildmenu)
exp_path = expand_env_save_opt(files_found[k], TRUE); exp_path = expand_env_save_opt(files_found[k], TRUE);
halved_slash = backslash_halve_save( halved_slash = backslash_halve_save(
exp_path != NULL ? exp_path : files_found[k]); exp_path != NULL ? exp_path : files_found[k]);
j = os_isdir(halved_slash != NULL ? halved_slash j = os_isdir(halved_slash);
: files_found[k]);
free(exp_path); free(exp_path);
free(halved_slash); free(halved_slash);
} else } else
@ -3403,8 +3366,8 @@ addstar (
|| context == EXPAND_USER_LIST) && fname[i] == '\\') || context == EXPAND_USER_LIST) && fname[i] == '\\')
new_len++; /* '\' becomes "\\" */ new_len++; /* '\' becomes "\\" */
} }
retval = alloc(new_len); retval = xmalloc(new_len);
if (retval != NULL) { {
retval[0] = '^'; retval[0] = '^';
j = 1; j = 1;
for (i = 0; i < len; i++, j++) { for (i = 0; i < len; i++, j++) {
@ -3437,7 +3400,7 @@ addstar (
} }
} }
} else { } else {
retval = alloc(len + 4); retval = xmalloc(len + 4);
if (retval != NULL) { if (retval != NULL) {
vim_strncpy(retval, fname, len); vim_strncpy(retval, fname, len);
@ -3831,7 +3794,7 @@ ExpandFromContext (
* obtain strings, one by one. The strings are matched against a regexp * obtain strings, one by one. The strings are matched against a regexp
* program. Matching strings are copied into an array, which is returned. * program. Matching strings are copied into an array, which is returned.
* *
* Returns OK when no problems encountered, FAIL for error (out of memory). * Returns OK when no problems encountered, FAIL for error.
*/ */
int ExpandGeneric(xp, regmatch, num_file, file, func, escaped) int ExpandGeneric(xp, regmatch, num_file, file, func, escaped)
expand_T *xp; expand_T *xp;
@ -3860,11 +3823,7 @@ int escaped;
if (count == 0) if (count == 0)
return OK; return OK;
*num_file = count; *num_file = count;
*file = (char_u **)alloc((unsigned)(count * sizeof(char_u *))); *file = (char_u **)xmalloc(count * sizeof(char_u *));
if (*file == NULL) {
*file = (char_u **)"";
return FAIL;
}
// copy the matching names into allocated memory // copy the matching names into allocated memory
count = 0; count = 0;
@ -3925,15 +3884,12 @@ expand_shellcmd (
char_u *path; char_u *path;
int mustfree = FALSE; int mustfree = FALSE;
garray_T ga; garray_T ga;
char_u *buf = alloc(MAXPATHL); char_u *buf = xmalloc(MAXPATHL);
size_t l; size_t l;
char_u *s, *e; char_u *s, *e;
int flags = flagsarg; int flags = flagsarg;
int ret; int ret;
if (buf == NULL)
return FAIL;
/* for ":set path=" and ":set tags=" halve backslashes for escaped /* for ":set path=" and ":set tags=" halve backslashes for escaped
* space */ * space */
pat = vim_strsave(filepat); pat = vim_strsave(filepat);
@ -4157,11 +4113,7 @@ static int ExpandRTDir(char_u *pat, int *num_file, char_u ***file, char *dirname
ga_init(&ga, (int)sizeof(char *), 10); ga_init(&ga, (int)sizeof(char *), 10);
for (i = 0; dirnames[i] != NULL; ++i) { for (i = 0; dirnames[i] != NULL; ++i) {
s = alloc((unsigned)(STRLEN(dirnames[i]) + pat_len + 7)); s = xmalloc(STRLEN(dirnames[i]) + pat_len + 7);
if (s == NULL) {
ga_clear_strings(&ga);
return FAIL;
}
sprintf((char *)s, "%s/%s*.vim", dirnames[i], pat); sprintf((char *)s, "%s/%s*.vim", dirnames[i], pat);
matches = globpath(p_rtp, s, 0); matches = globpath(p_rtp, s, 0);
free(s); free(s);
@ -4208,7 +4160,6 @@ static int ExpandRTDir(char_u *pat, int *num_file, char_u ***file, char *dirname
char_u *globpath(char_u *path, char_u *file, int expand_options) char_u *globpath(char_u *path, char_u *file, int expand_options)
{ {
expand_T xpc; expand_T xpc;
char_u *buf;
garray_T ga; garray_T ga;
int i; int i;
int len; int len;
@ -4216,9 +4167,7 @@ char_u *globpath(char_u *path, char_u *file, int expand_options)
char_u **p; char_u **p;
char_u *cur = NULL; char_u *cur = NULL;
buf = alloc(MAXPATHL); char_u *buf = xmalloc(MAXPATHL);
if (buf == NULL)
return NULL;
ExpandInit(&xpc); ExpandInit(&xpc);
xpc.xp_context = EXPAND_FILES; xpc.xp_context = EXPAND_FILES;
@ -4510,7 +4459,6 @@ 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];

View File

@ -14,7 +14,7 @@ char_u *getexmodeline(int promptc, void *cookie, int indent);
void free_cmdline_buf(void); void free_cmdline_buf(void);
void putcmdline(int c, int shift); void putcmdline(int c, int shift);
void unputcmdline(void); void unputcmdline(void);
int put_on_cmdline(char_u *str, int len, int redraw); void put_on_cmdline(char_u *str, int len, int redraw);
char_u *save_cmdline_alloc(void); char_u *save_cmdline_alloc(void);
void restore_cmdline_alloc(char_u *p); void restore_cmdline_alloc(char_u *p);
void cmdline_paste_str(char_u *s, int literally); void cmdline_paste_str(char_u *s, int literally);

View File

@ -278,8 +278,7 @@ vim_findfile_init (
if (search_ctx_arg != NULL) if (search_ctx_arg != NULL)
search_ctx = search_ctx_arg; search_ctx = search_ctx_arg;
else { else {
search_ctx = (ff_search_ctx_T*)alloc((unsigned)sizeof(ff_search_ctx_T)); search_ctx = xcalloc(1, sizeof(ff_search_ctx_T));
memset(search_ctx, 0, sizeof(ff_search_ctx_T));
} }
search_ctx->ffsc_find_what = find_what; search_ctx->ffsc_find_what = find_what;
search_ctx->ffsc_tagfile = tagfile; search_ctx->ffsc_tagfile = tagfile;
@ -305,7 +304,7 @@ vim_findfile_init (
} }
if (ff_expand_buffer == NULL) { if (ff_expand_buffer == NULL) {
ff_expand_buffer = (char_u*)alloc(MAXPATHL); ff_expand_buffer = xmalloc(MAXPATHL);
} }
/* Store information on starting dir now if path is relative. /* Store information on starting dir now if path is relative.
@ -322,8 +321,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 +341,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
@ -374,8 +369,7 @@ vim_findfile_init (
walker++; walker++;
dircount = 1; dircount = 1;
search_ctx->ffsc_stopdirs_v = search_ctx->ffsc_stopdirs_v = xmalloc(sizeof(char_u *));
(char_u **)alloc((unsigned)sizeof(char_u *));
do { do {
char_u *helper; char_u *helper;
@ -458,9 +452,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 +460,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;
} }
@ -483,9 +472,8 @@ vim_findfile_init (
STRCPY(ff_expand_buffer, search_ctx->ffsc_start_dir); STRCPY(ff_expand_buffer, search_ctx->ffsc_start_dir);
add_pathsep(ff_expand_buffer); add_pathsep(ff_expand_buffer);
{ {
int eb_len = (int)STRLEN(ff_expand_buffer); size_t eb_len = STRLEN(ff_expand_buffer);
char_u *buf = alloc(eb_len char_u *buf = xmalloc(eb_len + STRLEN(search_ctx->ffsc_fix_path) + 1);
+ (int)STRLEN(search_ctx->ffsc_fix_path) + 1);
STRCPY(buf, ff_expand_buffer); STRCPY(buf, ff_expand_buffer);
STRCPY(buf + eb_len, search_ctx->ffsc_fix_path); STRCPY(buf + eb_len, search_ctx->ffsc_fix_path);
@ -507,9 +495,9 @@ vim_findfile_init (
if (search_ctx->ffsc_wc_path != NULL) { if (search_ctx->ffsc_wc_path != NULL) {
wc_path = vim_strsave(search_ctx->ffsc_wc_path); wc_path = vim_strsave(search_ctx->ffsc_wc_path);
temp = alloc((int)(STRLEN(search_ctx->ffsc_wc_path) temp = xmalloc(STRLEN(search_ctx->ffsc_wc_path)
+ STRLEN(search_ctx->ffsc_fix_path + len) + STRLEN(search_ctx->ffsc_fix_path + len)
+ 1)); + 1);
} }
if (temp == NULL || wc_path == NULL) { if (temp == NULL || wc_path == NULL) {
@ -532,15 +520,8 @@ vim_findfile_init (
search_ctx->ffsc_wc_path, search_ctx->ffsc_wc_path,
level, 0); level, 0);
if (sptr == NULL)
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:
@ -623,8 +604,7 @@ char_u *vim_findfile(void *search_ctx_arg)
* filepath is used as buffer for various actions and as the storage to * filepath is used as buffer for various actions and as the storage to
* return a found filename. * return a found filename.
*/ */
if ((file_path = alloc((int)MAXPATHL)) == NULL) file_path = xmalloc(MAXPATHL);
return NULL;
/* store the end of the start dir -- needed for upward search */ /* store the end of the start dir -- needed for upward search */
if (search_ctx->ffsc_start_dir != NULL) if (search_ctx->ffsc_start_dir != NULL)
@ -776,12 +756,9 @@ char_u *vim_findfile(void *search_ctx_arg)
* If the path is a URL don't try this. * If the path is a URL don't try this.
*/ */
if (path_with_url(dirptrs[0])) { if (path_with_url(dirptrs[0])) {
stackp->ffs_filearray = (char_u **) stackp->ffs_filearray = (char_u **)xmalloc(sizeof(char *));
alloc((unsigned)sizeof(char *)); stackp->ffs_filearray[0] = vim_strsave(dirptrs[0]);
if ((stackp->ffs_filearray[0] = vim_strsave(dirptrs[0])) != NULL)
stackp->ffs_filearray_size = 1; stackp->ffs_filearray_size = 1;
else
stackp->ffs_filearray_size = 0;
} else } else
/* Add EW_NOTWILD because the expanded path may contain /* Add EW_NOTWILD because the expanded path may contain
* wildcard characters that are to be taken literally. * wildcard characters that are to be taken literally.
@ -969,8 +946,6 @@ char_u *vim_findfile(void *search_ctx_arg)
/* create a new stack entry */ /* create a new stack entry */
sptr = ff_create_stack_element(file_path, sptr = ff_create_stack_element(file_path,
search_ctx->ffsc_wc_path, search_ctx->ffsc_level, 0); search_ctx->ffsc_wc_path, search_ctx->ffsc_level, 0);
if (sptr == NULL)
break;
ff_push(search_ctx, sptr); ff_push(search_ctx, sptr);
} else } else
break; break;
@ -1066,14 +1041,10 @@ static ff_visited_list_hdr_T *ff_get_visited_list(char_u *filename, ff_visited_l
/* /*
* if we reach this we didn't find a list and we have to allocate new list * if we reach this we didn't find a list and we have to allocate new list
*/ */
retptr = (ff_visited_list_hdr_T*)alloc((unsigned)sizeof(*retptr)); retptr = xmalloc(sizeof(*retptr));
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;
@ -1156,8 +1127,7 @@ static int ff_check_visited(ff_visited_T **visited_list, char_u *fname, char_u *
/* /*
* New file/dir. Add it to the list of visited files/dirs. * New file/dir. Add it to the list of visited files/dirs.
*/ */
vp = (ff_visited_T *)alloc((unsigned)(sizeof(ff_visited_T) vp = xmalloc(sizeof(ff_visited_T) + STRLEN(ff_expand_buffer));
+ STRLEN(ff_expand_buffer)));
if (!url) { if (!url) {
vp->ffv_dev_valid = TRUE; vp->ffv_dev_valid = TRUE;
@ -1185,9 +1155,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 +1174,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 +1390,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] == '.'
@ -1525,7 +1482,7 @@ find_file_in_path_option (
break; break;
} }
buf = alloc((int)(MAXPATHL)); buf = xmalloc(MAXPATHL);
/* copy next path */ /* copy next path */
buf[0] = 0; buf[0] = 0;

View File

@ -2070,12 +2070,10 @@ 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 *)"";
*pp = NULL; *pp = NULL;
@ -3438,7 +3436,7 @@ restore_backup:
"E513: write error, conversion failed (make 'fenc' empty to override)"); "E513: write error, conversion failed (make 'fenc' empty to override)");
else { else {
errmsg_allocated = TRUE; errmsg_allocated = TRUE;
errmsg = alloc(300); errmsg = xmalloc(300);
vim_snprintf((char *)errmsg, 300, vim_snprintf((char *)errmsg, 300,
_("E513: write error, conversion failed in line %" PRId64 _("E513: write error, conversion failed in line %" PRId64
" (make 'fenc' empty to override)"), " (make 'fenc' empty to override)"),
@ -4373,7 +4371,7 @@ modname (
* (we need the full path in case :cd is used). * (we need the full path in case :cd is used).
*/ */
if (fname == NULL || *fname == NUL) { if (fname == NULL || *fname == NUL) {
retval = alloc((unsigned)(MAXPATHL + extlen + 3)); retval = xmalloc(MAXPATHL + extlen + 3);
if (os_dirname(retval, MAXPATHL) == FAIL || if (os_dirname(retval, MAXPATHL) == FAIL ||
(fnamelen = (int)STRLEN(retval)) == 0) { (fnamelen = (int)STRLEN(retval)) == 0) {
free(retval); free(retval);
@ -4386,7 +4384,7 @@ modname (
prepend_dot = FALSE; /* nothing to prepend a dot to */ prepend_dot = FALSE; /* nothing to prepend a dot to */
} else { } else {
fnamelen = (int)STRLEN(fname); fnamelen = (int)STRLEN(fname);
retval = alloc((unsigned)(fnamelen + extlen + 3)); retval = xmalloc(fnamelen + extlen + 3);
STRCPY(retval, fname); STRCPY(retval, fname);
} }
@ -4759,7 +4757,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;
@ -4936,8 +4934,7 @@ buf_check_timestamp (
if (path != NULL) { if (path != NULL) {
if (!helpmesg) if (!helpmesg)
mesg2 = ""; mesg2 = "";
tbuf = alloc((unsigned)(STRLEN(path) + STRLEN(mesg) tbuf = xmalloc(STRLEN(path) + STRLEN(mesg) + STRLEN(mesg2) + 2);
+ STRLEN(mesg2) + 2));
sprintf((char *)tbuf, mesg, path); sprintf((char *)tbuf, mesg, path);
/* Set warningmsg here, before the unimportant and output-specific /* Set warningmsg here, before the unimportant and output-specific
* mesg2 has been appended. */ * mesg2 has been appended. */
@ -5759,8 +5756,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;
} }
@ -5964,18 +5959,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 (new_ei != NULL) {
if (*what == ',' && *p_ei == NUL) if (*what == ',' && *p_ei == NUL)
STRCPY(new_ei, what + 1); STRCPY(new_ei, what + 1);
else else
STRCAT(new_ei, what); STRCAT(new_ei, what);
set_string_option_direct((char_u *)"ei", -1, new_ei, set_string_option_direct((char_u *)"ei", -1, new_ei, OPT_FREE, SID_NONE);
OPT_FREE, SID_NONE);
free(new_ei); free(new_ei);
}
}
return save_ei; return save_ei;
} }
@ -6126,7 +6117,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)
{ {
@ -6138,8 +6129,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 */
@ -6306,13 +6295,9 @@ static int do_autocmd_event(event_T event, char_u *pat, int nested, char_u *cmd,
return FAIL; return FAIL;
} }
ap = (AutoPat *)alloc((unsigned)sizeof(AutoPat)); ap = xmalloc(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;
@ -6347,13 +6332,9 @@ static int do_autocmd_event(event_T event, char_u *pat, int nested, char_u *cmd,
prev_ac = &(ap->cmds); prev_ac = &(ap->cmds);
while ((ac = *prev_ac) != NULL) while ((ac = *prev_ac) != NULL)
prev_ac = &ac->next; prev_ac = &ac->next;
ac = (AutoCmd *)alloc((unsigned)sizeof(AutoCmd)); ac = xmalloc(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;
@ -7160,8 +7141,7 @@ auto_next_pat (
: ap->buflocal_nr == apc->arg_bufnr) { : ap->buflocal_nr == apc->arg_bufnr) {
name = event_nr2name(apc->event); name = event_nr2name(apc->event);
s = _("%s Auto commands for \"%s\""); s = _("%s Auto commands for \"%s\"");
sourcing_name = alloc((unsigned)(STRLEN(s) sourcing_name = xmalloc(STRLEN(s) + STRLEN(name) + ap->patlen + 1);
+ STRLEN(name) + ap->patlen + 1));
sprintf((char *)sourcing_name, s, sprintf((char *)sourcing_name, s,
(char *)name, (char *)ap->pat); (char *)name, (char *)ap->pat);
if (p_verbose >= 8) { if (p_verbose >= 8) {
@ -7264,7 +7244,6 @@ 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
@ -7403,8 +7382,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

@ -1610,7 +1610,7 @@ static void foldAddMarker(linenr_T lnum, char_u *marker, int markerlen)
line_len = (int)STRLEN(line); line_len = (int)STRLEN(line);
if (u_save(lnum - 1, lnum + 1) == OK) { if (u_save(lnum - 1, lnum + 1) == OK) {
newline = alloc((unsigned)(line_len + markerlen + STRLEN(cms) + 1)); newline = xmalloc(line_len + markerlen + STRLEN(cms) + 1);
STRCPY(newline, line); STRCPY(newline, line);
if (p == NULL) if (p == NULL)
vim_strncpy(newline + line_len, marker, markerlen); vim_strncpy(newline + line_len, marker, markerlen);
@ -1681,7 +1681,7 @@ static void foldDelMarker(linenr_T lnum, char_u *marker, int markerlen)
} }
if (u_save(lnum - 1, lnum + 1) == OK) { if (u_save(lnum - 1, lnum + 1) == OK) {
/* Make new line: text-before-marker + text-after-marker */ /* Make new line: text-before-marker + text-after-marker */
newline = alloc((unsigned)(STRLEN(line) - len + 1)); newline = xmalloc(STRLEN(line) - len + 1);
STRNCPY(newline, line, p - line); STRNCPY(newline, line, p - line);
STRCPY(newline + (p - line), p + len); STRCPY(newline + (p - line), p + len);
ml_replace(lnum, newline, FALSE); ml_replace(lnum, newline, FALSE);

View File

@ -891,14 +891,8 @@ int ins_typebuf(char_u *str, int noremap, int offset, int nottyped, int silent)
setcursor(); setcursor();
return FAIL; return FAIL;
} }
s1 = alloc(newlen); s1 = xmalloc(newlen);
if (s1 == NULL) /* out of memory */ s2 = xmalloc(newlen);
return FAIL;
s2 = alloc(newlen);
if (s2 == NULL) { /* out of memory */
free(s1);
return FAIL;
}
typebuf.tb_buflen = newlen; typebuf.tb_buflen = newlen;
/* copy the old chars, before the insertion point */ /* copy the old chars, before the insertion point */
@ -1147,16 +1141,11 @@ static void may_sync_undo(void)
/* /*
* Make "typebuf" empty and allocate new buffers. * Make "typebuf" empty and allocate new buffers.
* Returns FAIL when out of memory.
*/ */
int alloc_typebuf(void) void alloc_typebuf(void)
{ {
typebuf.tb_buf = alloc(TYPELEN_INIT); typebuf.tb_buf = xmalloc(TYPELEN_INIT);
typebuf.tb_noremap = alloc(TYPELEN_INIT); typebuf.tb_noremap = xmalloc(TYPELEN_INIT);
if (typebuf.tb_buf == NULL || typebuf.tb_noremap == NULL) {
free_typebuf();
return FAIL;
}
typebuf.tb_buflen = TYPELEN_INIT; typebuf.tb_buflen = TYPELEN_INIT;
typebuf.tb_off = 0; typebuf.tb_off = 0;
typebuf.tb_len = 0; typebuf.tb_len = 0;
@ -1165,7 +1154,6 @@ int alloc_typebuf(void)
typebuf.tb_no_abbr_cnt = 0; typebuf.tb_no_abbr_cnt = 0;
if (++typebuf.tb_change_cnt == 0) if (++typebuf.tb_change_cnt == 0)
typebuf.tb_change_cnt = 1; typebuf.tb_change_cnt = 1;
return OK;
} }
/* /*
@ -1189,16 +1177,11 @@ void free_typebuf(void)
*/ */
static typebuf_T saved_typebuf[NSCRIPT]; static typebuf_T saved_typebuf[NSCRIPT];
int save_typebuf(void) void save_typebuf(void)
{ {
init_typebuf(); init_typebuf();
saved_typebuf[curscript] = typebuf; saved_typebuf[curscript] = typebuf;
/* If out of memory: restore typebuf and close file. */ alloc_typebuf();
if (alloc_typebuf() == FAIL) {
closescript();
return FAIL;
}
return OK;
} }
static int old_char = -1; /* character put back by vungetc() */ static int old_char = -1; /* character put back by vungetc() */
@ -1213,10 +1196,8 @@ static int old_mouse_col; /* mouse_col related to old_char */
void save_typeahead(tasave_T *tp) void save_typeahead(tasave_T *tp)
{ {
tp->save_typebuf = typebuf; tp->save_typebuf = typebuf;
tp->typebuf_valid = (alloc_typebuf() == OK); alloc_typebuf();
if (!tp->typebuf_valid) tp->typebuf_valid = TRUE;
typebuf = tp->save_typebuf;
tp->old_char = old_char; tp->old_char = old_char;
tp->old_mod_mask = old_mod_mask; tp->old_mod_mask = old_mod_mask;
old_char = -1; old_char = -1;
@ -1280,8 +1261,7 @@ openscript (
--curscript; --curscript;
return; return;
} }
if (save_typebuf() == FAIL) save_typebuf();
return;
/* /*
* Execute the commands from the file right now when using ":source!" * Execute the commands from the file right now when using ":source!"
@ -2636,7 +2616,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 +2958,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;
@ -3044,11 +3018,7 @@ do_map (
/* /*
* Get here when adding a new entry to the maphash[] list or abbrlist. * Get here when adding a new entry to the maphash[] list or abbrlist.
*/ */
mp = (mapblock_T *)alloc((unsigned)sizeof(mapblock_T)); mp = xmalloc(sizeof(mapblock_T));
if (mp == NULL) {
retval = 4; /* no mem */
goto theend;
}
/* If CTRL-C has been mapped, don't always use it for Interrupting */ /* If CTRL-C has been mapped, don't always use it for Interrupting */
if (*keys == Ctrl_C) if (*keys == Ctrl_C)
@ -3057,14 +3027,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,12 +3290,10 @@ 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);
out_flush(); /* show one line at a time */ out_flush(); /* show one line at a time */
@ -3564,9 +3524,7 @@ int ExpandMappings(regmatch_T *regmatch, int *num_file, char_u ***file)
break; /* for (round) */ break; /* for (round) */
if (round == 1) { if (round == 1) {
*file = (char_u **)alloc((unsigned)(count * sizeof(char_u *))); *file = (char_u **)xmalloc(count * sizeof(char_u *));
if (*file == NULL)
return FAIL;
} }
} /* for (round) */ } /* for (round) */
@ -3778,8 +3736,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();
@ -3831,7 +3787,7 @@ char_u *vim_strsave_escape_csi(char_u *p)
char_u *s, *d; char_u *s, *d;
/* Need a buffer to hold up to three times as much. */ /* Need a buffer to hold up to three times as much. */
res = alloc((unsigned)(STRLEN(p) * 3) + 1); res = xmalloc(STRLEN(p) * 3 + 1);
d = res; d = res;
for (s = p; *s != NUL; ) { for (s = p; *s != NUL; ) {
if (s[0] == K_SPECIAL && s[1] != NUL && s[2] != NUL) { if (s[0] == K_SPECIAL && s[1] != NUL && s[2] != NUL) {
@ -4325,10 +4281,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

@ -31,9 +31,9 @@ int typebuf_changed(int tb_change_cnt);
int typebuf_typed(void); int typebuf_typed(void);
int typebuf_maplen(void); int typebuf_maplen(void);
void del_typebuf(int len, int offset); void del_typebuf(int len, int offset);
int alloc_typebuf(void); void alloc_typebuf(void);
void free_typebuf(void); void free_typebuf(void);
int save_typebuf(void); void save_typebuf(void);
void save_typeahead(tasave_T *tp); void save_typeahead(tasave_T *tp);
void restore_typeahead(tasave_T *tp); void restore_typeahead(tasave_T *tp);
void openscript(char_u *name, int directly); void openscript(char_u *name, int directly);

View File

@ -347,18 +347,7 @@ static int hash_may_resize(hashtab_T *ht, int minitems)
} }
} else { } else {
// Allocate an array. // Allocate an array.
newarray = (hashitem_T *)alloc((unsigned)(sizeof(hashitem_T) * newsize)); newarray = xmalloc(sizeof(hashitem_T) * newsize);
if (newarray == NULL) {
// Out of memory. When there are NULL items still return OK.
// Otherwise set ht_error, because lookup may result in a hang if
// we add another item.
if (ht->ht_filled < ht->ht_mask) {
return OK;
}
ht->ht_error = TRUE;
return FAIL;
}
oldarray = ht->ht_array; oldarray = ht->ht_array;
} }
memset(newarray, 0, (size_t)(sizeof(hashitem_T) * newsize)); memset(newarray, 0, (size_t)(sizeof(hashitem_T) * newsize));

View File

@ -459,7 +459,7 @@ static int cs_add(exarg_T *eap)
static void cs_stat_emsg(char *fname) static void cs_stat_emsg(char *fname)
{ {
char *stat_emsg = _("E563: stat(%s) error: %d"); char *stat_emsg = _("E563: stat(%s) error: %d");
char *buf = (char *)alloc((unsigned)strlen(stat_emsg) + MAXPATHL + 10); char *buf = xmalloc(strlen(stat_emsg) + MAXPATHL + 10);
(void)sprintf(buf, stat_emsg, fname, errno); (void)sprintf(buf, stat_emsg, fname, errno);
(void)EMSG(buf); (void)EMSG(buf);
@ -490,7 +490,7 @@ cs_add_common (
char_u *fbuf = NULL; char_u *fbuf = NULL;
/* get the filename (arg1), expand it, and try to stat it */ /* get the filename (arg1), expand it, and try to stat it */
fname = (char *)alloc(MAXPATHL + 1); fname = xmalloc(MAXPATHL + 1);
expand_env((char_u *)arg1, (char_u *)fname, MAXPATHL); expand_env((char_u *)arg1, (char_u *)fname, MAXPATHL);
len = (int)STRLEN(fname); len = (int)STRLEN(fname);
@ -512,7 +512,7 @@ staterr:
// get the prepend path (arg2), expand it, and see if it exists // get the prepend path (arg2), expand it, and see if it exists
if (arg2 != NULL) { if (arg2 != NULL) {
ppath = (char *)alloc(MAXPATHL + 1); ppath = xmalloc(MAXPATHL + 1);
expand_env((char_u *)arg2, (char_u *)ppath, MAXPATHL); expand_env((char_u *)arg2, (char_u *)ppath, MAXPATHL);
if (!os_file_exists((char_u *)ppath)) if (!os_file_exists((char_u *)ppath))
goto staterr; goto staterr;
@ -520,7 +520,7 @@ staterr:
/* if filename is a directory, append the cscope database name to it */ /* if filename is a directory, append the cscope database name to it */
if ((file_info.stat.st_mode & S_IFMT) == S_IFDIR) { if ((file_info.stat.st_mode & S_IFMT) == S_IFDIR) {
fname2 = (char *)alloc((unsigned)(strlen(CSCOPE_DBFILE) + strlen(fname) + 2)); fname2 = (char *)xmalloc(strlen(CSCOPE_DBFILE) + strlen(fname) + 2);
while (fname[strlen(fname)-1] == '/' while (fname[strlen(fname)-1] == '/'
) { ) {
@ -625,10 +625,9 @@ cs_reading_emsg (
static int cs_cnt_matches(int idx) static int cs_cnt_matches(int idx)
{ {
char *stok; char *stok;
char *buf;
int nlines; int nlines;
buf = (char *)alloc(CSREAD_BUFSIZE); char *buf = xmalloc(CSREAD_BUFSIZE);
for (;; ) { for (;; ) {
if (!fgets(buf, CSREAD_BUFSIZE, csinfo[idx].fr_fp)) { if (!fgets(buf, CSREAD_BUFSIZE, csinfo[idx].fr_fp)) {
if (feof(csinfo[idx].fr_fp)) if (feof(csinfo[idx].fr_fp))
@ -721,7 +720,7 @@ static char *cs_create_cmd(char *csoption, char *pattern)
while (vim_iswhite(*pat)) while (vim_iswhite(*pat))
++pat; ++pat;
cmd = (char *)alloc((unsigned)(strlen(pat) + 2)); cmd = xmalloc(strlen(pat) + 2);
(void)sprintf(cmd, "%d%s", search, pat); (void)sprintf(cmd, "%d%s", search, pat);
@ -801,14 +800,14 @@ err_closing:
} }
#endif #endif
/* expand the cscope exec for env var's */ /* expand the cscope exec for env var's */
prog = (char *)alloc(MAXPATHL + 1); prog = xmalloc(MAXPATHL + 1);
expand_env((char_u *)p_csprg, (char_u *)prog, MAXPATHL); expand_env((char_u *)p_csprg, (char_u *)prog, MAXPATHL);
/* alloc space to hold the cscope command */ /* alloc space to hold the cscope command */
len = (int)(strlen(prog) + strlen(csinfo[i].fname) + 32); len = (int)(strlen(prog) + strlen(csinfo[i].fname) + 32);
if (csinfo[i].ppath) { if (csinfo[i].ppath) {
/* expand the prepend path for env var's */ /* expand the prepend path for env var's */
ppath = (char *)alloc(MAXPATHL + 1); ppath = xmalloc(MAXPATHL + 1);
expand_env((char_u *)csinfo[i].ppath, (char_u *)ppath, MAXPATHL); expand_env((char_u *)csinfo[i].ppath, (char_u *)ppath, MAXPATHL);
len += (int)strlen(ppath); len += (int)strlen(ppath);
@ -817,7 +816,7 @@ err_closing:
if (csinfo[i].flags) if (csinfo[i].flags)
len += (int)strlen(csinfo[i].flags); len += (int)strlen(csinfo[i].flags);
cmd = (char *)alloc(len); cmd = xmalloc(len);
/* run the cscope command; is there execl for non-unix systems? */ /* run the cscope command; is there execl for non-unix systems? */
#if defined(UNIX) #if defined(UNIX)
@ -1009,7 +1008,7 @@ static int cs_find_common(char *opt, char *pat, int forceit, int verbose, int us
if (strchr(CSQF_FLAGS, *qfpos) == NULL) { if (strchr(CSQF_FLAGS, *qfpos) == NULL) {
char *nf = _("E469: invalid cscopequickfix flag %c for %c"); char *nf = _("E469: invalid cscopequickfix flag %c for %c");
/* strlen will be enough because we use chars */ /* strlen will be enough because we use chars */
char *buf = (char *)alloc((unsigned)strlen(nf)); char *buf = xmalloc(strlen(nf));
sprintf(buf, nf, *qfpos, *(qfpos-1)); sprintf(buf, nf, *qfpos, *(qfpos-1));
(void)EMSG(buf); (void)EMSG(buf);
@ -1030,7 +1029,7 @@ static int cs_find_common(char *opt, char *pat, int forceit, int verbose, int us
if (cmd == NULL) if (cmd == NULL)
return FALSE; return FALSE;
nummatches = (int *)alloc(sizeof(int)*csinfo_size); nummatches = xmalloc(sizeof(int) * csinfo_size);
/* Send query to all open connections, then count the total number /* Send query to all open connections, then count the total number
* of matches so we can alloc all in one swell foop. */ * of matches so we can alloc all in one swell foop. */
@ -1064,7 +1063,7 @@ static int cs_find_common(char *opt, char *pat, int forceit, int verbose, int us
return FALSE; return FALSE;
} }
buf = (char *)alloc((unsigned)(strlen(opt) + strlen(pat) + strlen(nf))); buf = xmalloc(strlen(opt) + strlen(pat) + strlen(nf));
sprintf(buf, nf, opt, pat); sprintf(buf, nf, opt, pat);
(void)EMSG(buf); (void)EMSG(buf);
free(buf); free(buf);
@ -1249,18 +1248,18 @@ static int cs_insert_filelist(char *fname, char *ppath, char *flags,
clear_csinfo(j); clear_csinfo(j);
} }
csinfo[i].fname = (char *)alloc((unsigned)strlen(fname)+1); csinfo[i].fname = xmalloc(strlen(fname) + 1);
(void)strcpy(csinfo[i].fname, (const char *)fname); (void)strcpy(csinfo[i].fname, (const char *)fname);
if (ppath != NULL) { if (ppath != NULL) {
csinfo[i].ppath = (char *)alloc((unsigned)strlen(ppath) + 1); csinfo[i].ppath = xmalloc(strlen(ppath) + 1);
(void)strcpy(csinfo[i].ppath, (const char *)ppath); (void)strcpy(csinfo[i].ppath, (const char *)ppath);
} else } else
csinfo[i].ppath = NULL; csinfo[i].ppath = NULL;
if (flags != NULL) { if (flags != NULL) {
csinfo[i].flags = (char *)alloc((unsigned)strlen(flags) + 1); csinfo[i].flags = xmalloc(strlen(flags) + 1);
(void)strcpy(csinfo[i].flags, (const char *)flags); (void)strcpy(csinfo[i].flags, (const char *)flags);
} else } else
csinfo[i].flags = NULL; csinfo[i].flags = NULL;
@ -1553,13 +1552,12 @@ static char *cs_parse_results(int cnumber, char *buf, int bufsize, char **contex
static void cs_file_results(FILE *f, int *nummatches_a) static void cs_file_results(FILE *f, int *nummatches_a)
{ {
int i, j; int i, j;
char *buf;
char *search, *slno; char *search, *slno;
char *fullname; char *fullname;
char *cntx; char *cntx;
char *context; char *context;
buf = (char *)alloc(CSREAD_BUFSIZE); char *buf = xmalloc(CSREAD_BUFSIZE);
for (i = 0; i < csinfo_size; i++) { for (i = 0; i < csinfo_size; i++) {
if (nummatches_a[i] < 1) if (nummatches_a[i] < 1)
@ -1570,7 +1568,7 @@ static void cs_file_results(FILE *f, int *nummatches_a)
&slno, &search)) == NULL) &slno, &search)) == NULL)
continue; continue;
context = (char *)alloc((unsigned)strlen(cntx)+5); context = xmalloc(strlen(cntx) + 5);
if (strcmp(cntx, "<global>")==0) if (strcmp(cntx, "<global>")==0)
strcpy(context, "<<global>>"); strcpy(context, "<<global>>");
@ -1633,10 +1631,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++;
@ -1689,9 +1684,6 @@ static char *cs_pathcomponents(char *path)
*/ */
static void cs_print_tags_priv(char **matches, char **cntxts, int num_matches) static void cs_print_tags_priv(char **matches, char **cntxts, int num_matches)
{ {
char *buf = NULL;
int bufsize = 0; /* Track available bufsize */
int newsize = 0;
char *ptag; char *ptag;
char *fname, *lno, *extra, *tbuf; char *fname, *lno, *extra, *tbuf;
int i, idx, num; int i, idx, num;
@ -1703,14 +1695,14 @@ static void cs_print_tags_priv(char **matches, char **cntxts, int num_matches)
assert (num_matches > 0); assert (num_matches > 0);
tbuf = (char *)alloc((unsigned)strlen(matches[0]) + 1); tbuf = xmalloc(strlen(matches[0]) + 1);
strcpy(tbuf, matches[0]); strcpy(tbuf, matches[0]);
ptag = strtok(tbuf, "\t"); ptag = strtok(tbuf, "\t");
newsize = (int)(strlen(cstag_msg) + strlen(ptag)); size_t newsize = strlen(cstag_msg) + strlen(ptag);
buf = (char *)alloc(newsize); char *buf = xmalloc(newsize);
bufsize = newsize; size_t bufsize = newsize; // Track available bufsize
(void)sprintf(buf, cstag_msg, ptag); (void)sprintf(buf, cstag_msg, ptag);
MSG_PUTS_ATTR(buf, hl_attr(HLF_T)); MSG_PUTS_ATTR(buf, hl_attr(HLF_T));
@ -1728,7 +1720,7 @@ static void cs_print_tags_priv(char **matches, char **cntxts, int num_matches)
* by parsing matches[i] on the fly and placing stuff into buf * by parsing matches[i] on the fly and placing stuff into buf
* directly, but that's too much of a hassle * directly, but that's too much of a hassle
*/ */
tbuf = (char *)alloc((unsigned)strlen(matches[idx]) + 1); tbuf = xmalloc(strlen(matches[idx]) + 1);
(void)strcpy(tbuf, matches[idx]); (void)strcpy(tbuf, matches[idx]);
if (strtok(tbuf, (const char *)"\t") == NULL) if (strtok(tbuf, (const char *)"\t") == NULL)
@ -1742,9 +1734,9 @@ static void cs_print_tags_priv(char **matches, char **cntxts, int num_matches)
lno[strlen(lno)-2] = '\0'; /* ignore ;" at the end */ lno[strlen(lno)-2] = '\0'; /* ignore ;" at the end */
/* hopefully 'num' (num of matches) will be less than 10^16 */ /* hopefully 'num' (num of matches) will be less than 10^16 */
newsize = (int)(strlen(csfmt_str) + 16 + strlen(lno)); newsize = strlen(csfmt_str) + 16 + strlen(lno);
if (bufsize < newsize) { if (bufsize < newsize) {
buf = (char *)xrealloc(buf, newsize); buf = xrealloc(buf, newsize);
bufsize = newsize; bufsize = newsize;
} }
if (buf != NULL) { if (buf != NULL) {
@ -1759,10 +1751,10 @@ static void cs_print_tags_priv(char **matches, char **cntxts, int num_matches)
context = cntxts[idx]; context = cntxts[idx];
else else
context = globalcntx; context = globalcntx;
newsize = (int)(strlen(context) + strlen(cntxformat)); newsize = strlen(context) + strlen(cntxformat);
if (bufsize < newsize) { if (bufsize < newsize) {
buf = (char *)xrealloc(buf, newsize); buf = xrealloc(buf, newsize);
bufsize = newsize; bufsize = newsize;
} }
if (buf != NULL) { if (buf != NULL) {
@ -1822,9 +1814,11 @@ static int cs_read_prompt(int i)
while ((ch = getc(csinfo[i].fr_fp)) != EOF && ch != CSCOPE_PROMPT[0]) while ((ch = getc(csinfo[i].fr_fp)) != EOF && ch != CSCOPE_PROMPT[0])
/* if there is room and char is printable */ /* if there is room and char is printable */
if (bufpos < maxlen - 1 && vim_isprintc(ch)) { if (bufpos < maxlen - 1 && vim_isprintc(ch)) {
if (buf == NULL) /* lazy buffer allocation */ // lazy buffer allocation
buf = (char *)alloc(maxlen); if (buf == NULL) {
if (buf != NULL) { buf = xmalloc(maxlen);
}
{
/* append character to the message */ /* append character to the message */
buf[bufpos++] = ch; buf[bufpos++] = ch;
buf[bufpos] = NUL; buf[bufpos] = NUL;
@ -2075,7 +2069,6 @@ static int cs_reset(exarg_T *eap)
static char *cs_resolve_file(int i, char *name) static char *cs_resolve_file(int i, char *name)
{ {
char *fullname; char *fullname;
int len;
char_u *csdir = NULL; char_u *csdir = NULL;
/* /*
@ -2083,17 +2076,17 @@ static char *cs_resolve_file(int i, char *name)
* Fullname is freed after cs_make_vim_style_matches, after it's been * Fullname is freed after cs_make_vim_style_matches, after it's been
* copied into the tag buffer used by Vim. * copied into the tag buffer used by Vim.
*/ */
len = (int)(strlen(name) + 2); size_t len = strlen(name) + 2;
if (csinfo[i].ppath != NULL) if (csinfo[i].ppath != NULL)
len += (int)strlen(csinfo[i].ppath); len += strlen(csinfo[i].ppath);
else if (p_csre && csinfo[i].fname != NULL) { else if (p_csre && csinfo[i].fname != NULL) {
/* If 'cscoperelative' is set and ppath is not set, use cscope.out /* If 'cscoperelative' is set and ppath is not set, use cscope.out
* path in path resolution. */ * path in path resolution. */
csdir = alloc(MAXPATHL); csdir = xmalloc(MAXPATHL);
vim_strncpy(csdir, (char_u *)csinfo[i].fname, vim_strncpy(csdir, (char_u *)csinfo[i].fname,
path_tail((char_u *)csinfo[i].fname) path_tail((char_u *)csinfo[i].fname)
- (char_u *)csinfo[i].fname); - (char_u *)csinfo[i].fname);
len += (int)STRLEN(csdir); len += STRLEN(csdir);
} }
/* Note/example: this won't work if the cscope output already starts /* Note/example: this won't work if the cscope output already starts
@ -2110,7 +2103,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

@ -182,7 +182,7 @@ int set_indent(int size, int flags)
// characters and allocate accordingly. We will fill the rest with spaces // characters and allocate accordingly. We will fill the rest with spaces
// after the if (!curbuf->b_p_et) below. // after the if (!curbuf->b_p_et) below.
if (orig_char_len != -1) { if (orig_char_len != -1) {
newline = alloc(orig_char_len + size - ind_done + line_len); newline = xmalloc(orig_char_len + size - ind_done + line_len);
todo = size - ind_done; todo = size - ind_done;
// Set total length of indent in characters, which may have been // Set total length of indent in characters, which may have been
@ -203,7 +203,7 @@ int set_indent(int size, int flags)
} }
} else { } else {
todo = size; todo = size;
newline = alloc(ind_len + line_len); newline = xmalloc(ind_len + line_len);
s = newline; s = newline;
} }
@ -368,7 +368,7 @@ int copy_indent(int size, char_u *src)
// Allocate memory for the result: the copied indent, new indent // Allocate memory for the result: the copied indent, new indent
// and the rest of the line. // and the rest of the line.
line_len = (int)STRLEN(ml_get_curline()) + 1; line_len = (int)STRLEN(ml_get_curline()) + 1;
line = alloc(ind_len + line_len); line = xmalloc(ind_len + line_len);
p = line; p = line;
} }
} }

View File

@ -122,7 +122,7 @@ int cin_is_cinword(char_u *line)
int len; int len;
cinw_len = (int)STRLEN(curbuf->b_p_cinw) + 1; cinw_len = (int)STRLEN(curbuf->b_p_cinw) + 1;
cinw_buf = alloc((unsigned)cinw_len); cinw_buf = xmalloc(cinw_len);
line = skipwhite(line); line = skipwhite(line);
for (cinw = curbuf->b_p_cinw; *cinw; ) { for (cinw = curbuf->b_p_cinw; *cinw; ) {
len = copy_option_part(&cinw, cinw_buf, cinw_len, ","); len = copy_option_part(&cinw, cinw_buf, cinw_len, ",");

View File

@ -1308,7 +1308,7 @@ static void command_line_scan(mparm_T *parmp)
--argv; --argv;
} else } else
a = argv[0]; a = argv[0];
p = alloc((unsigned)(STRLEN(a) + 4)); p = xmalloc(STRLEN(a) + 4);
sprintf((char *)p, "so %s", a); sprintf((char *)p, "so %s", a);
parmp->cmds_tofree[parmp->n_commands] = TRUE; parmp->cmds_tofree[parmp->n_commands] = TRUE;
parmp->commands[parmp->n_commands++] = p; parmp->commands[parmp->n_commands++] = p;
@ -1352,8 +1352,7 @@ scripterror:
mch_errmsg("\"\n"); mch_errmsg("\"\n");
mch_exit(2); mch_exit(2);
} }
if (save_typebuf() == FAIL) save_typebuf();
mch_exit(2); /* out of memory */
break; break;
case 't': /* "-t {tag}" */ case 't': /* "-t {tag}" */
@ -1415,8 +1414,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;
@ -1456,7 +1455,7 @@ scripterror:
/* If there is a "+123" or "-c" command, set v:swapcommand to the first /* If there is a "+123" or "-c" command, set v:swapcommand to the first
* one. */ * one. */
if (parmp->n_commands > 0) { if (parmp->n_commands > 0) {
p = alloc((unsigned)STRLEN(parmp->commands[0]) + 3); p = xmalloc(STRLEN(parmp->commands[0]) + 3);
sprintf((char *)p, ":%s\r", parmp->commands[0]); sprintf((char *)p, ":%s\r", parmp->commands[0]);
set_vim_var_string(VV_SWAPCOMMAND, p, -1); set_vim_var_string(VV_SWAPCOMMAND, p, -1);
free(p); free(p);
@ -1502,7 +1501,7 @@ static void init_startuptime(mparm_T *paramp)
*/ */
static void allocate_generic_buffers(void) static void allocate_generic_buffers(void)
{ {
NameBuff = alloc(MAXPATHL); NameBuff = xmalloc(MAXPATHL);
TIME_MSG("Allocated generic buffers"); TIME_MSG("Allocated generic buffers");
} }

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)) {
@ -844,8 +843,6 @@ void ex_changes(exarg_T *eap)
curbuf->b_changelist[i].col); curbuf->b_changelist[i].col);
msg_outtrans(IObuff); msg_outtrans(IObuff);
name = mark_line(&curbuf->b_changelist[i], 17); name = mark_line(&curbuf->b_changelist[i], 17);
if (name == NULL)
break;
msg_outtrans_attr(name, hl_attr(HLF_D)); msg_outtrans_attr(name, hl_attr(HLF_D));
free(name); free(name);
ui_breakcheck(); ui_breakcheck();
@ -1418,7 +1415,7 @@ void copy_viminfo_marks(vir_T *virp, FILE *fp_out, int count, int eof, int flags
pos_T pos; pos_T pos;
list_T *list = NULL; list_T *list = NULL;
name_buf = alloc(LSIZE); name_buf = xmalloc(LSIZE);
*name_buf = NUL; *name_buf = NUL;
if (fp_out == NULL && (flags & (VIF_GET_OLDFILES | VIF_FORCEIT))) { if (fp_out == NULL && (flags & (VIF_GET_OLDFILES | VIF_FORCEIT))) {

View File

@ -3333,7 +3333,7 @@ char_u * enc_canonize(char_u *enc)
} }
/* copy "enc" to allocated memory, with room for two '-' */ /* copy "enc" to allocated memory, with room for two '-' */
r = alloc((unsigned)(STRLEN(enc) + 3)); r = xmalloc(STRLEN(enc) + 3);
/* Make it all lower case and replace '_' with '-'. */ /* Make it all lower case and replace '_' with '-'. */
p = r; p = r;
for (s = enc; *s != NUL; ++s) { for (s = enc; *s != NUL; ++s) {
@ -3534,7 +3534,7 @@ static char_u * iconv_string(vimconv_T *vcp, char_u *str, int slen, int *unconvl
/* Allocate enough room for most conversions. When re-allocating /* Allocate enough room for most conversions. When re-allocating
* increase the buffer size. */ * increase the buffer size. */
len = len + fromlen * 2 + 40; len = len + fromlen * 2 + 40;
p = alloc((unsigned)len); p = xmalloc(len);
if (done > 0) if (done > 0)
memmove(p, result, done); memmove(p, result, done);
free(result); free(result);
@ -3852,7 +3852,7 @@ int convert_input_safe(ptr, len, maxlen, restp, restlenp)
if (dlen <= maxlen) { if (dlen <= maxlen) {
if (unconvertlen > 0) { if (unconvertlen > 0) {
/* Move the unconverted characters to allocated memory. */ /* Move the unconverted characters to allocated memory. */
*restp = alloc(unconvertlen); *restp = xmalloc(unconvertlen);
memmove(*restp, ptr + len - unconvertlen, unconvertlen); memmove(*restp, ptr + len - unconvertlen, unconvertlen);
*restlenp = unconvertlen; *restlenp = unconvertlen;
} }
@ -3908,7 +3908,7 @@ char_u * string_convert_ext(vcp, ptr, lenp, unconvlenp)
switch (vcp->vc_type) { switch (vcp->vc_type) {
case CONV_TO_UTF8: /* latin1 to utf-8 conversion */ case CONV_TO_UTF8: /* latin1 to utf-8 conversion */
retval = alloc(len * 2 + 1); retval = xmalloc(len * 2 + 1);
d = retval; d = retval;
for (i = 0; i < len; ++i) { for (i = 0; i < len; ++i) {
c = ptr[i]; c = ptr[i];
@ -3925,7 +3925,7 @@ char_u * string_convert_ext(vcp, ptr, lenp, unconvlenp)
break; break;
case CONV_9_TO_UTF8: /* latin9 to utf-8 conversion */ case CONV_9_TO_UTF8: /* latin9 to utf-8 conversion */
retval = alloc(len * 3 + 1); retval = xmalloc(len * 3 + 1);
d = retval; d = retval;
for (i = 0; i < len; ++i) { for (i = 0; i < len; ++i) {
c = ptr[i]; c = ptr[i];
@ -3948,7 +3948,7 @@ char_u * string_convert_ext(vcp, ptr, lenp, unconvlenp)
case CONV_TO_LATIN1: /* utf-8 to latin1 conversion */ case CONV_TO_LATIN1: /* utf-8 to latin1 conversion */
case CONV_TO_LATIN9: /* utf-8 to latin9 conversion */ case CONV_TO_LATIN9: /* utf-8 to latin9 conversion */
retval = alloc(len + 1); retval = xmalloc(len + 1);
d = retval; d = retval;
for (i = 0; i < len; ++i) { for (i = 0; i < len; ++i) {
l = utf_ptr2len_len(ptr + i, len - i); l = utf_ptr2len_len(ptr + i, len - i);

View File

@ -104,11 +104,9 @@ static void mf_hash_grow(mf_hashtab_T *);
*/ */
memfile_T *mf_open(char_u *fname, int flags) memfile_T *mf_open(char_u *fname, int flags)
{ {
memfile_T *mfp;
off_t size; off_t size;
if ((mfp = (memfile_T *)alloc((unsigned)sizeof(memfile_T))) == NULL) memfile_T *mfp = xmalloc(sizeof(memfile_T));
return NULL;
if (fname == NULL) { /* no file for this memfile, use memory only */ if (fname == NULL) { /* no file for this memfile, use memory only */
mfp->mf_fname = NULL; mfp->mf_fname = NULL;
@ -316,14 +314,14 @@ bhdr_T *mf_new(memfile_T *mfp, int negative, int page_count)
* just use the number and free the bhdr_T from the free list * just use the number and free the bhdr_T from the free list
*/ */
if (freep->bh_page_count > page_count) { if (freep->bh_page_count > page_count) {
if (hp == NULL && (hp = mf_alloc_bhdr(mfp, page_count)) == NULL) if (hp == NULL) {
return NULL; hp = mf_alloc_bhdr(mfp, page_count);
}
hp->bh_bnum = freep->bh_bnum; hp->bh_bnum = freep->bh_bnum;
freep->bh_bnum += page_count; freep->bh_bnum += page_count;
freep->bh_page_count -= page_count; freep->bh_page_count -= page_count;
} else if (hp == NULL) { /* need to allocate memory for this block */ } else if (hp == NULL) { /* need to allocate memory for this block */
if ((p = (char_u *)alloc(mfp->mf_page_size * page_count)) == NULL) p = xmalloc(mfp->mf_page_size * page_count);
return NULL;
hp = mf_rem_free(mfp); hp = mf_rem_free(mfp);
hp->bh_data = p; hp->bh_data = p;
} else { /* use the number, remove entry from free list */ } else { /* use the number, remove entry from free list */
@ -332,8 +330,9 @@ bhdr_T *mf_new(memfile_T *mfp, int negative, int page_count)
free(freep); free(freep);
} }
} else { /* get a new number */ } else { /* get a new number */
if (hp == NULL && (hp = mf_alloc_bhdr(mfp, page_count)) == NULL) if (hp == NULL) {
return NULL; hp = mf_alloc_bhdr(mfp, page_count);
}
if (negative) { if (negative) {
hp->bh_bnum = mfp->mf_blocknr_min--; hp->bh_bnum = mfp->mf_blocknr_min--;
mfp->mf_neg_count++; mfp->mf_neg_count++;
@ -386,8 +385,9 @@ bhdr_T *mf_get(memfile_T *mfp, blocknr_T nr, int page_count)
* If not, allocate a new block. * If not, allocate a new block.
*/ */
hp = mf_release(mfp, page_count); hp = mf_release(mfp, page_count);
if (hp == NULL && (hp = mf_alloc_bhdr(mfp, page_count)) == NULL) if (hp == NULL) {
return NULL; hp = mf_alloc_bhdr(mfp, page_count);
}
hp->bh_bnum = nr; hp->bh_bnum = nr;
hp->bh_flags = 0; hp->bh_flags = 0;
@ -689,10 +689,7 @@ static bhdr_T *mf_release(memfile_T *mfp, int page_count)
*/ */
if (hp->bh_page_count != page_count) { if (hp->bh_page_count != page_count) {
free(hp->bh_data); free(hp->bh_data);
if ((hp->bh_data = alloc(mfp->mf_page_size * page_count)) == NULL) { hp->bh_data = xmalloc(mfp->mf_page_size * page_count);
free(hp);
return NULL;
}
hp->bh_page_count = page_count; hp->bh_page_count = page_count;
} }
return hp; return hp;
@ -743,16 +740,10 @@ int mf_release_all(void)
*/ */
static bhdr_T *mf_alloc_bhdr(memfile_T *mfp, int page_count) static bhdr_T *mf_alloc_bhdr(memfile_T *mfp, int page_count)
{ {
bhdr_T *hp; bhdr_T *hp = xmalloc(sizeof(bhdr_T));
hp->bh_data = xmalloc(mfp->mf_page_size * page_count);
if ((hp = (bhdr_T *)alloc((unsigned)sizeof(bhdr_T))) != NULL) {
if ((hp->bh_data = (char_u *)alloc(mfp->mf_page_size * page_count))
== NULL) {
free(hp); /* not enough memory */
return NULL;
}
hp->bh_page_count = page_count; hp->bh_page_count = page_count;
}
return hp; return hp;
} }
@ -911,14 +902,12 @@ static int mf_trans_add(memfile_T *mfp, bhdr_T *hp)
{ {
bhdr_T *freep; bhdr_T *freep;
blocknr_T new_bnum; blocknr_T new_bnum;
NR_TRANS *np;
int page_count; int page_count;
if (hp->bh_bnum >= 0) /* it's already positive */ if (hp->bh_bnum >= 0) /* it's already positive */
return OK; return OK;
if ((np = (NR_TRANS *)alloc((unsigned)sizeof(NR_TRANS))) == NULL) NR_TRANS *np = xmalloc(sizeof(NR_TRANS));
return FAIL;
/* /*
* Get a new number for the block. * Get a new number for the block.

View File

@ -313,8 +313,7 @@ int ml_open(buf_T *buf)
/* /*
* fill block0 struct and write page 0 * fill block0 struct and write page 0
*/ */
if ((hp = mf_new(mfp, FALSE, 1)) == NULL) hp = mf_new(mfp, FALSE, 1);
goto error;
if (hp->bh_bnum != 0) { if (hp->bh_bnum != 0) {
EMSG(_("E298: Didn't get block nr 0?")); EMSG(_("E298: Didn't get block nr 0?"));
goto error; goto error;
@ -373,8 +372,7 @@ int ml_open(buf_T *buf)
/* /*
* Allocate first data block and create an empty line 1. * Allocate first data block and create an empty line 1.
*/ */
if ((hp = ml_new_data(mfp, FALSE, 1)) == NULL) hp = ml_new_data(mfp, FALSE, 1);
goto error;
if (hp->bh_bnum != 2) { if (hp->bh_bnum != 2) {
EMSG(_("E298: Didn't get block nr 2?")); EMSG(_("E298: Didn't get block nr 2?"));
goto error; goto error;
@ -857,7 +855,7 @@ void ml_recover(void)
* Allocate a buffer structure for the swap file that is used for recovery. * Allocate a buffer structure for the swap file that is used for recovery.
* Only the memline in it is really used. * Only the memline in it is really used.
*/ */
buf = (buf_T *)alloc((unsigned)sizeof(buf_T)); buf = xmalloc(sizeof(buf_T));
/* /*
* init fields in memline struct * init fields in memline struct
@ -956,7 +954,7 @@ void ml_recover(void)
mfp->mf_infile_count = mfp->mf_blocknr_max; mfp->mf_infile_count = mfp->mf_blocknr_max;
/* need to reallocate the memory used to store the data */ /* need to reallocate the memory used to store the data */
p = alloc(mfp->mf_page_size); p = xmalloc(mfp->mf_page_size);
memmove(p, hp->bh_data, previous_page_size); memmove(p, hp->bh_data, previous_page_size);
free(hp->bh_data); free(hp->bh_data);
hp->bh_data = p; hp->bh_data = p;
@ -1334,7 +1332,7 @@ recover_names (
* Do the loop for every directory in 'directory'. * Do the loop for every directory in 'directory'.
* First allocate some memory to put the directory name in. * First allocate some memory to put the directory name in.
*/ */
dir_name = alloc((unsigned)STRLEN(p_dir) + 1); dir_name = xmalloc(STRLEN(p_dir) + 1);
dirp = p_dir; dirp = p_dir;
while (dir_name != NULL && *dirp) { while (dir_name != NULL && *dirp) {
/* /*
@ -1408,7 +1406,7 @@ recover_names (
char_u *swapname = modname(fname_res, (char_u *)".swp", TRUE); char_u *swapname = modname(fname_res, (char_u *)".swp", TRUE);
if (swapname != NULL) { if (swapname != NULL) {
if (os_file_exists(swapname)) { if (os_file_exists(swapname)) {
files = (char_u **)alloc((unsigned)sizeof(char_u *)); files = (char_u **)xmalloc(sizeof(char_u *));
files[0] = swapname; files[0] = swapname;
swapname = NULL; swapname = NULL;
num_files = 1; num_files = 1;
@ -2118,12 +2116,7 @@ ml_append_int (
} }
page_count = ((space_needed + HEADER_SIZE) + page_size - 1) / page_size; page_count = ((space_needed + HEADER_SIZE) + page_size - 1) / page_size;
if ((hp_new = ml_new_data(mfp, newfile, page_count)) == NULL) { hp_new = ml_new_data(mfp, newfile, page_count);
/* correct line counts in pointer blocks */
--(buf->b_ml.ml_locked_lineadd);
--(buf->b_ml.ml_locked_high);
return FAIL;
}
if (db_idx < 0) { /* left block is new */ if (db_idx < 0) { /* left block is new */
hp_left = hp_new; hp_left = hp_new;
hp_right = hp; hp_right = hp;
@ -2403,8 +2396,9 @@ 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 */
@ -2777,13 +2771,8 @@ static void ml_flush_line(buf_T *buf)
*/ */
static bhdr_T *ml_new_data(memfile_T *mfp, int negative, int page_count) static bhdr_T *ml_new_data(memfile_T *mfp, int negative, int page_count)
{ {
bhdr_T *hp; bhdr_T *hp = mf_new(mfp, negative, page_count);
DATA_BL *dp; DATA_BL *dp = (DATA_BL *)(hp->bh_data);
if ((hp = mf_new(mfp, negative, page_count)) == NULL)
return NULL;
dp = (DATA_BL *)(hp->bh_data);
dp->db_id = DATA_ID; dp->db_id = DATA_ID;
dp->db_txt_start = dp->db_txt_end = page_count * mfp->mf_page_size; dp->db_txt_start = dp->db_txt_end = page_count * mfp->mf_page_size;
dp->db_free = dp->db_txt_start - HEADER_SIZE; dp->db_free = dp->db_txt_start - HEADER_SIZE;
@ -2797,13 +2786,8 @@ static bhdr_T *ml_new_data(memfile_T *mfp, int negative, int page_count)
*/ */
static bhdr_T *ml_new_ptr(memfile_T *mfp) static bhdr_T *ml_new_ptr(memfile_T *mfp)
{ {
bhdr_T *hp; bhdr_T *hp = mf_new(mfp, FALSE, 1);
PTR_BL *pp; PTR_BL *pp = (PTR_BL *)(hp->bh_data);
if ((hp = mf_new(mfp, FALSE, 1)) == NULL)
return NULL;
pp = (PTR_BL *)(hp->bh_data);
pp->pb_id = PTR_ID; pp->pb_id = PTR_ID;
pp->pb_count = 0; pp->pb_count = 0;
pp->pb_count_max = (mfp->mf_page_size - sizeof(PTR_BL)) / sizeof(PTR_EN) + 1; pp->pb_count_max = (mfp->mf_page_size - sizeof(PTR_BL)) / sizeof(PTR_EN) + 1;
@ -3335,7 +3319,7 @@ findswapname (
* Isolate a directory name from *dirp and put it in dir_name. * Isolate a directory name from *dirp and put it in dir_name.
* First allocate some memory to put the directory name in. * First allocate some memory to put the directory name in.
*/ */
dir_name = alloc((unsigned)STRLEN(*dirp) + 1); dir_name = xmalloc(STRLEN(*dirp) + 1);
(void)copy_option_part(dirp, dir_name, 31000, ","); (void)copy_option_part(dirp, dir_name, 31000, ",");
/* /*
@ -3462,9 +3446,9 @@ findswapname (
if (swap_exists_action != SEA_NONE && choice == 0) { if (swap_exists_action != SEA_NONE && choice == 0) {
char_u *name; char_u *name;
name = alloc((unsigned)(STRLEN(fname) name = xmalloc(STRLEN(fname)
+ STRLEN(_("Swap file \"")) + STRLEN(_("Swap file \""))
+ STRLEN(_("\" already exists!")) + 5)); + STRLEN(_("\" already exists!")) + 5);
STRCPY(name, _("Swap file \"")); STRCPY(name, _("Swap file \""));
home_replace(NULL, fname, name + STRLEN(name), home_replace(NULL, fname, name + STRLEN(name),
1000, TRUE); 1000, TRUE);

View File

@ -43,14 +43,6 @@
static void try_to_free_memory(); static void try_to_free_memory();
/*
* Note: if unsigned is 16 bits we can only allocate up to 64K with alloc().
*/
char_u *alloc(unsigned size)
{
return xmalloc(size);
}
/// Try to free memory. Used when trying to recover from out of memory errors. /// Try to free memory. Used when trying to recover from out of memory errors.
/// @see {xmalloc} /// @see {xmalloc}
static void try_to_free_memory() static void try_to_free_memory()

View File

@ -5,8 +5,6 @@
#include "nvim/types.h" #include "nvim/types.h"
#include "nvim/vim.h" #include "nvim/vim.h"
char_u *alloc(unsigned size) FUNC_ATTR_MALLOC FUNC_ATTR_ALLOC_SIZE(1);
/// malloc() wrapper /// malloc() wrapper
/// ///
/// try_malloc() is a malloc() wrapper that tries to free some memory before /// try_malloc() is a malloc() wrapper that tries to free some memory before

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;
@ -464,7 +462,7 @@ add_menu_path (
} }
if (c != 0) { if (c != 0) {
menu->strings[i] = alloc((unsigned)(STRLEN(call_data) + 5 )); menu->strings[i] = xmalloc(STRLEN(call_data) + 5 );
menu->strings[i][0] = c; menu->strings[i][0] = c;
if (d == 0) if (d == 0)
STRCPY(menu->strings[i] + 1, call_data); STRCPY(menu->strings[i] + 1, call_data);
@ -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,10 +1504,9 @@ 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 && to != NULL) { if (from_noamp != 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);
@ -1533,7 +1523,6 @@ void ex_menutranslate(exarg_T *eap)
} }
} }
} }
}
/* /*
* Find the character just after one part of a menu name. * Find the character just after one part of a menu name.

View File

@ -267,7 +267,7 @@ msg_strtrunc (
len = (room + 2) * 2; len = (room + 2) * 2;
else else
len = room + 2; len = room + 2;
buf = alloc(len); buf = xmalloc(len);
trunc_string(s, buf, room, len); trunc_string(s, buf, room, len);
} }
} }
@ -421,7 +421,7 @@ static char_u *get_emsg_source(void)
if (sourcing_name != NULL && other_sourcing_name()) { if (sourcing_name != NULL && other_sourcing_name()) {
p = (char_u *)_("Error detected while processing %s:"); p = (char_u *)_("Error detected while processing %s:");
Buf = alloc((unsigned)(STRLEN(sourcing_name) + STRLEN(p))); Buf = xmalloc(STRLEN(sourcing_name) + STRLEN(p));
sprintf((char *)Buf, (char *)p, sourcing_name); sprintf((char *)Buf, (char *)p, sourcing_name);
return Buf; return Buf;
} }
@ -443,7 +443,7 @@ static char_u *get_emsg_lnum(void)
&& (other_sourcing_name() || sourcing_lnum != last_sourcing_lnum) && (other_sourcing_name() || sourcing_lnum != last_sourcing_lnum)
&& sourcing_lnum != 0) { && sourcing_lnum != 0) {
p = (char_u *)_("line %4ld:"); p = (char_u *)_("line %4ld:");
Buf = alloc((unsigned)(STRLEN(p) + 20)); Buf = xmalloc(STRLEN(p) + 20);
sprintf((char *)Buf, (char *)p, (long)sourcing_lnum); sprintf((char *)Buf, (char *)p, (long)sourcing_lnum);
return Buf; return Buf;
} }
@ -680,8 +680,6 @@ add_msg_hist (
int attr int attr
) )
{ {
struct msg_hist *p;
if (msg_hist_off || msg_silent != 0) if (msg_hist_off || msg_silent != 0)
return; return;
@ -690,7 +688,7 @@ add_msg_hist (
(void)delete_first_msg(); (void)delete_first_msg();
/* allocate an entry and add the message at the end of the history */ /* allocate an entry and add the message at the end of the history */
p = (struct msg_hist *)alloc((int)sizeof(struct msg_hist)); struct msg_hist *p = xmalloc(sizeof(struct msg_hist));
if (len < 0) if (len < 0)
len = (int)STRLEN(s); len = (int)STRLEN(s);
/* remove leading and trailing newlines */ /* remove leading and trailing newlines */
@ -1841,7 +1839,7 @@ static void inc_msg_scrolled(void)
p = (char_u *)_("Unknown"); p = (char_u *)_("Unknown");
else { else {
len = (int)STRLEN(p) + 40; len = (int)STRLEN(p) + 40;
tofree = alloc(len); tofree = xmalloc(len);
vim_snprintf((char *)tofree, len, _("%s line %" PRId64), vim_snprintf((char *)tofree, len, _("%s line %" PRId64),
p, (int64_t)sourcing_lnum); p, (int64_t)sourcing_lnum);
p = tofree; p = tofree;
@ -1893,7 +1891,7 @@ store_sb_text (
} }
if (s > *sb_str) { if (s > *sb_str) {
mp = (msgchunk_T *)alloc((int)(sizeof(msgchunk_T) + (s - *sb_str))); mp = xmalloc((sizeof(msgchunk_T) + (s - *sb_str)));
mp->sb_eol = finish; mp->sb_eol = finish;
mp->sb_msg_col = *sb_col; mp->sb_msg_col = *sb_col;
mp->sb_attr = attr; mp->sb_attr = attr;

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
@ -505,7 +501,7 @@ open_line (
} }
if (lead_len) { if (lead_len) {
/* allocate buffer (may concatenate p_extra later) */ /* allocate buffer (may concatenate p_extra later) */
leader = alloc(lead_len + lead_repl_len + extra_space + extra_len leader = xmalloc(lead_len + lead_repl_len + extra_space + extra_len
+ (second_line_indent > 0 ? second_line_indent : 0) + 1); + (second_line_indent > 0 ? second_line_indent : 0) + 1);
allocated = leader; /* remember to free it later */ allocated = leader; /* remember to free it later */
@ -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);
@ -1708,9 +1702,7 @@ del_bytes (
if (was_alloced) if (was_alloced)
newp = oldp; /* use same allocated memory */ newp = oldp; /* use same allocated memory */
else { /* need to allocate a new line */ else { /* need to allocate a new line */
newp = alloc((unsigned)(oldlen + 1 - count)); newp = xmalloc(oldlen + 1 - count);
if (newp == NULL)
return FAIL;
memmove(newp, oldp, (size_t)col); memmove(newp, oldp, (size_t)col);
} }
memmove(newp + col, oldp + col + count, (size_t)movelen); memmove(newp + col, oldp + col + count, (size_t)movelen);
@ -1726,10 +1718,8 @@ del_bytes (
/* /*
* Delete from cursor to end of line. * Delete from cursor to end of line.
* Caller must have prepared for undo. * Caller must have prepared for undo.
*
* return FAIL for failure, OK otherwise
*/ */
int void
truncate_line ( truncate_line (
int fixpos /* if TRUE fix the cursor position when done */ int fixpos /* if TRUE fix the cursor position when done */
) )
@ -1743,9 +1733,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 */
@ -1756,8 +1743,6 @@ truncate_line (
*/ */
if (fixpos && curwin->w_cursor.col > 0) if (fixpos && curwin->w_cursor.col > 0)
--curwin->w_cursor.col; --curwin->w_cursor.col;
return OK;
} }
/* /*
@ -2404,7 +2389,7 @@ int get_keystroke(void)
* bytes. */ * bytes. */
maxlen = (buflen - 6 - len) / 3; maxlen = (buflen - 6 - len) / 3;
if (buf == NULL) if (buf == NULL)
buf = alloc(buflen); buf = xmalloc(buflen);
else if (maxlen < 10) { else if (maxlen < 10) {
/* Need some more space. This might happen when receiving a long /* Need some more space. This might happen when receiving a long
* escape sequence. */ * escape sequence. */
@ -2724,9 +2709,7 @@ char_u *expand_env_save(char_u *src)
*/ */
char_u *expand_env_save_opt(char_u *src, int one) char_u *expand_env_save_opt(char_u *src, int one)
{ {
char_u *p; char_u *p = xmalloc(MAXPATHL);
p = alloc(MAXPATHL);
expand_env_esc(src, p, MAXPATHL, FALSE, one, NULL); expand_env_esc(src, p, MAXPATHL, FALSE, one, NULL);
return p; return p;
} }
@ -2874,14 +2857,13 @@ 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
/* If "var" contains white space, escape it with a backslash. /* If "var" contains white space, escape it with a backslash.
@ -3033,7 +3015,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 {
@ -3332,13 +3314,12 @@ home_replace_save (
) )
{ {
char_u *dst; char_u *dst;
unsigned len;
len = 3; /* space for "~/" and trailing NUL */ size_t len = 3; /* space for "~/" and trailing NUL */
if (src != NULL) /* just in case */ if (src != NULL) /* just in case */
len += (unsigned)STRLEN(src); len += STRLEN(src);
dst = alloc(len); dst = xmalloc(len);
home_replace(buf, src, dst, len, TRUE); home_replace(buf, src, dst, (int)len, TRUE);
return dst; return dst;
} }
@ -3499,7 +3480,7 @@ get_cmd_output (
len = ftell(fd); /* get size of temp file */ len = ftell(fd); /* get size of temp file */
fseek(fd, 0L, SEEK_SET); fseek(fd, 0L, SEEK_SET);
buffer = alloc(len + 1); buffer = xmalloc(len + 1);
i = (int)fread((char *)buffer, (size_t)1, (size_t)len, fd); i = (int)fread((char *)buffer, (size_t)1, (size_t)len, fd);
fclose(fd); fclose(fd);
os_remove((char *)tempname); os_remove((char *)tempname);

View File

@ -22,7 +22,7 @@ void ins_str(char_u *s);
int del_char(int fixpos); int del_char(int fixpos);
int del_chars(long count, int fixpos); int del_chars(long count, int fixpos);
int del_bytes(long count, int fixpos_arg, int use_delcombine); int del_bytes(long count, int fixpos_arg, int use_delcombine);
int truncate_line(int fixpos); void truncate_line(int fixpos);
void del_lines(long nlines, int undo); void del_lines(long nlines, int undo);
int gchar_pos(pos_T *pos); int gchar_pos(pos_T *pos);
int gchar_cursor(void); int gchar_cursor(void);

View File

@ -229,7 +229,7 @@ coladvance2 (
if (line[idx] == NUL) { if (line[idx] == NUL) {
/* Append spaces */ /* Append spaces */
int correct = wcol - col; int correct = wcol - col;
char_u *newline = alloc(idx + correct + 1); char_u *newline = xmalloc(idx + correct + 1);
int t; int t;
for (t = 0; t < idx; ++t) for (t = 0; t < idx; ++t)
@ -255,7 +255,7 @@ coladvance2 (
if (-correct > csize) if (-correct > csize)
return FAIL; return FAIL;
newline = alloc(linelen + csize); newline = xmalloc(linelen + csize);
for (t = 0; t < linelen; t++) { for (t = 0; t < linelen; t++) {
if (t != idx) if (t != idx)

View File

@ -3382,7 +3382,7 @@ find_decl (
int retval = OK; int retval = OK;
int incll; int incll;
pat = alloc(len + 7); pat = xmalloc(len + 7);
/* Put "\V" before the pattern to avoid that the special meaning of "." /* Put "\V" before the pattern to avoid that the special meaning of "."
* and "~" causes trouble. */ * and "~" causes trouble. */
@ -4356,7 +4356,7 @@ static void nv_ident(cmdarg_T *cap)
kp = (*curbuf->b_p_kp == NUL ? p_kp : curbuf->b_p_kp); kp = (*curbuf->b_p_kp == NUL ? p_kp : curbuf->b_p_kp);
kp_help = (*kp == NUL || STRCMP(kp, ":he") == 0 kp_help = (*kp == NUL || STRCMP(kp, ":he") == 0
|| STRCMP(kp, ":help") == 0); || STRCMP(kp, ":help") == 0);
buf = alloc((unsigned)(n * 2 + 30 + STRLEN(kp))); buf = xmalloc(n * 2 + 30 + STRLEN(kp));
buf[0] = NUL; buf[0] = NUL;
switch (cmdchar) { switch (cmdchar) {

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. */
@ -907,7 +905,7 @@ static int stuff_yank(int regname, char_u *p)
*pp = lp; *pp = lp;
} else { } else {
free_yank_all(); free_yank_all();
y_current->y_array = (char_u **)alloc((unsigned)sizeof(char_u *)); y_current->y_array = (char_u **)xmalloc(sizeof(char_u *));
y_current->y_array[0] = p; y_current->y_array[0] = p;
y_current->y_size = 1; y_current->y_size = 1;
y_current->y_type = MCHAR; /* used to be MLINE, why? */ y_current->y_type = MCHAR; /* used to be MLINE, why? */
@ -2154,7 +2152,6 @@ 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)
@ -2167,7 +2164,6 @@ void op_insert(oparg_T *oap, long count1)
} }
} }
} }
}
/* /*
* op_change - handle a change operation * op_change - handle a change operation
@ -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)
@ -2676,8 +2664,7 @@ do_put (
} }
if (y_array != NULL) if (y_array != NULL)
break; break;
y_array = (char_u **)alloc((unsigned) y_array = (char_u **)xmalloc(y_size * sizeof(char_u *));
(y_size * sizeof(char_u *)));
} }
} else { } else {
y_size = 1; /* use fake one-line yank register */ y_size = 1; /* use fake one-line yank register */
@ -2699,14 +2686,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,7 +3611,6 @@ 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);
@ -3641,7 +3623,7 @@ static int same_leader(linenr_T lnum, int leader1_len, char_u *leader1_flags, in
++idx1; ++idx1;
} }
free(line1); free(line1);
}
return idx2 == leader2_len && idx1 == leader1_len; return idx2 == leader2_len && idx1 == leader1_len;
} }
@ -4401,7 +4383,7 @@ int do_addsub(int command, linenr_T Prenum1)
* When there are many leading zeros it could be very long. Allocate * When there are many leading zeros it could be very long. Allocate
* a bit too much. * a bit too much.
*/ */
buf1 = alloc((unsigned)length + NUMBUFLEN); buf1 = xmalloc(length + NUMBUFLEN);
ptr = buf1; ptr = buf1;
if (negative) { if (negative) {
*ptr++ = '-'; *ptr++ = '-';
@ -4491,7 +4473,7 @@ int read_viminfo_register(vir_T *virp, int force)
y_previous = y_current; y_previous = y_current;
free(y_current->y_array); free(y_current->y_array);
array = y_current->y_array = array = y_current->y_array =
(char_u **)alloc((unsigned)(limit * sizeof(char_u *))); (char_u **)xmalloc(limit * sizeof(char_u *));
str = skipwhite(skiptowhite(str)); str = skipwhite(skiptowhite(str));
if (STRNCMP(str, "CHAR", 4) == 0) if (STRNCMP(str, "CHAR", 4) == 0)
y_current->y_type = MCHAR; y_current->y_type = MCHAR;
@ -4508,8 +4490,7 @@ int read_viminfo_register(vir_T *virp, int force)
&& (virp->vir_line[0] == TAB || virp->vir_line[0] == '<')) { && (virp->vir_line[0] == TAB || virp->vir_line[0] == '<')) {
if (do_it) { if (do_it) {
if (size >= limit) { if (size >= limit) {
y_current->y_array = (char_u **) y_current->y_array = (char_u **)xmalloc(limit * 2 * sizeof(char_u *));
alloc((unsigned)(limit * 2 * sizeof(char_u *)));
for (i = 0; i < limit; i++) for (i = 0; i < limit; i++)
y_current->y_array[i] = array[i]; y_current->y_array[i] = array[i];
free(array); free(array);
@ -4529,7 +4510,7 @@ int read_viminfo_register(vir_T *virp, int force)
y_current->y_array = NULL; y_current->y_array = NULL;
} else if (size < limit) { } else if (size < limit) {
y_current->y_array = y_current->y_array =
(char_u **)alloc((unsigned)(size * sizeof(char_u *))); (char_u **)xmalloc(size * sizeof(char_u *));
for (i = 0; i < size; i++) for (i = 0; i < size; i++)
y_current->y_array[i] = array[i]; y_current->y_array[i] = array[i];
free(array); free(array);
@ -4773,8 +4754,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);
@ -4885,7 +4865,7 @@ str_to_reg (
extra = (int)STRLEN(y_ptr->y_array[lnum]); extra = (int)STRLEN(y_ptr->y_array[lnum]);
} else } else
extra = 0; extra = 0;
s = alloc((unsigned)(i + extra + 1)); s = xmalloc(i + extra + 1);
if (extra) if (extra)
memmove(s, y_ptr->y_array[lnum], (size_t)extra); memmove(s, y_ptr->y_array[lnum], (size_t)extra);
if (append) if (append)

View File

@ -2089,7 +2089,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
@ -2278,7 +2279,6 @@ 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)
@ -2287,7 +2287,6 @@ void set_string_default(char *name, char_u *val)
options[opt_idx].flags |= P_DEF_ALLOCED; options[opt_idx].flags |= P_DEF_ALLOCED;
} }
} }
}
/* /*
* Set the Vi-default value of a number option. * Set the Vi-default value of a number option.
@ -2450,7 +2449,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.
@ -2506,16 +2505,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)
p_hlg = empty_option;
else {
/* zh_CN becomes "cn", zh_TW becomes "tw". */ /* zh_CN becomes "cn", zh_TW becomes "tw". */
if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5) { if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5) {
p_hlg[0] = TOLOWER_ASC(p_hlg[3]); p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
p_hlg[1] = TOLOWER_ASC(p_hlg[4]); 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;
} }
} }
@ -3075,7 +3070,7 @@ do_set (
newlen = (unsigned)STRLEN(arg) + 1; newlen = (unsigned)STRLEN(arg) + 1;
if (adding || prepending || removing) if (adding || prepending || removing)
newlen += (unsigned)STRLEN(origval) + 1; newlen += (unsigned)STRLEN(origval) + 1;
newval = alloc(newlen); newval = xmalloc(newlen);
s = newval; s = newval;
/* /*
@ -3121,7 +3116,7 @@ do_set (
newlen = (unsigned)STRLEN(s) + 1; newlen = (unsigned)STRLEN(s) + 1;
if (adding || prepending || removing) if (adding || prepending || removing)
newlen += (unsigned)STRLEN(origval) + 1; newlen += (unsigned)STRLEN(origval) + 1;
newval = alloc(newlen); newval = xmalloc(newlen);
STRCPY(newval, s); STRCPY(newval, s);
} }
} }
@ -3739,7 +3734,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))
@ -3780,9 +3775,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;
} }
@ -3809,7 +3803,6 @@ 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)
@ -3820,7 +3813,7 @@ set_string_option (
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;
} }
@ -4768,7 +4761,7 @@ skip:
if (count == 0) if (count == 0)
wp->w_p_cc_cols = NULL; wp->w_p_cc_cols = NULL;
else { else {
wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1)); wp->w_p_cc_cols = xmalloc(sizeof(int) * (count + 1));
/* sort the columns for faster usage on screen redraw inside /* sort the columns for faster usage on screen redraw inside
* win_line() */ * win_line() */
qsort(color_cols, count, sizeof(int), int_cmp); qsort(color_cols, count, sizeof(int), int_cmp);
@ -6139,7 +6132,6 @@ showoptions (
int col; int col;
int isterm; int isterm;
char_u *varp; char_u *varp;
struct vimoption **items;
int item_count; int item_count;
int run; int run;
int row, rows; int row, rows;
@ -6150,8 +6142,7 @@ showoptions (
#define INC 20 #define INC 20
#define GAP 3 #define GAP 3
items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) * struct vimoption **items = xmalloc(sizeof(struct vimoption *) * PARAM_COUNT);
PARAM_COUNT));
/* Highlight title */ /* Highlight title */
if (all == 2) if (all == 2)
@ -6440,7 +6431,7 @@ static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, int e
if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL) if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
return FAIL; return FAIL;
} else if (expand) { } else if (expand) {
buf = alloc(MAXPATHL); buf = xmalloc(MAXPATHL);
home_replace(NULL, *valuep, buf, MAXPATHL, FALSE); home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
if (put_escstr(fd, buf, 2) == FAIL) { if (put_escstr(fd, buf, 2) == FAIL) {
free(buf); free(buf);
@ -7454,11 +7445,7 @@ int ExpandSettings(expand_T *xp, regmatch_T *regmatch, int *num_file, char_u ***
*num_file = num_term; *num_file = num_term;
else else
return OK; return OK;
*file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *))); *file = (char_u **)xmalloc(*num_file * sizeof(char_u *));
if (*file == NULL) {
*file = (char_u **)"";
return FAIL;
}
} }
} }
return OK; return OK;
@ -7470,7 +7457,7 @@ int ExpandOldSetting(int *num_file, char_u ***file)
char_u *buf; char_u *buf;
*num_file = 0; *num_file = 0;
*file = (char_u **)alloc((unsigned)sizeof(char_u *)); *file = (char_u **)xmalloc(sizeof(char_u *));
/* /*
* For a terminal key code expand_option_idx is < 0. * For a terminal key code expand_option_idx is < 0.

View File

@ -89,8 +89,8 @@ static bool is_executable_in_path(const char_u *name)
return false; return false;
} }
int buf_len = STRLEN(name) + STRLEN(path) + 2; size_t buf_len = STRLEN(name) + STRLEN(path) + 2;
char_u *buf = alloc((unsigned)(buf_len)); char_u *buf = xmalloc(buf_len);
// Walk through all entries in $PATH to check if "name" exists there and // Walk through all entries in $PATH to check if "name" exists there and
// is an executable file. // is an executable file.
@ -103,7 +103,7 @@ static bool is_executable_in_path(const char_u *name)
// Glue together the given directory from $PATH with name and save into // Glue together the given directory from $PATH with name and save into
// buf. // buf.
vim_strncpy(buf, (char_u *) path, e - path); vim_strncpy(buf, (char_u *) path, e - path);
append_path((char *) buf, (const char *) name, buf_len); append_path((char *) buf, (const char *) name, (int)buf_len);
if (is_executable(buf)) { if (is_executable(buf)) {
// Found our executable. Free buf and return. // Found our executable. Free buf and return.

View File

@ -4,6 +4,7 @@
#include "nvim/os/os.h" #include "nvim/os/os.h"
#include "nvim/garray.h" #include "nvim/garray.h"
#include "nvim/memory.h"
#include "nvim/misc2.h" #include "nvim/misc2.h"
#include "nvim/strings.h" #include "nvim/strings.h"
#ifdef HAVE_PWD_H #ifdef HAVE_PWD_H
@ -28,10 +29,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 +77,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 xstrdup(pw->pw_dir);
return user_directory;
} }
#endif #endif
return NULL; return NULL;

View File

@ -1120,7 +1120,7 @@ int flags; /* EW_* flags */
++len; ++len;
} }
} }
command = alloc(len); command = xmalloc(len);
/* /*
* Build the shell command: * Build the shell command:
@ -1269,7 +1269,7 @@ int flags; /* EW_* flags */
fseek(fd, 0L, SEEK_END); fseek(fd, 0L, SEEK_END);
len = ftell(fd); /* get size of temp file */ len = ftell(fd); /* get size of temp file */
fseek(fd, 0L, SEEK_SET); fseek(fd, 0L, SEEK_SET);
buffer = alloc(len + 1); buffer = xmalloc(len + 1);
i = fread((char *)buffer, 1, len, fd); i = fread((char *)buffer, 1, len, fd);
fclose(fd); fclose(fd);
os_remove((char *)tempname); os_remove((char *)tempname);
@ -1353,7 +1353,7 @@ int flags; /* EW_* flags */
goto notfound; goto notfound;
} }
*num_file = i; *num_file = i;
*file = (char_u **)alloc(sizeof(char_u *) * i); *file = (char_u **)xmalloc(sizeof(char_u *) * i);
/* /*
* Isolate the individual file names. * Isolate the individual file names.
@ -1397,7 +1397,7 @@ int flags; /* EW_* flags */
if (!dir && (flags & EW_EXEC) && !os_can_exe((*file)[i])) if (!dir && (flags & EW_EXEC) && !os_can_exe((*file)[i]))
continue; continue;
p = alloc((unsigned)(STRLEN((*file)[i]) + 1 + dir)); p = xmalloc(STRLEN((*file)[i]) + 1 + dir);
STRCPY(p, (*file)[i]); STRCPY(p, (*file)[i]);
if (dir) if (dir)
add_pathsep(p); /* add '/' to a directory name */ add_pathsep(p); /* add '/' to a directory name */
@ -1437,7 +1437,6 @@ 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);

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,20 @@ 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;
} }
@ -380,7 +380,7 @@ unix_expandpath (
} }
/* make room for file name */ /* make room for file name */
buf = alloc((int)STRLEN(path) + BASENAMELEN + 5); buf = xmalloc(STRLEN(path) + BASENAMELEN + 5);
/* /*
* Find the first part in the path name that contains a wildcard. * Find the first part in the path name that contains a wildcard.
@ -609,7 +609,7 @@ static void expand_path_option(char_u *curdir, garray_T *gap)
char_u *p; char_u *p;
int len; int len;
buf = alloc((int)MAXPATHL); buf = xmalloc(MAXPATHL);
while (*path_option != NUL) { while (*path_option != NUL) {
copy_option_part(&path_option, buf, MAXPATHL, " ,"); copy_option_part(&path_option, buf, MAXPATHL, " ,");
@ -650,8 +650,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;
} }
@ -723,7 +721,7 @@ static void uniquefy_paths(garray_T *gap, char_u *pattern)
* possible patterns? * possible patterns?
*/ */
len = (int)STRLEN(pattern); len = (int)STRLEN(pattern);
file_pattern = alloc(len + 2); file_pattern = xmalloc(len + 2);
file_pattern[0] = '*'; file_pattern[0] = '*';
file_pattern[1] = NUL; file_pattern[1] = NUL;
STRCAT(file_pattern, pattern); STRCAT(file_pattern, pattern);
@ -738,7 +736,7 @@ static void uniquefy_paths(garray_T *gap, char_u *pattern)
if (regmatch.regprog == NULL) if (regmatch.regprog == NULL)
return; return;
curdir = alloc((int)(MAXPATHL)); curdir = xmalloc(MAXPATHL);
os_dirname(curdir, MAXPATHL); os_dirname(curdir, MAXPATHL);
expand_path_option(curdir, &path_ga); expand_path_option(curdir, &path_ga);
@ -814,7 +812,7 @@ static void uniquefy_paths(garray_T *gap, char_u *pattern)
continue; continue;
} }
rel_path = alloc((int)(STRLEN(short_name) + STRLEN(PATHSEPSTR) + 2)); rel_path = xmalloc(STRLEN(short_name) + STRLEN(PATHSEPSTR) + 2);
STRCPY(rel_path, "."); STRCPY(rel_path, ".");
add_pathsep(rel_path); add_pathsep(rel_path);
STRCAT(rel_path, short_name); STRCAT(rel_path, short_name);
@ -887,7 +885,7 @@ expand_in_path (
char_u *e; /* end */ char_u *e; /* end */
char_u *paths = NULL; char_u *paths = NULL;
curdir = alloc((unsigned)MAXPATHL); curdir = xmalloc(MAXPATHL);
os_dirname(curdir, MAXPATHL); os_dirname(curdir, MAXPATHL);
ga_init(&path_ga, (int)sizeof(char_u *), 1); ga_init(&path_ga, (int)sizeof(char_u *), 1);
@ -1137,8 +1135,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);
@ -1211,7 +1207,7 @@ addfile (
/* Make room for another item in the file list. */ /* Make room for another item in the file list. */
ga_grow(gap, 1); ga_grow(gap, 1);
p = alloc((unsigned)(STRLEN(f) + 1 + isdir)); p = xmalloc(STRLEN(f) + 1 + isdir);
STRCPY(p, f); STRCPY(p, f);
#ifdef BACKSLASH_IN_FILENAME #ifdef BACKSLASH_IN_FILENAME
@ -1563,9 +1559,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

@ -346,12 +346,8 @@ void pum_redraw(void)
if (curwin->w_p_rl) { if (curwin->w_p_rl) {
char_u *rt = reverse_text(st); char_u *rt = reverse_text(st);
if (rt != NULL) {
char_u *rt_start = rt; char_u *rt_start = rt;
int size; int size = vim_strsize(rt);
size = vim_strsize(rt);
if (size > pum_width) { if (size > pum_width) {
do { do {
@ -370,7 +366,6 @@ void pum_redraw(void)
screen_puts_len(rt, (int)STRLEN(rt), row, col - size + 1, screen_puts_len(rt, (int)STRLEN(rt), row, col - size + 1,
attr); attr);
free(rt_start); free(rt_start);
}
free(st); free(st);
col -= width; col -= width;

View File

@ -283,9 +283,9 @@ qf_init_ext (
{'s', ".\\+"} {'s', ".\\+"}
}; };
namebuf = alloc(CMDBUFFSIZE + 1); namebuf = xmalloc(CMDBUFFSIZE + 1);
errmsg = alloc(CMDBUFFSIZE + 1); errmsg = xmalloc(CMDBUFFSIZE + 1);
pattern = alloc(CMDBUFFSIZE + 1); pattern = xmalloc(CMDBUFFSIZE + 1);
if (efile != NULL && (fd = mch_fopen((char *)efile, "r")) == NULL) { if (efile != NULL && (fd = mch_fopen((char *)efile, "r")) == NULL) {
EMSG2(_(e_openerrf), efile); EMSG2(_(e_openerrf), efile);
@ -321,7 +321,7 @@ qf_init_ext (
#else #else
i += 2; /* "%f" can become two chars longer */ i += 2; /* "%f" can become two chars longer */
#endif #endif
fmtstr = alloc(i); fmtstr = xmalloc(i);
while (efm[0] != NUL) { while (efm[0] != NUL) {
/* /*
@ -719,13 +719,10 @@ restofline:
if (qfprev == NULL) if (qfprev == NULL)
goto error2; goto error2;
if (*errmsg && !multiignore) { if (*errmsg && !multiignore) {
len = (int)STRLEN(qfprev->qf_text); size_t len = STRLEN(qfprev->qf_text);
ptr = alloc((unsigned)(len + STRLEN(errmsg) + 2)); qfprev->qf_text = xrealloc(qfprev->qf_text, len + STRLEN(errmsg) + 2);
STRCPY(ptr, qfprev->qf_text); qfprev->qf_text[len] = '\n';
free(qfprev->qf_text); STRCPY(qfprev->qf_text + len + 1, errmsg);
qfprev->qf_text = ptr;
*(ptr += len) = '\n';
STRCPY(++ptr, errmsg);
} }
if (qfprev->qf_nr == -1) if (qfprev->qf_nr == -1)
qfprev->qf_nr = enr; qfprev->qf_nr = enr;
@ -856,7 +853,7 @@ static void qf_new_list(qf_info_T *qi, char_u *qf_title)
qi->qf_curlist = qi->qf_listcount++; qi->qf_curlist = qi->qf_listcount++;
memset(&qi->qf_lists[qi->qf_curlist], 0, (size_t)(sizeof(qf_list_T))); memset(&qi->qf_lists[qi->qf_curlist], 0, (size_t)(sizeof(qf_list_T)));
if (qf_title != NULL) { if (qf_title != NULL) {
char_u *p = alloc((int)STRLEN(qf_title) + 2); char_u *p = xmalloc(STRLEN(qf_title) + 2);
qi->qf_lists[qi->qf_curlist].qf_title = p; qi->qf_lists[qi->qf_curlist].qf_title = p;
sprintf((char *)p, ":%s", (char *)qf_title); sprintf((char *)p, ":%s", (char *)qf_title);
@ -921,27 +918,20 @@ qf_add_entry (
int valid /* valid entry */ int valid /* valid entry */
) )
{ {
qfline_T *qfp; qfline_T *qfp = xmalloc(sizeof(qfline_T));
qfp = (qfline_T *)alloc((unsigned)sizeof(qfline_T));
if (bufnum != 0) if (bufnum != 0)
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 */
@ -1145,11 +1135,10 @@ static int qf_get_fnum(char_u *directory, char_u *fname)
*/ */
static char_u *qf_push_dir(char_u *dirbuf, struct dir_stack_T **stackptr) static char_u *qf_push_dir(char_u *dirbuf, struct dir_stack_T **stackptr)
{ {
struct dir_stack_T *ds_new;
struct dir_stack_T *ds_ptr; struct dir_stack_T *ds_ptr;
/* allocate new stack element and hook it in */ /* allocate new stack element and hook it in */
ds_new = (struct dir_stack_T *)alloc((unsigned)sizeof(struct dir_stack_T)); struct dir_stack_T *ds_new = xmalloc(sizeof(struct dir_stack_T));
ds_new->next = *stackptr; ds_new->next = *stackptr;
*stackptr = ds_new; *stackptr = ds_new;
@ -2521,7 +2510,7 @@ void ex_make(exarg_T *eap)
len = (unsigned)STRLEN(p_shq) * 2 + (unsigned)STRLEN(eap->arg) + 1; len = (unsigned)STRLEN(p_shq) * 2 + (unsigned)STRLEN(eap->arg) + 1;
if (*p_sp != NUL) if (*p_sp != NUL)
len += (unsigned)STRLEN(p_sp) + (unsigned)STRLEN(fname) + 3; len += (unsigned)STRLEN(p_sp) + (unsigned)STRLEN(fname) + 3;
cmd = alloc(len); cmd = xmalloc(len);
sprintf((char *)cmd, "%s%s%s", (char *)p_shq, (char *)eap->arg, sprintf((char *)cmd, "%s%s%s", (char *)p_shq, (char *)eap->arg,
(char *)p_shq); (char *)p_shq);
if (*p_sp != NUL) if (*p_sp != NUL)
@ -2596,7 +2585,7 @@ static char_u *get_mef_name(void)
else else
off += 19; off += 19;
name = alloc((unsigned)STRLEN(p_mef) + 30); name = xmalloc(STRLEN(p_mef) + 30);
STRCPY(name, p_mef); STRCPY(name, p_mef);
sprintf((char *)name + (p - p_mef), "%d%d", start, off); sprintf((char *)name + (p - p_mef), "%d%d", start, off);
STRCAT(name, p + 2); STRCAT(name, p + 2);
@ -2843,8 +2832,8 @@ void ex_vimgrep(exarg_T *eap)
goto theend; goto theend;
} }
dirname_start = alloc(MAXPATHL); dirname_start = xmalloc(MAXPATHL);
dirname_now = alloc(MAXPATHL); dirname_now = xmalloc(MAXPATHL);
/* Remember the current directory, because a BufRead autocommand that does /* Remember the current directory, because a BufRead autocommand that does
* ":lcd %:p:h" changes the meaning of short path names. */ * ":lcd %:p:h" changes the meaning of short path names. */
@ -3112,7 +3101,7 @@ char_u *skip_vimgrep_pat(char_u *p, char_u **s, int *flags)
*/ */
static void restore_start_dir(char_u *dirname_start) static void restore_start_dir(char_u *dirname_start)
{ {
char_u *dirname_now = alloc(MAXPATHL); char_u *dirname_now = xmalloc(MAXPATHL);
os_dirname(dirname_now, MAXPATHL); os_dirname(dirname_now, MAXPATHL);
if (STRCMP(dirname_start, dirname_now) != 0) { if (STRCMP(dirname_start, dirname_now) != 0) {

View File

@ -1141,7 +1141,6 @@ 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)
@ -5654,7 +5653,7 @@ static int match_with_backref(linenr_T start_lnum, colnr_T start_col, linenr_T e
if (reg_tofree == NULL || len >= (int)reg_tofreelen) { if (reg_tofree == NULL || len >= (int)reg_tofreelen) {
len += 50; /* get some extra */ len += 50; /* get some extra */
free(reg_tofree); free(reg_tofree);
reg_tofree = alloc(len); reg_tofree = xmalloc(len);
reg_tofreelen = len; reg_tofreelen = len;
} }
STRCPY(reg_tofree, regline); STRCPY(reg_tofree, regline);
@ -6405,7 +6404,7 @@ char_u *regtilde(char_u *source, int magic)
if (reg_prev_sub != NULL) { if (reg_prev_sub != NULL) {
/* length = len(newsub) - 1 + len(prev_sub) + 1 */ /* length = len(newsub) - 1 + len(prev_sub) + 1 */
prevlen = (int)STRLEN(reg_prev_sub); prevlen = (int)STRLEN(reg_prev_sub);
tmpsub = alloc((unsigned)(STRLEN(newsub) + prevlen)); tmpsub = xmalloc(STRLEN(newsub) + prevlen);
/* copy prefix */ /* copy prefix */
len = (int)(p - newsub); /* not including ~ */ len = (int)(p - newsub); /* not including ~ */
memmove(tmpsub, newsub, (size_t)len); memmove(tmpsub, newsub, (size_t)len);

View File

@ -516,7 +516,7 @@ static char_u *nfa_get_match_text(nfa_state_T *start)
if (p->c != NFA_MCLOSE || p->out->c != NFA_MATCH) if (p->c != NFA_MCLOSE || p->out->c != NFA_MATCH)
return NULL; return NULL;
ret = alloc(len); ret = xmalloc(len);
p = start->out->out; /* skip first char, it goes into regstart */ p = start->out->out; /* skip first char, it goes into regstart */
s = ret; s = ret;
while (p->c > 0) { while (p->c > 0) {
@ -4193,10 +4193,9 @@ addstate_here (
if (l->n + count - 1 >= l->len) { if (l->n + count - 1 >= l->len) {
/* not enough space to move the new states, reallocate the list /* not enough space to move the new states, reallocate the list
* and move the states to the right position */ * and move the states to the right position */
nfa_thread_T *newl;
l->len = l->len * 3 / 2 + 50; l->len = l->len * 3 / 2 + 50;
newl = (nfa_thread_T *)alloc(l->len * sizeof(nfa_thread_T)); nfa_thread_T *newl = xmalloc(l->len * sizeof(nfa_thread_T));
memmove(&(newl[0]), memmove(&(newl[0]),
&(l->t[0]), &(l->t[0]),
sizeof(nfa_thread_T) * listidx); sizeof(nfa_thread_T) * listidx);

View File

@ -4691,10 +4691,7 @@ win_redr_status_matches (
if (matches == NULL) /* interrupted completion? */ if (matches == NULL) /* interrupted completion? */
return; return;
if (has_mbyte) buf = xmalloc(has_mbyte ? Columns * MB_MAXBYTES + 1 : Columns + 1);
buf = alloc((unsigned)Columns * MB_MAXBYTES + 1);
else
buf = alloc((unsigned)Columns + 1);
if (match == -1) { /* don't show match but original text */ if (match == -1) { /* don't show match but original text */
match = 0; match = 0;

View File

@ -230,35 +230,29 @@ char_u *get_search_pat(void)
/* /*
* Reverse text into allocated memory. * Reverse text into allocated memory.
* Returns the allocated string, NULL when out of memory. * Returns the allocated string.
*
* TODO(philix): move reverse_text() to strings.c
*/ */
char_u *reverse_text(char_u *s) char_u *reverse_text(char_u *s)
{ {
unsigned len;
unsigned s_i, rev_i;
char_u *rev;
/* /*
* Reverse the pattern. * Reverse the pattern.
*/ */
len = (unsigned)STRLEN(s); size_t len = STRLEN(s);
rev = alloc(len + 1); char_u *rev = xmalloc(len + 1);
if (rev != NULL) { size_t rev_i = len;
rev_i = len; for (size_t s_i = 0; s_i < len; ++s_i) {
for (s_i = 0; s_i < len; ++s_i) {
if (has_mbyte) { if (has_mbyte) {
int mb_len; int mb_len = (*mb_ptr2len)(s + s_i);
mb_len = (*mb_ptr2len)(s + s_i);
rev_i -= mb_len; rev_i -= mb_len;
memmove(rev + rev_i, s + s_i, mb_len); memmove(rev + rev_i, s + s_i, mb_len);
s_i += mb_len - 1; s_i += mb_len - 1;
} else } else
rev[--rev_i] = s[s_i]; rev[--rev_i] = s[s_i];
} }
rev[len] = NUL; rev[len] = NUL;
}
return rev; return rev;
} }
@ -1056,8 +1050,8 @@ proftime_T *tm; /* timeout limit or NULL */
p = spats[last_idx].pat; p = spats[last_idx].pat;
else else
p = searchstr; p = searchstr;
msgbuf = alloc((unsigned)(STRLEN(p) + 40)); msgbuf = xmalloc(STRLEN(p) + 40);
if (msgbuf != NULL) { {
msgbuf[0] = dirc; msgbuf[0] = dirc;
if (enc_utf8 && utf_iscomposing(utf_ptr2char(p))) { if (enc_utf8 && utf_iscomposing(utf_ptr2char(p))) {
/* Use a space to draw the composing char on. */ /* Use a space to draw the composing char on. */
@ -1088,14 +1082,10 @@ proftime_T *tm; /* timeout limit or NULL */
* it would be blanked out again very soon. Show it on the * it would be blanked out again very soon. Show it on the
* left, but do reverse the text. */ * left, but do reverse the text. */
if (curwin->w_p_rl && *curwin->w_p_rlc == 's') { if (curwin->w_p_rl && *curwin->w_p_rlc == 's') {
char_u *r; char_u *r = reverse_text(trunc != NULL ? trunc : msgbuf);
r = reverse_text(trunc != NULL ? trunc : msgbuf);
if (r != NULL) {
free(trunc); free(trunc);
trunc = r; trunc = r;
} }
}
if (trunc != NULL) { if (trunc != NULL) {
msg_outtrans(trunc); msg_outtrans(trunc);
free(trunc); free(trunc);
@ -3257,14 +3247,8 @@ again:
curwin->w_cursor = old_pos; curwin->w_cursor = old_pos;
goto theend; goto theend;
} }
spat = alloc(len + 31); spat = xmalloc(len + 31);
epat = alloc(len + 9); epat = xmalloc(len + 9);
if (spat == NULL || epat == NULL) {
free(spat);
free(epat);
curwin->w_cursor = old_pos;
goto theend;
}
sprintf((char *)spat, "<%.*s\\>\\%%(\\s\\_[^>]\\{-}[^/]>\\|>\\)\\c", len, p); sprintf((char *)spat, "<%.*s\\>\\%%(\\s\\_[^>]\\{-}[^/]>\\|>\\)\\c", len, p);
sprintf((char *)epat, "</%.*s>\\c", len, p); sprintf((char *)epat, "</%.*s>\\c", len, p);
@ -4024,18 +4008,14 @@ find_pattern_in_path (
incl_regmatch.regprog = NULL; incl_regmatch.regprog = NULL;
def_regmatch.regprog = NULL; def_regmatch.regprog = NULL;
file_line = alloc(LSIZE); file_line = xmalloc(LSIZE);
if (file_line == NULL)
return;
if (type != CHECK_PATH && type != FIND_DEFINE if (type != CHECK_PATH && type != FIND_DEFINE
/* when CONT_SOL is set compare "ptr" with the beginning of the line /* when CONT_SOL is set compare "ptr" with the beginning of the line
* is faster than quote_meta/regcomp/regexec "ptr" -- Acevedo */ * is faster than quote_meta/regcomp/regexec "ptr" -- Acevedo */
&& !(compl_cont_status & CONT_SOL) && !(compl_cont_status & CONT_SOL)
) { ) {
pat = alloc(len + 5); pat = xmalloc(len + 5);
if (pat == NULL)
goto fpip_end;
sprintf((char *)pat, whole ? "\\<%.*s\\>" : "%.*s", len, ptr); sprintf((char *)pat, whole ? "\\<%.*s\\>" : "%.*s", len, ptr);
/* ignore case according to p_ic, p_scs and pat */ /* ignore case according to p_ic, p_scs and pat */
regmatch.rm_ic = ignorecase(pat); regmatch.rm_ic = ignorecase(pat);

View File

@ -2010,7 +2010,7 @@ spell_move_to (
if (buflen < len + MAXWLEN + 2) { if (buflen < len + MAXWLEN + 2) {
free(buf); free(buf);
buflen = len + MAXWLEN + 2; buflen = len + MAXWLEN + 2;
buf = alloc(buflen); buf = xmalloc(buflen);
} }
// In first line check first word for Capital. // 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. // 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;
@ -2856,7 +2854,7 @@ static int read_sal_section(FILE *fd, slang_T *slang)
ccnt = getc(fd); // <salfromlen> ccnt = getc(fd); // <salfromlen>
if (ccnt < 0) if (ccnt < 0)
return SP_TRUNCERROR; return SP_TRUNCERROR;
p = alloc(ccnt + 2); p = xmalloc(ccnt + 2);
smp->sm_lead = p; smp->sm_lead = p;
// Read up to the first special char into sm_lead. // 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 // Add one extra entry to mark the end with an empty sm_lead. Avoids
// that we need to check the index every time. // that we need to check the index every time.
smp = &((salitem_T *)gap->ga_data)[gap->ga_len]; smp = &((salitem_T *)gap->ga_data)[gap->ga_len];
p = alloc(1); p = xmalloc(1);
p[0] = NUL; p[0] = NUL;
smp->sm_lead = p; smp->sm_lead = p;
smp->sm_leadlen = 0; smp->sm_leadlen = 0;
@ -2996,7 +2994,7 @@ count_common_word (
hash = hash_hash(p); hash = hash_hash(p);
hi = hash_lookup(&lp->sl_wordcount, p, hash); hi = hash_lookup(&lp->sl_wordcount, p, hash);
if (HASHITEM_EMPTY(hi)) { 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); STRCPY(wc->wc_word, p);
wc->wc_count = count; wc->wc_count = count;
hash_add_item(&lp->sl_wordcount, hi, wc->wc_word, hash); 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; c = todo * 2 + 7;
if (enc_utf8) if (enc_utf8)
c += todo * 2; 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 // We also need a list of all flags that can appear at the start and one
// for all flags. // for all flags.
cp = alloc(todo + 1); cp = xmalloc(todo + 1);
slang->sl_compstartflags = cp; slang->sl_compstartflags = cp;
*cp = NUL; *cp = NUL;
ap = alloc(todo + 1); ap = xmalloc(todo + 1);
slang->sl_compallflags = ap; slang->sl_compallflags = ap;
*ap = NUL; *ap = NUL;
// And a list of all patterns in their original form, for checking whether // And a list of all patterns in their original form, for checking whether
// compounding may work in match_compoundrule(). This is freed when we // compounding may work in match_compoundrule(). This is freed when we
// encounter a wildcard, the check doesn't work then. // encounter a wildcard, the check doesn't work then.
crp = alloc(todo + 1); crp = xmalloc(todo + 1);
slang->sl_comprules = crp; slang->sl_comprules = crp;
pp = pat; pp = pat;
@ -3378,7 +3376,7 @@ static int set_sofo(slang_T *lp, char_u *from, char_u *to)
// Allocate the lists. // Allocate the lists.
for (i = 0; i < 256; ++i) for (i = 0; i < 256; ++i)
if (lp->sl_sal_first[i] > 0) { 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 **)gap->ga_data)[i] = (int *)p;
*(int *)p = 0; *(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 // 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,12 +3932,10 @@ 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
wp->w_s->b_spell_ismw[*p++] = TRUE; wp->w_s->b_spell_ismw[*p++] = TRUE;
@ -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);
} }
} }
@ -7382,7 +7374,7 @@ static void spell_make_sugfile(spellinfo_T *spin, char_u *wfname)
// Write the .sug file. // Write the .sug file.
// Make the file name by changing ".spl" to ".sug". // Make the file name by changing ".spl" to ".sug".
fname = alloc(MAXPATHL); fname = xmalloc(MAXPATHL);
vim_strncpy(fname, wfname, MAXPATHL - 1); vim_strncpy(fname, wfname, MAXPATHL - 1);
len = (int)STRLEN(fname); len = (int)STRLEN(fname);
fname[len - 2] = 'u'; fname[len - 2] = 'u';
@ -7789,7 +7781,7 @@ mkspell (
innames = &fnames[1]; innames = &fnames[1];
incount = fcount - 1; incount = fcount - 1;
wfname = alloc(MAXPATHL); wfname = xmalloc(MAXPATHL);
if (fcount >= 1) { if (fcount >= 1) {
len = (int)STRLEN(fnames[0]); len = (int)STRLEN(fnames[0]);
@ -7840,7 +7832,7 @@ mkspell (
goto theend; goto theend;
} }
fname = alloc(MAXPATHL); fname = xmalloc(MAXPATHL);
// Init the aff and dic pointers. // Init the aff and dic pointers.
// Get the region names if there are more than 2 arguments. // Get the region names if there are more than 2 arguments.
@ -8032,7 +8024,7 @@ spell_add_word (
EMSG2(_(e_notset), "spellfile"); EMSG2(_(e_notset), "spellfile");
return; return;
} }
fnamebuf = alloc(MAXPATHL); fnamebuf = xmalloc(MAXPATHL);
for (spf = curwin->w_s->b_p_spf, i = 1; *spf != NUL; ++i) { for (spf = curwin->w_s->b_p_spf, i = 1; *spf != NUL; ++i) {
copy_option_part(&spf, fnamebuf, MAXPATHL, ","); copy_option_part(&spf, fnamebuf, MAXPATHL, ",");
@ -8151,7 +8143,7 @@ static void init_spellfile(void)
char_u *lstart = curbuf->b_s.b_p_spl; char_u *lstart = curbuf->b_s.b_p_spl;
if (*curwin->w_s->b_p_spl != NUL && !GA_EMPTY(&curwin->w_s->b_langp)) { 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 // Find the end of the language name. Exclude the region. If there
// is a path separator remember the start of the tail. // 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. // 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.
@ -8796,8 +8786,7 @@ void spell_suggest(int count)
} }
// Replace the word. // Replace the word.
p = alloc((unsigned)STRLEN(line) - stp->st_orglen p = xmalloc(STRLEN(line) - stp->st_orglen + stp->st_wordlen + 1);
+ stp->st_wordlen + 1);
c = (int)(sug.su_badptr - line); c = (int)(sug.su_badptr - line);
memmove(p, line, c); memmove(p, line, c);
STRCPY(p + c, stp->st_word); STRCPY(p + c, stp->st_word);
@ -8818,8 +8807,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
@ -8897,7 +8884,7 @@ void ex_spellrepall(exarg_T *eap)
} }
addlen = (int)(STRLEN(repl_to) - STRLEN(repl_from)); 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); sprintf((char *)frompat, "\\V\\<%s\\>", repl_from);
p_ws = FALSE; p_ws = FALSE;
@ -8914,7 +8901,7 @@ void ex_spellrepall(exarg_T *eap)
line = ml_get_curline(); line = ml_get_curline();
if (addlen <= 0 || STRNCMP(line + curwin->w_cursor.col, if (addlen <= 0 || STRNCMP(line + curwin->w_cursor.col,
repl_to, STRLEN(repl_to)) != 0) { 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); memmove(p, line, curwin->w_cursor.col);
STRCPY(p + curwin->w_cursor.col, repl_to); STRCPY(p + curwin->w_cursor.col, repl_to);
STRCAT(p, line + curwin->w_cursor.col + STRLEN(repl_from)); 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 // The suggested word may replace only part of "word", add the not
// replaced part. // replaced part.
wcopy = alloc(stp->st_wordlen wcopy = xmalloc(stp->st_wordlen
+ (unsigned)STRLEN(sug.su_badptr + stp->st_orglen) + 1); + STRLEN(sug.su_badptr + stp->st_orglen) + 1);
STRCPY(wcopy, stp->st_word); STRCPY(wcopy, stp->st_word);
STRCPY(wcopy + stp->st_wordlen, sug.su_badptr + stp->st_orglen); STRCPY(wcopy + stp->st_wordlen, sug.su_badptr + stp->st_orglen);
((char_u **)gap->ga_data)[gap->ga_len++] = wcopy; ((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. // 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; ) {
@ -11024,7 +11009,6 @@ 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;
@ -11032,7 +11016,6 @@ static void score_comp_sal(suginfo_T *su)
++su->su_sga.ga_len; ++su->su_sga.ga_len;
} }
} }
}
break; break;
} }
} }
@ -11313,8 +11296,7 @@ add_sound_suggest (
hash = hash_hash(goodword); hash = hash_hash(goodword);
hi = hash_lookup(&slang->sl_sounddone, goodword, hash); hi = hash_lookup(&slang->sl_sounddone, goodword, hash);
if (HASHITEM_EMPTY(hi)) { if (HASHITEM_EMPTY(hi)) {
sft = (sftword_T *)alloc((unsigned)(sizeof(sftword_T) sft = xmalloc(sizeof(sftword_T) + STRLEN(goodword));
+ STRLEN(goodword)));
sft->sft_score = score; sft->sft_score = score;
STRCPY(sft->sft_word, goodword); STRCPY(sft->sft_word, goodword);
hash_add_item(&slang->sl_sounddone, hi, sft->sft_word, hash); 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; hash_T hash;
hashitem_T *hi; hashitem_T *hi;
b = alloc((unsigned)(cl + headcl + 2)); b = xmalloc(cl + headcl + 2);
mb_char2bytes(c, b); mb_char2bytes(c, b);
b[cl] = NUL; b[cl] = NUL;
mb_char2bytes(headc, b + cl + 1); mb_char2bytes(headc, b + cl + 1);
@ -11730,7 +11712,6 @@ 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;
@ -11751,7 +11732,6 @@ add_suggestion (
} }
} }
} }
}
// Suggestions may in fact be flagged as errors. Esp. for banned words and // Suggestions may in fact be flagged as errors. Esp. for banned words and
// for split words, such as "the the". Remove these from the list here. // for split words, such as "the the". Remove these from the list here.
@ -11799,7 +11779,6 @@ 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

@ -45,14 +45,7 @@
*/ */
char_u *vim_strsave(char_u *string) char_u *vim_strsave(char_u *string)
{ {
char_u *p; return (char_u *)xstrdup((char *)string);
unsigned len;
len = (unsigned)STRLEN(string) + 1;
p = alloc(len);
if (p != NULL)
memmove(p, string, (size_t)len);
return p;
} }
/* /*
@ -63,12 +56,7 @@ char_u *vim_strsave(char_u *string)
*/ */
char_u *vim_strnsave(char_u *string, int len) char_u *vim_strnsave(char_u *string, int len)
{ {
char_u *p; return (char_u *)strncpy(xmallocz(len), (char *)string, len);
p = alloc((unsigned)(len + 1));
STRNCPY(p, string, len);
p[len] = NUL;
return p;
} }
/* /*
@ -108,7 +96,7 @@ char_u *vim_strsave_escaped_ext(char_u *string, char_u *esc_chars, int cc, int b
++length; /* count a backslash */ ++length; /* count a backslash */
++length; /* count an ordinary char */ ++length; /* count an ordinary char */
} }
escaped_string = alloc(length); escaped_string = xmalloc(length);
p2 = escaped_string; p2 = escaped_string;
for (p = string; *p; p++) { for (p = string; *p; p++) {
if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1) { if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1) {
@ -169,7 +157,7 @@ char_u *vim_strsave_shellescape(char_u *string, bool do_special, bool do_newline
} }
/* Allocate memory for the result and fill it. */ /* Allocate memory for the result and fill it. */
escaped_string = alloc(length); escaped_string = xmalloc(length);
d = escaped_string; d = escaped_string;
/* add opening quote */ /* add opening quote */
@ -253,16 +241,12 @@ 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;
if (res != NULL)
while (*p != NUL) { while (*p != NUL) {
int l; int l;
@ -279,7 +263,7 @@ char_u *strup_save(char_u *orig)
l = utf_ptr2len(p); l = utf_ptr2len(p);
newl = utf_char2len(uc); newl = utf_char2len(uc);
if (newl != l) { if (newl != l) {
s = alloc((unsigned)STRLEN(res) + 1 + newl - l); s = xmalloc(STRLEN(res) + 1 + newl - l);
memmove(s, res, p - res); memmove(s, res, p - res);
STRCPY(s + (p - res) + newl, p + l); STRCPY(s + (p - res) + newl, p + l);
p = s + (p - res); p = s + (p - res);

View File

@ -1,7 +1,10 @@
#ifndef NVIM_STRINGS_H #ifndef NVIM_STRINGS_H
#define NVIM_STRINGS_H #define NVIM_STRINGS_H
char_u *vim_strsave(char_u *string);
char_u *vim_strnsave(char_u *string, int len); #include "func_attr.h"
char_u *vim_strsave(char_u *string) FUNC_ATTR_NONNULL_RET;
char_u *vim_strnsave(char_u *string, int len) FUNC_ATTR_NONNULL_RET;
char_u *vim_strsave_escaped(char_u *string, char_u *esc_chars); char_u *vim_strsave_escaped(char_u *string, char_u *esc_chars);
char_u *vim_strsave_escaped_ext(char_u *string, char_u *esc_chars, char_u *vim_strsave_escaped_ext(char_u *string, char_u *esc_chars,
int cc, int cc,

View File

@ -3924,7 +3924,6 @@ add_keyword (
int conceal_char int conceal_char
) )
{ {
keyentry_T *kp;
hashtab_T *ht; hashtab_T *ht;
hashitem_T *hi; hashitem_T *hi;
char_u *name_ic; char_u *name_ic;
@ -3936,7 +3935,7 @@ add_keyword (
name_folded, MAXKEYWLEN + 1); name_folded, MAXKEYWLEN + 1);
else else
name_ic = name; name_ic = name;
kp = (keyentry_T *)alloc((int)(sizeof(keyentry_T) + STRLEN(name_ic))); keyentry_T *kp = xmalloc(sizeof(keyentry_T) + STRLEN(name_ic));
STRCPY(kp->keyword, name_ic); STRCPY(kp->keyword, name_ic);
kp->k_syn.id = id; kp->k_syn.id = id;
kp->k_syn.inc_tag = current_syn_inc_tag; kp->k_syn.inc_tag = current_syn_inc_tag;
@ -4113,8 +4112,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 {
@ -4156,7 +4153,7 @@ static void syn_incl_toplevel(int id, int *flagsp)
*flagsp |= HL_CONTAINED; *flagsp |= HL_CONTAINED;
if (curwin->w_s->b_syn_topgrp >= SYNID_CLUSTER) { if (curwin->w_s->b_syn_topgrp >= SYNID_CLUSTER) {
/* We have to alloc this, because syn_combine_list() will free it. */ /* We have to alloc this, because syn_combine_list() will free it. */
short *grp_list = (short *)alloc((unsigned)(2 * sizeof(short))); short *grp_list = xmalloc(2 * sizeof(short));
int tlg_id = curwin->w_s->b_syn_topgrp - SYNID_CLUSTER; int tlg_id = curwin->w_s->b_syn_topgrp - SYNID_CLUSTER;
grp_list[0] = id; grp_list[0] = id;
@ -4257,7 +4254,7 @@ static void syn_cmd_keyword(exarg_T *eap, int syncing)
syn_id = syn_check_group(arg, (int)(group_name_end - arg)); syn_id = syn_check_group(arg, (int)(group_name_end - arg));
if (syn_id != 0) if (syn_id != 0)
/* allocate a buffer, for removing backslashes in the keyword */ /* allocate a buffer, for removing backslashes in the keyword */
keyword_copy = alloc((unsigned)STRLEN(rest) + 1); keyword_copy = xmalloc(STRLEN(rest) + 1);
syn_opt_arg.flags = 0; syn_opt_arg.flags = 0;
syn_opt_arg.keyword = TRUE; syn_opt_arg.keyword = TRUE;
syn_opt_arg.sync_idx = NULL; syn_opt_arg.sync_idx = NULL;
@ -4558,7 +4555,7 @@ syn_cmd_region (
* syn_patterns for this item, at the start (because the list is * syn_patterns for this item, at the start (because the list is
* used from end to start). * used from end to start).
*/ */
ppp = (struct pat_ptr *)alloc((unsigned)sizeof(struct pat_ptr)); ppp = xmalloc(sizeof(struct pat_ptr));
ppp->pp_next = pat_ptrs[item]; ppp->pp_next = pat_ptrs[item];
pat_ptrs[item] = ppp; pat_ptrs[item] = ppp;
ppp->pp_synp = xcalloc(1, sizeof(synpat_T)); ppp->pp_synp = xcalloc(1, sizeof(synpat_T));
@ -4784,7 +4781,7 @@ static void syn_combine_list(short **clstr1, short **clstr2, int list_op)
clstr = NULL; clstr = NULL;
break; break;
} }
clstr = (short *)alloc((unsigned)((count + 1) * sizeof(short))); clstr = xmalloc((count + 1) * sizeof(short));
clstr[count] = 0; clstr[count] = 0;
} }
} }
@ -4823,14 +4820,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);
name = vim_strnsave(linep, len);
if (name != NULL) {
id = syn_scl_name2id(name);
free(name); free(name);
}
return id; return id;
} }
@ -4846,8 +4839,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 +4987,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 +5129,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 */
@ -5243,7 +5230,7 @@ get_id_list (
while (!ends_excmd(*p)) { while (!ends_excmd(*p)) {
for (end = p; *end && !vim_iswhite(*end) && *end != ','; ++end) for (end = p; *end && !vim_iswhite(*end) && *end != ','; ++end)
; ;
name = alloc((int)(end - p + 3)); /* leave room for "^$" */ name = xmalloc((int)(end - p + 3)); /* leave room for "^$" */
vim_strncpy(name + 1, p, end - p); vim_strncpy(name + 1, p, end - p);
if ( STRCMP(name + 1, "ALLBUT") == 0 if ( STRCMP(name + 1, "ALLBUT") == 0
|| STRCMP(name + 1, "ALL") == 0 || STRCMP(name + 1, "ALL") == 0
@ -5337,7 +5324,7 @@ get_id_list (
if (failed) if (failed)
break; break;
if (round == 1) { if (round == 1) {
retval = (short *)alloc((unsigned)((count + 1) * sizeof(short))); retval = xmalloc((count + 1) * sizeof(short));
retval[count] = 0; /* zero means end of the list */ retval[count] = 0; /* zero means end of the list */
total_count = count; total_count = count;
} }
@ -5372,7 +5359,7 @@ static short *copy_id_list(short *list)
for (count = 0; list[count]; ++count) for (count = 0; list[count]; ++count)
; ;
len = (count + 1) * sizeof(short); len = (count + 1) * sizeof(short);
retval = (short *)alloc((unsigned)len); retval = xmalloc(len);
memmove(retval, list, (size_t)len); memmove(retval, list, (size_t)len);
return retval; return retval;
@ -5518,7 +5505,6 @@ 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) {
@ -5536,7 +5522,6 @@ void ex_syntax(exarg_T *eap)
if (eap->skip) if (eap->skip)
--emsg_skip; --emsg_skip;
} }
}
void ex_ownsyntax(exarg_T *eap) void ex_ownsyntax(exarg_T *eap)
{ {
@ -5544,7 +5529,7 @@ void ex_ownsyntax(exarg_T *eap)
char_u *new_value; char_u *new_value;
if (curwin->w_s == &curwin->w_buffer->b_s) { if (curwin->w_s == &curwin->w_buffer->b_s) {
curwin->w_s = (synblock_T *)alloc(sizeof(synblock_T)); curwin->w_s = xmalloc(sizeof(synblock_T));
memset(curwin->w_s, 0, sizeof(synblock_T)); memset(curwin->w_s, 0, sizeof(synblock_T));
curwin->w_p_spell = FALSE; /* No spell checking */ curwin->w_p_spell = FALSE; /* No spell checking */
clear_string_option(&curwin->w_s->b_p_spc); clear_string_option(&curwin->w_s->b_p_spc);
@ -6184,7 +6169,7 @@ int load_colors(char_u *name)
return OK; return OK;
recursive = TRUE; recursive = TRUE;
buf = alloc((unsigned)(STRLEN(name) + 12)); buf = xmalloc(STRLEN(name) + 12);
sprintf((char *)buf, "colors/%s.vim", name); sprintf((char *)buf, "colors/%s.vim", name);
retval = source_runtime(buf, FALSE); retval = source_runtime(buf, FALSE);
free(buf); free(buf);
@ -6392,10 +6377,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 +6421,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 +6703,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 +7384,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);
name = vim_strnsave(linep, len);
if (name != NULL) {
id = syn_name2id(name);
free(name); free(name);
}
return id; return id;
} }
@ -7433,8 +7403,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 */
@ -562,10 +557,9 @@ do_tag (
/* Find out the actual file name. If it is long, truncate /* Find out the actual file name. If it is long, truncate
* it and put "..." in the middle */ * it and put "..." in the middle */
p = tag_full_fname(&tagp); p = tag_full_fname(&tagp);
if (p != NULL) {
msg_puts_long_attr(p, hl_attr(HLF_D)); msg_puts_long_attr(p, hl_attr(HLF_D));
free(p); free(p);
}
if (msg_col > 0) if (msg_col > 0)
msg_putchar('\n'); msg_putchar('\n');
if (got_int) if (got_int)
@ -684,8 +678,8 @@ do_tag (
* window. * window.
*/ */
fname = alloc(MAXPATHL + 1); fname = xmalloc(MAXPATHL + 1);
cmd = alloc(CMDBUFFSIZE + 1); cmd = xmalloc(CMDBUFFSIZE + 1);
list = list_alloc(); list = list_alloc();
for (i = 0; i < num_matches; ++i) { for (i = 0; i < num_matches; ++i) {
@ -704,8 +698,6 @@ do_tag (
/* Save the tag file name */ /* Save the tag file name */
p = tag_full_fname(&tagp); p = tag_full_fname(&tagp);
if (p == NULL)
continue;
vim_strncpy(fname, p, MAXPATHL); vim_strncpy(fname, p, MAXPATHL);
free(p); free(p);
@ -1190,8 +1182,8 @@ find_tags (
/* /*
* Allocate memory for the buffers that are used * Allocate memory for the buffers that are used
*/ */
lbuf = alloc(lbuf_size); lbuf = xmalloc(lbuf_size);
tag_fname = alloc(MAXPATHL + 1); tag_fname = xmalloc(MAXPATHL + 1);
for (mtt = 0; mtt < MT_COUNT; ++mtt) for (mtt = 0; mtt < MT_COUNT; ++mtt)
ga_init(&ga_match[mtt], (int)sizeof(struct match_found *), 100); ga_init(&ga_match[mtt], (int)sizeof(struct match_found *), 100);
@ -1211,13 +1203,11 @@ 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' */
orgpat.len = p_tl; orgpat.len = p_tl;
@ -1821,9 +1811,7 @@ parse_line:
*/ */
*tagp.tagname_end = NUL; *tagp.tagname_end = NUL;
len = (int)(tagp.tagname_end - tagp.tagname); len = (int)(tagp.tagname_end - tagp.tagname);
mfp = (struct match_found *) mfp = xmalloc(sizeof(struct match_found) + len + 10 + ML_EXTRA);
alloc((int)sizeof(struct match_found) + len
+ 10 + ML_EXTRA);
/* "len" includes the language and the NUL, but /* "len" includes the language and the NUL, but
* not the priority. */ * not the priority. */
mfp->len = len + ML_EXTRA + 1; mfp->len = len + ML_EXTRA + 1;
@ -1851,8 +1839,7 @@ parse_line:
if (tagp.command + 2 < temp_end) { if (tagp.command + 2 < temp_end) {
len = (int)(temp_end - tagp.command - 2); len = (int)(temp_end - tagp.command - 2);
mfp = (struct match_found *)alloc( mfp = xmalloc(sizeof(struct match_found) + len);
(int)sizeof(struct match_found) + len);
mfp->len = len + 1; /* include the NUL */ mfp->len = len + 1; /* include the NUL */
p = mfp->match; p = mfp->match;
vim_strncpy(p, tagp.command + 2, len); vim_strncpy(p, tagp.command + 2, len);
@ -1861,8 +1848,7 @@ parse_line:
get_it_again = FALSE; get_it_again = FALSE;
} else { } else {
len = (int)(tagp.tagname_end - tagp.tagname); len = (int)(tagp.tagname_end - tagp.tagname);
mfp = (struct match_found *)alloc( mfp = xmalloc(sizeof(struct match_found) + len);
(int)sizeof(struct match_found) + len);
mfp->len = len + 1; /* include the NUL */ mfp->len = len + 1; /* include the NUL */
p = mfp->match; p = mfp->match;
vim_strncpy(p, tagp.tagname, len); vim_strncpy(p, tagp.tagname, len);
@ -1879,8 +1865,7 @@ parse_line:
*/ */
len = (int)STRLEN(tag_fname) len = (int)STRLEN(tag_fname)
+ (int)STRLEN(lbuf) + 3; + (int)STRLEN(lbuf) + 3;
mfp = (struct match_found *)alloc( mfp = xmalloc(sizeof(struct match_found) + len);
(int)sizeof(struct match_found) + len);
mfp->len = len; mfp->len = len;
p = mfp->match; p = mfp->match;
p[0] = mtt; p[0] = mtt;
@ -2099,8 +2084,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;
} }
@ -2335,19 +2318,13 @@ parse_match (
/* /*
* Find out the actual file name of a tag. Concatenate the tags file name * Find out the actual file name of a tag. Concatenate the tags file name
* with the matching tag file name. * with the matching tag file name.
* Returns an allocated string or NULL (out of memory). * Returns an allocated string.
*/ */
static char_u *tag_full_fname(tagptrs_T *tagp) static char_u *tag_full_fname(tagptrs_T *tagp)
{ {
char_u *fullname; int c = *tagp->fname_end;
int c;
{
c = *tagp->fname_end;
*tagp->fname_end = NUL; *tagp->fname_end = NUL;
} char_u *fullname = expand_tag_fname(tagp->fname, tagp->tag_fname, FALSE);
fullname = expand_tag_fname(tagp->fname, tagp->tag_fname, FALSE);
*tagp->fname_end = c; *tagp->fname_end = c;
return fullname; return fullname;
@ -2384,7 +2361,7 @@ jumpto_tag (
char_u *full_fname = NULL; char_u *full_fname = NULL;
int old_KeyTyped = KeyTyped; /* getting the file may reset it */ int old_KeyTyped = KeyTyped; /* getting the file may reset it */
pbuf = alloc(LSIZE); pbuf = xmalloc(LSIZE);
/* parse the match line into the tagp structure */ /* parse the match line into the tagp structure */
if (parse_match(lbuf, &tagp) == FAIL) { if (parse_match(lbuf, &tagp) == FAIL) {
@ -2420,8 +2397,6 @@ jumpto_tag (
* If 'tagrelative' option set, may change file name. * If 'tagrelative' option set, may change file name.
*/ */
fname = expand_tag_fname(fname, tagp.tag_fname, TRUE); fname = expand_tag_fname(fname, tagp.tag_fname, TRUE);
if (fname == NULL)
goto erret;
tofree_fname = fname; /* free() it later */ tofree_fname = fname; /* free() it later */
/* /*
@ -2435,8 +2410,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;
} }
@ -2653,12 +2626,11 @@ erret:
* If "expand" is TRUE, expand wildcards in fname. * If "expand" is TRUE, expand wildcards in fname.
* If 'tagrelative' option set, change fname (name of file containing tag) * If 'tagrelative' option set, change fname (name of file containing tag)
* according to tag_fname (name of tag file containing fname). * according to tag_fname (name of tag file containing fname).
* Returns a pointer to allocated memory (or NULL when out of memory). * Returns a pointer to allocated memory.
*/ */
static char_u *expand_tag_fname(char_u *fname, char_u *tag_fname, int expand) static char_u *expand_tag_fname(char_u *fname, char_u *tag_fname, int expand)
{ {
char_u *p; char_u *p;
char_u *retval;
char_u *expanded_fname = NULL; char_u *expanded_fname = NULL;
expand_T xpc; expand_T xpc;
@ -2674,10 +2646,11 @@ static char_u *expand_tag_fname(char_u *fname, char_u *tag_fname, int expand)
fname = expanded_fname; fname = expanded_fname;
} }
char_u *retval;
if ((p_tr || curbuf->b_help) if ((p_tr || curbuf->b_help)
&& !vim_isAbsName(fname) && !vim_isAbsName(fname)
&& (p = path_tail(tag_fname)) != tag_fname) { && (p = path_tail(tag_fname)) != tag_fname) {
retval = alloc(MAXPATHL); retval = xmalloc(MAXPATHL);
STRCPY(retval, tag_fname); STRCPY(retval, tag_fname);
vim_strncpy(retval + (p - tag_fname), fname, vim_strncpy(retval + (p - tag_fname), fname,
MAXPATHL - (p - tag_fname) - 1); MAXPATHL - (p - tag_fname) - 1);
@ -2711,10 +2684,8 @@ static int test_for_current(char_u *fname, char_u *fname_end, char_u *tag_fname,
*fname_end = NUL; *fname_end = NUL;
} }
fullname = expand_tag_fname(fname, tag_fname, TRUE); fullname = expand_tag_fname(fname, tag_fname, TRUE);
if (fullname != NULL) {
retval = (path_full_compare(fullname, buf_ffname, TRUE) & kEqualFiles); retval = (path_full_compare(fullname, buf_ffname, TRUE) & kEqualFiles);
free(fullname); free(fullname);
}
*fname_end = c; *fname_end = c;
} }
@ -2816,7 +2787,6 @@ add_tag_field (
char_u *end /* after the value; can be NULL */ char_u *end /* after the value; can be NULL */
) )
{ {
char_u *buf;
int len = 0; int len = 0;
int retval; int retval;
@ -2829,7 +2799,7 @@ add_tag_field (
} }
return FAIL; return FAIL;
} }
buf = alloc(MAXPATHL); char_u *buf = xmalloc(MAXPATHL);
if (start != NULL) { if (start != NULL) {
if (end == NULL) { if (end == NULL) {
end = start + STRLEN(start); end = start + STRLEN(start);

View File

@ -1198,7 +1198,6 @@ 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);
@ -1206,7 +1205,6 @@ static void parse_builtin_tcap(char_u *term)
} }
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) {
@ -2987,8 +2983,7 @@ void add_termcode(char_u *name, char_u *string, int flags)
*/ */
if (tc_len == tc_max_len) { if (tc_len == tc_max_len) {
tc_max_len += 20; tc_max_len += 20;
new_tc = (struct termcode *)alloc( new_tc = xmalloc(tc_max_len * sizeof(struct termcode));
(unsigned)(tc_max_len * sizeof(struct termcode)));
for (i = 0; i < tc_len; ++i) for (i = 0; i < tc_len; ++i)
new_tc[i] = termcodes[i]; new_tc[i] = termcodes[i];
free(termcodes); free(termcodes);
@ -4174,7 +4169,7 @@ replace_termcodes (
* Allocate space for the translation. Worst case a single character is * Allocate space for the translation. Worst case a single character is
* replaced by 6 bytes (shifted special key), plus a NUL at the end. * replaced by 6 bytes (shifted special key), plus a NUL at the end.
*/ */
result = alloc((unsigned)STRLEN(from) * 6 + 1); result = xmalloc(STRLEN(from) * 6 + 1);
src = from; src = from;
@ -4309,14 +4304,9 @@ replace_termcodes (
} }
result[dlen] = NUL; result[dlen] = NUL;
/* *bufp = xrealloc(result, dlen + 1);
* Copy the new string to allocated memory.
* If this fails, just return from. return *bufp;
*/
if ((*bufp = vim_strsave(result)) != NULL)
from = *bufp;
free(result);
return from;
} }
/* /*
@ -4380,7 +4370,7 @@ void show_termcodes(void)
if (tc_len == 0) /* no terminal codes (must be GUI) */ if (tc_len == 0) /* no terminal codes (must be GUI) */
return; return;
items = (int *)alloc((unsigned)(sizeof(int) * tc_len)); items = xmalloc(sizeof(int) * tc_len);
/* Highlight title */ /* Highlight title */
MSG_PUTS_TITLE(_("\n--- Terminal keys ---")); MSG_PUTS_TITLE(_("\n--- Terminal keys ---"));

View File

@ -272,12 +272,10 @@ int vim_is_input_buf_empty(void)
*/ */
char_u *get_input_buf(void) char_u *get_input_buf(void)
{ {
garray_T *gap;
/* We use a growarray to store the data pointer and the length. */ /* We use a growarray to store the data pointer and the length. */
gap = (garray_T *)alloc((unsigned)sizeof(garray_T)); garray_T *gap = xmalloc(sizeof(garray_T));
/* Add one to avoid a zero size. */ /* Add one to avoid a zero size. */
gap->ga_data = alloc((unsigned)inbufcount + 1); gap->ga_data = xmalloc(inbufcount + 1);
if (gap->ga_data != NULL) if (gap->ga_data != NULL)
memmove(gap->ga_data, inbuf, (size_t)inbufcount); memmove(gap->ga_data, inbuf, (size_t)inbufcount);
gap->ga_len = inbufcount; gap->ga_len = inbufcount;

View File

@ -594,10 +594,7 @@ int u_savecommon(linenr_T top, linenr_T bot, linenr_T newbot, int reload)
u_freeentry(uep, i); u_freeentry(uep, i);
return FAIL; return FAIL;
} }
if ((uep->ue_array[i] = u_save_line(lnum++)) == NULL) { uep->ue_array[i] = u_save_line(lnum++);
u_freeentry(uep, i);
goto nomem;
}
} }
} else } else
uep->ue_array = NULL; uep->ue_array = NULL;
@ -610,16 +607,6 @@ int u_savecommon(linenr_T top, linenr_T bot, linenr_T newbot, int reload)
u_check(FALSE); u_check(FALSE);
#endif #endif
return OK; return OK;
nomem:
msg_silent = 0; /* must display the prompt */
if (ask_yesno((char_u *)_("No undo possible; continue anyway"), TRUE)
== 'y') {
undo_off = TRUE; /* will be reset when character typed */
return OK;
}
do_outofmem_msg((long_u)0);
return FAIL;
} }
@ -695,8 +682,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 = '.';
@ -706,8 +691,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 = '%';
@ -2034,8 +2017,7 @@ static void u_undoredo(int undo)
/* delete backwards, it goes faster in most cases */ /* delete backwards, it goes faster in most cases */
for (lnum = bot - 1, i = oldsize; --i >= 0; --lnum) { for (lnum = bot - 1, i = oldsize; --i >= 0; --lnum) {
/* what can we do when we run out of memory? */ /* what can we do when we run out of memory? */
if ((newarray[i] = u_save_line(lnum)) == NULL) newarray[i] = u_save_line(lnum);
do_outofmem_msg((long_u)0);
/* remember we deleted the last line in the buffer, and a /* remember we deleted the last line in the buffer, and a
* dummy empty line will be inserted */ * dummy empty line will be inserted */
if (curbuf->b_ml.ml_line_count == 1) if (curbuf->b_ml.ml_line_count == 1)
@ -2666,8 +2648,7 @@ void u_saveline(linenr_T lnum)
curbuf->b_u_line_colnr = curwin->w_cursor.col; curbuf->b_u_line_colnr = curwin->w_cursor.col;
else else
curbuf->b_u_line_colnr = 0; curbuf->b_u_line_colnr = 0;
if ((curbuf->b_u_line_ptr = u_save_line(lnum)) == NULL) curbuf->b_u_line_ptr = u_save_line(lnum);
do_outofmem_msg((long_u)0);
} }
/* /*
@ -2708,10 +2689,6 @@ void u_undoline(void)
curbuf->b_u_line_lnum + 1, (linenr_T)0, FALSE) == FAIL) curbuf->b_u_line_lnum + 1, (linenr_T)0, FALSE) == FAIL)
return; return;
oldp = u_save_line(curbuf->b_u_line_lnum); oldp = u_save_line(curbuf->b_u_line_lnum);
if (oldp == NULL) {
do_outofmem_msg((long_u)0);
return;
}
ml_replace(curbuf->b_u_line_lnum, curbuf->b_u_line_ptr, TRUE); ml_replace(curbuf->b_u_line_lnum, curbuf->b_u_line_ptr, TRUE);
changed_bytes(curbuf->b_u_line_lnum, 0); changed_bytes(curbuf->b_u_line_lnum, 0);
free(curbuf->b_u_line_ptr); free(curbuf->b_u_line_ptr);
@ -2737,7 +2714,6 @@ void u_blockfree(buf_T *buf)
/* /*
* u_save_line(): allocate memory and copy line 'lnum' into it. * u_save_line(): allocate memory and copy line 'lnum' into it.
* Returns NULL when out of memory.
*/ */
static char_u *u_save_line(linenr_T lnum) static char_u *u_save_line(linenr_T lnum)
{ {

View File

@ -5263,7 +5263,7 @@ int match_add(win_T *wp, char_u *grp, char_u *pat, int prio, int id)
} }
/* Build new match. */ /* Build new match. */
m = (matchitem_T *)alloc(sizeof(matchitem_T)); m = xmalloc(sizeof(matchitem_T));
m->id = id; m->id = id;
m->priority = prio; m->priority = prio;
m->pattern = vim_strsave(pat); m->pattern = vim_strsave(pat);