Replace lalloc() with xmalloc()

This commit is contained in:
Felipe Oliveira Carvalho 2014-05-01 15:07:48 -03:00 committed by Justin M. Keyes
parent 973baa2a06
commit 8704a5832b
13 changed files with 125 additions and 190 deletions

View File

@ -4359,9 +4359,7 @@ static void insert_sign(
int typenr /* typenr of sign we are adding */ int typenr /* typenr of sign we are adding */
) )
{ {
signlist_T *newsign; signlist_T *newsign = xmalloc(sizeof(signlist_T));
newsign = (signlist_T *)lalloc((long_u)sizeof(signlist_T), FALSE);
newsign->id = id; newsign->id = id;
newsign->lnum = lnum; newsign->lnum = lnum;
newsign->typenr = typenr; newsign->typenr = typenr;

View File

@ -6271,32 +6271,31 @@ static int echeck_abbr(int c)
*/ */
static char_u *replace_stack = NULL; static char_u *replace_stack = NULL;
static long replace_stack_nr = 0; /* next entry in replace stack */ static ssize_t replace_stack_nr = 0; /* next entry in replace stack */
static long replace_stack_len = 0; /* max. number of entries */ static ssize_t replace_stack_len = 0; /* max. number of entries */
void void
replace_push ( replace_push (
int c /* character that is replaced (NUL is none) */ int c /* character that is replaced (NUL is none) */
) )
{ {
char_u *p;
if (replace_stack_nr < replace_offset) /* nothing to do */ if (replace_stack_nr < replace_offset) /* nothing to do */
return; return;
// TODO(philix): use xrealloc in replace_push()
if (replace_stack_len <= replace_stack_nr) { if (replace_stack_len <= replace_stack_nr) {
replace_stack_len += 50; replace_stack_len += 50;
p = lalloc(sizeof(char_u) * replace_stack_len, TRUE); void *aux = xmalloc(replace_stack_len);
if (replace_stack != NULL) { if (replace_stack != NULL) {
memmove(p, replace_stack, memmove(aux, replace_stack, replace_stack_nr);
(size_t)(replace_stack_nr * sizeof(char_u)));
free(replace_stack); free(replace_stack);
} }
replace_stack = p; replace_stack = aux;
} }
p = replace_stack + replace_stack_nr - replace_offset; char_u *p = replace_stack + replace_stack_nr - replace_offset;
if (replace_offset) if (replace_offset)
memmove(p + 1, p, (size_t)(replace_offset * sizeof(char_u))); memmove(p + 1, p, replace_offset);
*p = c; *p = (char_u)c;
++replace_stack_nr; ++replace_stack_nr;
} }

View File

@ -344,7 +344,6 @@ void ex_sort(exarg_T *eap)
int len; int len;
linenr_T lnum; linenr_T lnum;
long maxlen = 0; long maxlen = 0;
sorti_T *nrs;
size_t count = (size_t)(eap->line2 - eap->line1 + 1); size_t count = (size_t)(eap->line2 - eap->line1 + 1);
size_t i; size_t i;
char_u *p; char_u *p;
@ -367,9 +366,7 @@ void ex_sort(exarg_T *eap)
sortbuf1 = NULL; sortbuf1 = NULL;
sortbuf2 = NULL; sortbuf2 = NULL;
regmatch.regprog = NULL; regmatch.regprog = NULL;
nrs = (sorti_T *)lalloc((long_u)(count * sizeof(sorti_T)), TRUE); sorti_T *nrs = xmalloc(count * sizeof(sorti_T));
if (nrs == NULL)
goto sortend;
sort_abort = sort_ic = sort_rx = sort_nr = sort_oct = sort_hex = 0; sort_abort = sort_ic = sort_rx = sort_nr = sort_oct = sort_hex = 0;
@ -621,10 +618,8 @@ void ex_retab(exarg_T *eap)
/* len is actual number of white characters used */ /* len is actual number of white characters used */
len = num_spaces + num_tabs; len = num_spaces + num_tabs;
old_len = (long)STRLEN(ptr); old_len = (long)STRLEN(ptr);
new_line = lalloc(old_len - col + start_col + len + 1, new_line = xmalloc(old_len - col + start_col + len + 1);
TRUE);
if (new_line == NULL)
break;
if (start_col > 0) if (start_col > 0)
memmove(new_line, ptr, (size_t)start_col); memmove(new_line, ptr, (size_t)start_col);
memmove(new_line + start_col + len, memmove(new_line + start_col + len,
@ -1893,16 +1888,11 @@ viminfo_readstring (
{ {
char_u *retval; char_u *retval;
char_u *s, *d; char_u *s, *d;
long len;
if (virp->vir_line[off] == Ctrl_V && vim_isdigit(virp->vir_line[off + 1])) { if (virp->vir_line[off] == Ctrl_V && vim_isdigit(virp->vir_line[off + 1])) {
len = atol((char *)virp->vir_line + off + 1); ssize_t len = atol((char *)virp->vir_line + off + 1);
retval = lalloc(len, TRUE); retval = xmalloc(len);
if (retval == NULL) { // TODO(philix): change type of vim_fgets() size argument to size_t
/* Line too long? File messed up? Skip next line. */
(void)vim_fgets(virp->vir_line, 10, virp->vir_fd);
return NULL;
}
(void)vim_fgets(retval, (int)len, virp->vir_fd); (void)vim_fgets(retval, (int)len, virp->vir_fd);
s = retval + 1; /* Skip the leading '<' */ s = retval + 1; /* Skip the leading '<' */
} else { } else {

View File

@ -2791,7 +2791,6 @@ ExpandOne (
static char_u *orig_save = NULL; /* kept value of orig */ static char_u *orig_save = NULL; /* kept value of orig */
int orig_saved = FALSE; int orig_saved = FALSE;
int i; int i;
long_u len;
int non_suf_match; /* number without matching suffix */ int non_suf_match; /* number without matching suffix */
/* /*
@ -2910,6 +2909,7 @@ ExpandOne (
/* Find longest common part */ /* Find longest common part */
if (mode == WILD_LONGEST && xp->xp_numfiles > 0) { if (mode == WILD_LONGEST && xp->xp_numfiles > 0) {
size_t len;
for (len = 0; xp->xp_files[0][len]; ++len) { for (len = 0; xp->xp_files[0][len]; ++len) {
for (i = 0; i < xp->xp_numfiles; ++i) { for (i = 0; i < xp->xp_numfiles; ++i) {
if (p_fic && (xp->xp_context == EXPAND_DIRECTORIES if (p_fic && (xp->xp_context == EXPAND_DIRECTORIES
@ -2928,25 +2928,22 @@ ExpandOne (
break; break;
} }
} }
ss = alloc((unsigned)len + 1); ss = (char_u *)xstrndup((char *)xp->xp_files[0], len);
if (ss)
vim_strncpy(ss, xp->xp_files[0], (size_t)len);
findex = -1; /* next p_wc gets first one */ findex = -1; /* next p_wc gets first one */
} }
/* Concatenate all matching names */ // Concatenate all matching names
// TODO(philix): use xstpcpy instead of strcat in a loop (ExpandOne)
if (mode == WILD_ALL && xp->xp_numfiles > 0) { if (mode == WILD_ALL && xp->xp_numfiles > 0) {
len = 0; size_t len = 0;
for (i = 0; i < xp->xp_numfiles; ++i) for (i = 0; i < xp->xp_numfiles; ++i)
len += (long_u)STRLEN(xp->xp_files[i]) + 1; len += STRLEN(xp->xp_files[i]) + 1;
ss = lalloc(len, TRUE); ss = xmalloc(len);
if (ss != NULL) { *ss = NUL;
*ss = NUL; for (i = 0; i < xp->xp_numfiles; ++i) {
for (i = 0; i < xp->xp_numfiles; ++i) { STRCAT(ss, xp->xp_files[i]);
STRCAT(ss, xp->xp_files[i]); if (i != xp->xp_numfiles - 1)
if (i != xp->xp_numfiles - 1) STRCAT(ss, (options & WILD_USE_NL) ? "\n" : " ");
STRCAT(ss, (options & WILD_USE_NL) ? "\n" : " ");
}
} }
} }
@ -4327,32 +4324,19 @@ static char_u *get_history_arg(expand_T *xp, int idx)
*/ */
void init_history(void) void init_history(void)
{ {
int newlen; /* new length of history table */
histentry_T *temp;
int i;
int j;
int type;
/* /*
* If size of history table changed, reallocate it * If size of history table changed, reallocate it
*/ */
newlen = (int)p_hi; ssize_t newlen = p_hi;
if (newlen != hislen) { /* history length changed */ if (newlen != hislen) {
for (type = 0; type < HIST_COUNT; ++type) { /* adjust the tables */ histentry_T *temp;
ssize_t i;
ssize_t j;
// adjust the tables
for (int type = 0; type < HIST_COUNT; ++type) {
if (newlen) { if (newlen) {
temp = (histentry_T *)lalloc( temp = xmalloc(newlen * sizeof(*temp));
(long_u)(newlen * sizeof(histentry_T)), TRUE);
if (temp == NULL) { /* out of memory! */
if (type == 0) { /* first one: just keep the old length */
newlen = hislen;
break;
}
/* Already changed one table, now we can only have zero
* length for all tables. */
newlen = 0;
type = -1;
continue;
}
} else } else
temp = NULL; temp = NULL;
if (newlen == 0 || temp != NULL) { if (newlen == 0 || temp != NULL) {
@ -4969,29 +4953,26 @@ void prepare_viminfo_history(int asklen, int writing)
{ {
int i; int i;
int num; int num;
int type;
int len;
init_history(); init_history();
viminfo_add_at_front = (asklen != 0 && !writing); viminfo_add_at_front = (asklen != 0 && !writing);
if (asklen > hislen) if (asklen > hislen)
asklen = hislen; asklen = hislen;
for (type = 0; type < HIST_COUNT; ++type) { for (int type = 0; type < HIST_COUNT; ++type) {
/* Count the number of empty spaces in the history list. Entries read /* Count the number of empty spaces in the history list. Entries read
* from viminfo previously are also considered empty. If there are * from viminfo previously are also considered empty. If there are
* more spaces available than we request, then fill them up. */ * more spaces available than we request, then fill them up. */
for (i = 0, num = 0; i < hislen; i++) for (i = 0, num = 0; i < hislen; i++)
if (history[type][i].hisstr == NULL || history[type][i].viminfo) if (history[type][i].hisstr == NULL || history[type][i].viminfo)
num++; num++;
len = asklen; int len = asklen;
if (num > len) if (num > len)
len = num; len = num;
if (len <= 0) if (len <= 0)
viminfo_history[type] = NULL; viminfo_history[type] = NULL;
else else
viminfo_history[type] = viminfo_history[type] = xmalloc(len * sizeof(char_u *));
(char_u **)lalloc((long_u)(len * sizeof(char_u *)), FALSE);
if (viminfo_history[type] == NULL) if (viminfo_history[type] == NULL)
len = 0; len = 0;
viminfo_hislen[type] = len; viminfo_hislen[type] = len;
@ -5006,9 +4987,7 @@ void prepare_viminfo_history(int asklen, int writing)
int read_viminfo_history(vir_T *virp, int writing) int read_viminfo_history(vir_T *virp, int writing)
{ {
int type; int type;
long_u len;
char_u *val; char_u *val;
char_u *p;
type = hist_char2type(virp->vir_line[0]); type = hist_char2type(virp->vir_line[0]);
if (viminfo_hisidx[type] < viminfo_hislen[type]) { if (viminfo_hisidx[type] < viminfo_hislen[type]) {
@ -5019,22 +4998,20 @@ int read_viminfo_history(vir_T *virp, int writing)
if (!in_history(type, val + (type == HIST_SEARCH), if (!in_history(type, val + (type == HIST_SEARCH),
viminfo_add_at_front, sep, writing)) { viminfo_add_at_front, sep, writing)) {
/* Need to re-allocate to append the separator byte. */ /* Need to re-allocate to append the separator byte. */
len = STRLEN(val); size_t len = STRLEN(val);
p = lalloc(len + 2, TRUE); char_u *p = xmalloc(len + 2);
if (p != NULL) { if (type == HIST_SEARCH) {
if (type == HIST_SEARCH) { /* Search entry: Move the separator from the first
/* Search entry: Move the separator from the first * column to after the NUL. */
* column to after the NUL. */ memmove(p, val + 1, len);
memmove(p, val + 1, (size_t)len); p[len] = sep;
p[len] = sep; } else {
} else { /* Not a search entry: No separator in the viminfo
/* Not a search entry: No separator in the viminfo * file, add a NUL separator. */
* file, add a NUL separator. */ memmove(p, val, len + 1);
memmove(p, val, (size_t)len + 1); p[len + 1] = NUL;
p[len + 1] = NUL;
}
viminfo_history[type][viminfo_hisidx[type]++] = p;
} }
viminfo_history[type][viminfo_hisidx[type]++] = p;
} }
} }
free(val); free(val);

View File

@ -187,20 +187,19 @@ static char_u *get_buffcont(buffheader_T *buffer,
int dozero // count == zero is not an error int dozero // count == zero is not an error
) )
{ {
long_u count = 0; size_t count = 0;
char_u *p = NULL; char_u *p = NULL;
char_u *p2; char_u *p2;
char_u *str; char_u *str;
buffblock_T *bp;
/* compute the total length of the string */ /* compute the total length of the string */
for (bp = buffer->bh_first.b_next; bp != NULL; bp = bp->b_next) for (buffblock_T *bp = buffer->bh_first.b_next; bp != NULL; bp = bp->b_next)
count += (long_u)STRLEN(bp->b_str); count += STRLEN(bp->b_str);
if (count || dozero) { if (count || dozero) {
p = lalloc(count + 1, TRUE); p = xmalloc(count + 1);
p2 = p; p2 = p;
for (bp = buffer->bh_first.b_next; bp != NULL; bp = bp->b_next) for (buffblock_T *bp = buffer->bh_first.b_next; bp != NULL; bp = bp->b_next)
for (str = bp->b_str; *str; ) for (str = bp->b_str; *str; )
*p2++ = *str++; *p2++ = *str++;
*p2 = NUL; *p2 = NUL;
@ -261,9 +260,6 @@ add_buff (
long slen /* length of "s" or -1 */ long slen /* length of "s" or -1 */
) )
{ {
buffblock_T *p;
long_u len;
if (slen < 0) if (slen < 0)
slen = (long)STRLEN(s); slen = (long)STRLEN(s);
if (slen == 0) /* don't add empty strings */ if (slen == 0) /* don't add empty strings */
@ -281,8 +277,9 @@ add_buff (
STRLEN(buf->bh_first.b_next->b_str + buf->bh_index) + 1); STRLEN(buf->bh_first.b_next->b_str + buf->bh_index) + 1);
buf->bh_index = 0; buf->bh_index = 0;
ssize_t len;
if (buf->bh_space >= (int)slen) { if (buf->bh_space >= (int)slen) {
len = (long_u)STRLEN(buf->bh_curr->b_str); len = STRLEN(buf->bh_curr->b_str);
vim_strncpy(buf->bh_curr->b_str + len, s, (size_t)slen); vim_strncpy(buf->bh_curr->b_str + len, s, (size_t)slen);
buf->bh_space -= slen; buf->bh_space -= slen;
} else { } else {
@ -290,7 +287,7 @@ add_buff (
len = MINIMAL_SIZE; len = MINIMAL_SIZE;
else else
len = slen; len = slen;
p = (buffblock_T *)lalloc((long_u)(sizeof(buffblock_T) + len), TRUE); buffblock_T *p = xmalloc(sizeof(buffblock_T) + len);
buf->bh_space = (int)(len - slen); buf->bh_space = (int)(len - slen);
vim_strncpy(p->b_str, s, (size_t)slen); vim_strncpy(p->b_str, s, (size_t)slen);

View File

@ -885,9 +885,6 @@ int do_record(int c)
*/ */
static int stuff_yank(int regname, char_u *p) static int stuff_yank(int regname, char_u *p)
{ {
char_u *lp;
char_u **pp;
/* check for read-only register */ /* check for read-only register */
if (regname != 0 && !valid_yank_reg(regname, TRUE)) { if (regname != 0 && !valid_yank_reg(regname, TRUE)) {
free(p); free(p);
@ -899,9 +896,10 @@ static int stuff_yank(int regname, char_u *p)
} }
get_yank_register(regname, TRUE); get_yank_register(regname, TRUE);
if (y_append && y_current->y_array != NULL) { if (y_append && y_current->y_array != NULL) {
pp = &(y_current->y_array[y_current->y_size - 1]); char_u **pp = &(y_current->y_array[y_current->y_size - 1]);
lp = lalloc((long_u)(STRLEN(*pp) + STRLEN(p) + 1), TRUE); char_u *lp = xmalloc(STRLEN(*pp) + STRLEN(p) + 1);
STRCPY(lp, *pp); STRCPY(lp, *pp);
// TODO(philix): use xstpcpy() in stuff_yank()
STRCAT(lp, p); STRCAT(lp, p);
free(p); free(p);
free(*pp); free(*pp);
@ -2486,10 +2484,7 @@ int op_yank(oparg_T *oap, int deleting, int mess)
} }
if (curr != y_current) { /* append the new block to the old block */ if (curr != y_current) { /* append the new block to the old block */
new_ptr = (char_u **)lalloc( new_ptr = xmalloc(sizeof(char_u *) * (curr->y_size + y_current->y_size));
(long_u)(sizeof(char_u *) *
(curr->y_size + y_current->y_size)),
TRUE);
for (j = 0; j < curr->y_size; ++j) for (j = 0; j < curr->y_size; ++j)
new_ptr[j] = curr->y_array[j]; new_ptr[j] = curr->y_array[j];
free(curr->y_array); free(curr->y_array);
@ -2501,8 +2496,8 @@ int op_yank(oparg_T *oap, int deleting, int mess)
/* Concatenate the last line of the old block with the first line of /* Concatenate the last line of the old block with the first line of
* the new block, unless being Vi compatible. */ * the new block, unless being Vi compatible. */
if (curr->y_type == MCHAR && vim_strchr(p_cpo, CPO_REGAPPEND) == NULL) { if (curr->y_type == MCHAR && vim_strchr(p_cpo, CPO_REGAPPEND) == NULL) {
pnew = lalloc((long_u)(STRLEN(curr->y_array[curr->y_size - 1]) pnew = xmalloc(STRLEN(curr->y_array[curr->y_size - 1])
+ STRLEN(y_current->y_array[0]) + 1), TRUE); + STRLEN(y_current->y_array[0]) + 1);
STRCPY(pnew, curr->y_array[--j]); STRCPY(pnew, curr->y_array[--j]);
STRCAT(pnew, y_current->y_array[0]); STRCAT(pnew, y_current->y_array[0]);
free(curr->y_array[j]); free(curr->y_array[j]);
@ -4676,7 +4671,6 @@ get_reg_contents (
long i; long i;
char_u *retval; char_u *retval;
int allocated; int allocated;
long len;
/* Don't allow using an expression register inside an expression */ /* Don't allow using an expression register inside an expression */
if (regname == '=') { if (regname == '=') {
@ -4711,9 +4705,9 @@ get_reg_contents (
/* /*
* Compute length of resulting string. * Compute length of resulting string.
*/ */
len = 0; size_t len = 0;
for (i = 0; i < y_current->y_size; ++i) { for (i = 0; i < y_current->y_size; ++i) {
len += (long)STRLEN(y_current->y_array[i]); len += STRLEN(y_current->y_array[i]);
/* /*
* Insert a newline between lines and after last line if * Insert a newline between lines and after last line if
* y_type is MLINE. * y_type is MLINE.
@ -4722,26 +4716,24 @@ get_reg_contents (
++len; ++len;
} }
retval = lalloc(len + 1, TRUE); retval = xmalloc(len + 1);
/* /*
* Copy the lines of the yank register into the string. * Copy the lines of the yank register into the string.
*/ */
if (retval != NULL) { len = 0;
len = 0; for (i = 0; i < y_current->y_size; ++i) {
for (i = 0; i < y_current->y_size; ++i) { STRCPY(retval + len, y_current->y_array[i]);
STRCPY(retval + len, y_current->y_array[i]); len += STRLEN(retval + len);
len += (long)STRLEN(retval + len);
/* /*
* Insert a NL between lines and after the last line if y_type is * Insert a NL between lines and after the last line if y_type is
* MLINE. * MLINE.
*/ */
if (y_current->y_type == MLINE || i < y_current->y_size - 1) if (y_current->y_type == MLINE || i < y_current->y_size - 1)
retval[len++] = '\n'; retval[len++] = '\n';
}
retval[len] = NUL;
} }
retval[len] = NUL;
return retval; return retval;
} }

View File

@ -1184,7 +1184,6 @@ static void bt_regfree(regprog_T *prog);
*/ */
static regprog_T *bt_regcomp(char_u *expr, int re_flags) static regprog_T *bt_regcomp(char_u *expr, int re_flags)
{ {
bt_regprog_T *r;
char_u *scan; char_u *scan;
char_u *longest; char_u *longest;
int len; int len;
@ -1211,7 +1210,7 @@ static regprog_T *bt_regcomp(char_u *expr, int re_flags)
#endif #endif
/* Allocate space. */ /* Allocate space. */
r = (bt_regprog_T *)lalloc(sizeof(bt_regprog_T) + regsize, TRUE); bt_regprog_T *r = xmalloc(sizeof(bt_regprog_T) + regsize);
/* /*
* Second pass: emit code. * Second pass: emit code.
@ -6824,7 +6823,6 @@ char_u *reg_submatch(int no)
{ {
char_u *retval = NULL; char_u *retval = NULL;
char_u *s; char_u *s;
int len;
int round; int round;
linenr_T lnum; linenr_T lnum;
@ -6832,6 +6830,8 @@ char_u *reg_submatch(int no)
return NULL; return NULL;
if (submatch_match == NULL) { if (submatch_match == NULL) {
ssize_t len;
/* /*
* First round: compute the length and allocate memory. * First round: compute the length and allocate memory.
* Second round: copy the text. * Second round: copy the text.
@ -6854,7 +6854,7 @@ char_u *reg_submatch(int no)
} else { } else {
/* Multiple lines: take start line from start col, middle /* Multiple lines: take start line from start col, middle
* lines completely and end line up to end col. */ * lines completely and end line up to end col. */
len = (int)STRLEN(s); len = STRLEN(s);
if (round == 2) { if (round == 2) {
STRCPY(retval, s); STRCPY(retval, s);
retval[len] = '\n'; retval[len] = '\n';
@ -6865,7 +6865,7 @@ char_u *reg_submatch(int no)
s = reg_getline_submatch(lnum++); s = reg_getline_submatch(lnum++);
if (round == 2) if (round == 2)
STRCPY(retval + len, s); STRCPY(retval + len, s);
len += (int)STRLEN(s); len += STRLEN(s);
if (round == 2) if (round == 2)
retval[len] = '\n'; retval[len] = '\n';
++len; ++len;
@ -6880,7 +6880,7 @@ char_u *reg_submatch(int no)
} }
if (retval == NULL) { if (retval == NULL) {
retval = lalloc((long_u)len, TRUE); retval = xmalloc(len);
} }
} }
} else { } else {

View File

@ -2869,7 +2869,7 @@ static nfa_state_T *post2nfa(int *postfix, int *end, int nfa_calc_size)
if (nfa_calc_size == FALSE) { if (nfa_calc_size == FALSE) {
/* Allocate space for the stack. Max states on the stack : nstate */ /* Allocate space for the stack. Max states on the stack : nstate */
stack = (Frag_T *)lalloc((nstate + 1) * sizeof(Frag_T), TRUE); stack = xmalloc((nstate + 1) * sizeof(Frag_T));
stackp = stack; stackp = stack;
stack_end = stack + (nstate + 1); stack_end = stack + (nstate + 1);
} }
@ -4525,7 +4525,7 @@ static int recursive_regmatch(nfa_state_T *state, nfa_pim_T *pim, nfa_regprog_T
/* Already calling nfa_regmatch() recursively. Save the lastlist[1] /* Already calling nfa_regmatch() recursively. Save the lastlist[1]
* values and clear them. */ * values and clear them. */
if (*listids == NULL) { if (*listids == NULL) {
*listids = (int *)lalloc(sizeof(int) * nstate, TRUE); *listids = xmalloc(sizeof(**listids) * nstate);
} }
nfa_save_listids(prog, *listids); nfa_save_listids(prog, *listids);
need_restore = TRUE; need_restore = TRUE;
@ -4821,7 +4821,6 @@ static long find_match_text(colnr_T startcol, int regstart, char_u *match_text)
static int nfa_regmatch(nfa_regprog_T *prog, nfa_state_T *start, regsubs_T *submatch, regsubs_T *m) static int nfa_regmatch(nfa_regprog_T *prog, nfa_state_T *start, regsubs_T *submatch, regsubs_T *m)
{ {
int result; int result;
int size = 0;
int flag = 0; int flag = 0;
int go_to_nextline = FALSE; int go_to_nextline = FALSE;
nfa_thread_T *t; nfa_thread_T *t;
@ -4852,10 +4851,10 @@ static int nfa_regmatch(nfa_regprog_T *prog, nfa_state_T *start, regsubs_T *subm
nfa_match = FALSE; nfa_match = FALSE;
/* Allocate memory for the lists of nodes. */ /* Allocate memory for the lists of nodes. */
size = (nstate + 1) * sizeof(nfa_thread_T); size_t size = (nstate + 1) * sizeof(nfa_thread_T);
list[0].t = (nfa_thread_T *)lalloc(size, TRUE); list[0].t = xmalloc(size);
list[0].len = nstate + 1; list[0].len = nstate + 1;
list[1].t = (nfa_thread_T *)lalloc(size, TRUE); list[1].t = xmalloc(size);
list[1].len = nstate + 1; list[1].len = nstate + 1;
#ifdef REGEXP_DEBUG #ifdef REGEXP_DEBUG
@ -6231,7 +6230,6 @@ theend:
static regprog_T *nfa_regcomp(char_u *expr, int re_flags) static regprog_T *nfa_regcomp(char_u *expr, int re_flags)
{ {
nfa_regprog_T *prog = NULL; nfa_regprog_T *prog = NULL;
size_t prog_size;
int *postfix; int *postfix;
if (expr == NULL) if (expr == NULL)
@ -6283,8 +6281,8 @@ static regprog_T *nfa_regcomp(char_u *expr, int re_flags)
post2nfa(postfix, post_ptr, TRUE); post2nfa(postfix, post_ptr, TRUE);
/* allocate the regprog with space for the compiled regexp */ /* allocate the regprog with space for the compiled regexp */
prog_size = sizeof(nfa_regprog_T) + sizeof(nfa_state_T) * (nstate - 1); size_t prog_size = sizeof(nfa_regprog_T) + sizeof(nfa_state_T) * (nstate - 1);
prog = (nfa_regprog_T *)lalloc(prog_size, TRUE); prog = xmalloc(prog_size);
state_ptr = prog->state; state_ptr = prog->state;
/* /*

View File

@ -288,23 +288,18 @@ int redraw_asap(int type)
/* Allocate space to save the text displayed in the command line area. */ /* Allocate space to save the text displayed in the command line area. */
rows = Rows - cmdline_row; rows = Rows - cmdline_row;
screenline = (schar_T *)lalloc( screenline = xmalloc((size_t)(rows * Columns * sizeof(schar_T)));
(long_u)(rows * Columns * sizeof(schar_T)), FALSE); screenattr = xmalloc((size_t)(rows * Columns * sizeof(sattr_T)));
screenattr = (sattr_T *)lalloc(
(long_u)(rows * Columns * sizeof(sattr_T)), FALSE);
if (enc_utf8) { if (enc_utf8) {
screenlineUC = (u8char_T *)lalloc( screenlineUC = xmalloc((size_t)(rows * Columns * sizeof(u8char_T)));
(long_u)(rows * Columns * sizeof(u8char_T)), FALSE);
for (i = 0; i < p_mco; ++i) { for (i = 0; i < p_mco; ++i) {
screenlineC[i] = (u8char_T *)lalloc( screenlineC[i] = xmalloc((size_t)(rows * Columns * sizeof(u8char_T)));
(long_u)(rows * Columns * sizeof(u8char_T)), FALSE);
} }
} }
if (enc_dbcs == DBCS_JPNU) { if (enc_dbcs == DBCS_JPNU) {
screenline2 = (schar_T *)lalloc( screenline2 = xmalloc((size_t)(rows * Columns * sizeof(schar_T)));
(long_u)(rows * Columns * sizeof(schar_T)), FALSE);
} }
/* Save the text displayed in the command line area. */ /* Save the text displayed in the command line area. */
@ -6258,24 +6253,21 @@ retry:
if (aucmd_win != NULL) if (aucmd_win != NULL)
win_free_lsize(aucmd_win); win_free_lsize(aucmd_win);
new_ScreenLines = (schar_T *)lalloc((long_u)( new_ScreenLines = xmalloc((size_t)((Rows + 1) * Columns * sizeof(schar_T)));
(Rows + 1) * Columns * sizeof(schar_T)), FALSE);
memset(new_ScreenLinesC, 0, sizeof(u8char_T *) * MAX_MCO); memset(new_ScreenLinesC, 0, sizeof(u8char_T *) * MAX_MCO);
if (enc_utf8) { if (enc_utf8) {
new_ScreenLinesUC = (u8char_T *)lalloc((long_u)( new_ScreenLinesUC = xmalloc(
(Rows + 1) * Columns * sizeof(u8char_T)), FALSE); (size_t)((Rows + 1) * Columns * sizeof(u8char_T)));
for (i = 0; i < p_mco; ++i) for (i = 0; i < p_mco; ++i)
new_ScreenLinesC[i] = xcalloc((Rows + 1) * Columns, sizeof(u8char_T)); new_ScreenLinesC[i] = xcalloc((Rows + 1) * Columns, sizeof(u8char_T));
} }
if (enc_dbcs == DBCS_JPNU) if (enc_dbcs == DBCS_JPNU)
new_ScreenLines2 = (schar_T *)lalloc((long_u)( new_ScreenLines2 = xmalloc(
(Rows + 1) * Columns * sizeof(schar_T)), FALSE); (size_t)((Rows + 1) * Columns * sizeof(schar_T)));
new_ScreenAttrs = (sattr_T *)lalloc((long_u)( new_ScreenAttrs = xmalloc((size_t)((Rows + 1) * Columns * sizeof(sattr_T)));
(Rows + 1) * Columns * sizeof(sattr_T)), FALSE); new_LineOffset = xmalloc((size_t)(Rows * sizeof(unsigned)));
new_LineOffset = (unsigned *)lalloc((long_u)( new_LineWraps = xmalloc((size_t)(Rows * sizeof(char_u)));
Rows * sizeof(unsigned)), FALSE); new_TabPageIdxs = xmalloc((size_t)(Columns * sizeof(short)));
new_LineWraps = (char_u *)lalloc((long_u)(Rows * sizeof(char_u)), FALSE);
new_TabPageIdxs = (short *)lalloc((long_u)(Columns * sizeof(short)), FALSE);
FOR_ALL_TAB_WINDOWS(tp, wp) FOR_ALL_TAB_WINDOWS(tp, wp)
{ {

View File

@ -4195,8 +4195,7 @@ find_pattern_in_path (
if (new_fname != NULL) { if (new_fname != NULL) {
/* Push the new file onto the file stack */ /* Push the new file onto the file stack */
if (depth + 1 == old_files) { if (depth + 1 == old_files) {
bigger = (SearchedFile *)lalloc((long_u)( bigger = xmalloc(max_path_depth * 2 * sizeof(SearchedFile));
max_path_depth * 2 * sizeof(SearchedFile)), TRUE);
for (i = 0; i <= depth; i++) for (i = 0; i <= depth; i++)
bigger[i] = files[i]; bigger[i] = files[i];
for (i = depth + 1; i < old_files + max_path_depth; i++) { for (i = depth + 1; i < old_files + max_path_depth; i++) {
@ -4217,10 +4216,8 @@ find_pattern_in_path (
free(new_fname); free(new_fname);
else { else {
if (++depth == old_files) { if (++depth == old_files) {
/* // Something wrong. We will forget one of our already visited files
* lalloc() for 'bigger' must have failed above. We // now.
* will forget one of our already visited files now.
*/
free(files[old_files].name); free(files[old_files].name);
++old_files; ++old_files;
} }

View File

@ -3493,19 +3493,18 @@ spell_read_tree (
int prefixcnt // when "prefixtree" is TRUE: prefix count int prefixcnt // when "prefixtree" is TRUE: prefix count
) )
{ {
int len;
int idx; int idx;
char_u *bp; char_u *bp;
idx_T *ip; idx_T *ip;
// The tree size was computed when writing the file, so that we can // The tree size was computed when writing the file, so that we can
// allocate it as one long block. <nodecount> // allocate it as one long block. <nodecount>
len = get4c(fd); int len = get4c(fd);
if (len < 0) if (len < 0)
return SP_TRUNCERROR; return SP_TRUNCERROR;
if (len > 0) { if (len > 0) {
// Allocate the byte array. // Allocate the byte array.
bp = lalloc((long_u)len, TRUE); bp = xmalloc(len);
*bytsp = bp; *bytsp = bp;
// Allocate the index array. // Allocate the index array.
@ -12762,8 +12761,7 @@ static int spell_edit_score(slang_T *slang, char_u *badword, char_u *goodword)
// We use "cnt" as an array: CNT(badword_idx, goodword_idx). // We use "cnt" as an array: CNT(badword_idx, goodword_idx).
#define CNT(a, b) cnt[(a) + (b) * (badlen + 1)] #define CNT(a, b) cnt[(a) + (b) * (badlen + 1)]
cnt = (int *)lalloc((long_u)(sizeof(int) * (badlen + 1) * (goodlen + 1)), cnt = xmalloc(sizeof(int) * (badlen + 1) * (goodlen + 1));
TRUE);
CNT(0, 0) = 0; CNT(0, 0) = 0;
for (j = 1; j <= goodlen; ++j) for (j = 1; j <= goodlen; ++j)

View File

@ -1990,8 +1990,7 @@ findtag_end:
match_count = 0; match_count = 0;
if (match_count > 0) if (match_count > 0)
matches = (char_u **)lalloc((long_u)(match_count * sizeof(char_u *)), matches = xmalloc(match_count * sizeof(char_u *));
TRUE);
else else
matches = NULL; matches = NULL;
match_count = 0; match_count = 0;

View File

@ -135,7 +135,6 @@ static void serialize_visualinfo(visualinfo_T *info, FILE *fp);
static void unserialize_visualinfo(visualinfo_T *info, FILE *fp); static void unserialize_visualinfo(visualinfo_T *info, FILE *fp);
static void put_header_ptr(FILE *fp, u_header_T *uhp); static void put_header_ptr(FILE *fp, u_header_T *uhp);
#define U_ALLOC_LINE(size) lalloc((long_u)(size), FALSE)
static char_u *u_save_line(linenr_T); static char_u *u_save_line(linenr_T);
/* used in undo_end() to report number of added and deleted lines */ /* used in undo_end() to report number of added and deleted lines */
@ -403,7 +402,7 @@ int u_savecommon(linenr_T top, linenr_T bot, linenr_T newbot, int reload)
* Make a new header entry. Do this first so that we don't mess * Make a new header entry. Do this first so that we don't mess
* up the undo info when out of memory. * up the undo info when out of memory.
*/ */
uhp = (u_header_T *)U_ALLOC_LINE(sizeof(u_header_T)); uhp = xmalloc(sizeof(u_header_T));
#ifdef U_DEBUG #ifdef U_DEBUG
uhp->uh_magic = UH_MAGIC; uhp->uh_magic = UH_MAGIC;
#endif #endif
@ -569,7 +568,7 @@ int u_savecommon(linenr_T top, linenr_T bot, linenr_T newbot, int reload)
/* /*
* add lines in front of entry list * add lines in front of entry list
*/ */
uep = (u_entry_T *)U_ALLOC_LINE(sizeof(u_entry_T)); uep = xmalloc(sizeof(u_entry_T));
memset(uep, 0, sizeof(u_entry_T)); memset(uep, 0, sizeof(u_entry_T));
#ifdef U_DEBUG #ifdef U_DEBUG
uep->ue_magic = UE_MAGIC; uep->ue_magic = UE_MAGIC;
@ -591,7 +590,7 @@ int u_savecommon(linenr_T top, linenr_T bot, linenr_T newbot, int reload)
} }
if (size > 0) { if (size > 0) {
uep->ue_array = (char_u **)U_ALLOC_LINE(sizeof(char_u *) * size); uep->ue_array = xmalloc(sizeof(char_u *) * size);
for (i = 0, lnum = top + 1; i < size; ++i) { for (i = 0, lnum = top + 1; i < size; ++i) {
fast_breakcheck(); fast_breakcheck();
if (got_int) { if (got_int) {
@ -769,7 +768,7 @@ static size_t fwrite_crypt(buf_T *buf, char_u *ptr, size_t len, FILE *fp)
if (len < 100) if (len < 100)
copy = small_buf; /* no malloc()/free() for short strings */ copy = small_buf; /* no malloc()/free() for short strings */
else { else {
copy = lalloc(len, FALSE); copy = xmalloc(len);
} }
crypt_encode(ptr, len, copy); crypt_encode(ptr, len, copy);
i = fwrite(copy, len, (size_t)1, fp); i = fwrite(copy, len, (size_t)1, fp);
@ -901,7 +900,7 @@ static u_header_T *unserialize_uhp(FILE *fp, char_u *file_name)
int c; int c;
int error; int error;
uhp = (u_header_T *)U_ALLOC_LINE(sizeof(u_header_T)); uhp = xmalloc(sizeof(u_header_T));
memset(uhp, 0, sizeof(u_header_T)); memset(uhp, 0, sizeof(u_header_T));
#ifdef U_DEBUG #ifdef U_DEBUG
uhp->uh_magic = UH_MAGIC; uhp->uh_magic = UH_MAGIC;
@ -997,7 +996,7 @@ static u_entry_T *unserialize_uep(FILE *fp, int *error, char_u *file_name)
char_u *line; char_u *line;
int line_len; int line_len;
uep = (u_entry_T *)U_ALLOC_LINE(sizeof(u_entry_T)); uep = xmalloc(sizeof(u_entry_T));
memset(uep, 0, sizeof(u_entry_T)); memset(uep, 0, sizeof(u_entry_T));
#ifdef U_DEBUG #ifdef U_DEBUG
uep->ue_magic = UE_MAGIC; uep->ue_magic = UE_MAGIC;
@ -1007,7 +1006,7 @@ static u_entry_T *unserialize_uep(FILE *fp, int *error, char_u *file_name)
uep->ue_lcount = get4c(fp); uep->ue_lcount = get4c(fp);
uep->ue_size = get4c(fp); uep->ue_size = get4c(fp);
if (uep->ue_size > 0) { if (uep->ue_size > 0) {
array = (char_u **)U_ALLOC_LINE(sizeof(char_u *) * uep->ue_size); array = xmalloc(sizeof(char_u *) * uep->ue_size);
memset(array, 0, sizeof(char_u *) * uep->ue_size); memset(array, 0, sizeof(char_u *) * uep->ue_size);
} else } else
array = NULL; array = NULL;
@ -1484,8 +1483,7 @@ void u_read_undo(char_u *name, char_u *hash, char_u *orig_name)
* sequence numbers of the headers. * sequence numbers of the headers.
* When there are no headers uhp_table is NULL. */ * When there are no headers uhp_table is NULL. */
if (num_head > 0) { if (num_head > 0) {
uhp_table = (u_header_T **)U_ALLOC_LINE( uhp_table = xmalloc(num_head * sizeof(u_header_T *));
num_head * sizeof(u_header_T *));
} }
while ((c = get2c(fp)) == UF_HEADER_MAGIC) { while ((c = get2c(fp)) == UF_HEADER_MAGIC) {
@ -2122,7 +2120,7 @@ static void u_undoredo(int undo)
/* delete the lines between top and bot and save them in newarray */ /* delete the lines between top and bot and save them in newarray */
if (oldsize > 0) { if (oldsize > 0) {
newarray = (char_u **)U_ALLOC_LINE(sizeof(char_u *) * oldsize); newarray = xmalloc(sizeof(char_u *) * oldsize);
/* 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? */