aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/buffer.c4
-rw-r--r--src/edit.c21
-rw-r--r--src/ex_cmds.c22
-rw-r--r--src/ex_getln.c97
-rw-r--r--src/getchar.c19
-rw-r--r--src/ops.c48
-rw-r--r--src/regexp.c12
-rw-r--r--src/regexp_nfa.c16
-rw-r--r--src/screen.c36
-rw-r--r--src/search.c9
-rw-r--r--src/spell.c8
-rw-r--r--src/tag.c3
-rw-r--r--src/undo.c20
13 files changed, 125 insertions, 190 deletions
diff --git a/src/buffer.c b/src/buffer.c
index 4e87305c60..d2379f4afa 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -4359,9 +4359,7 @@ static void insert_sign(
int typenr /* typenr of sign we are adding */
)
{
- signlist_T *newsign;
-
- newsign = (signlist_T *)lalloc((long_u)sizeof(signlist_T), FALSE);
+ signlist_T *newsign = xmalloc(sizeof(signlist_T));
newsign->id = id;
newsign->lnum = lnum;
newsign->typenr = typenr;
diff --git a/src/edit.c b/src/edit.c
index 4b1d1878d1..146a8bba70 100644
--- a/src/edit.c
+++ b/src/edit.c
@@ -6271,32 +6271,31 @@ static int echeck_abbr(int c)
*/
static char_u *replace_stack = NULL;
-static long replace_stack_nr = 0; /* next entry in replace stack */
-static long replace_stack_len = 0; /* max. number of entries */
+static ssize_t replace_stack_nr = 0; /* next entry in replace stack */
+static ssize_t replace_stack_len = 0; /* max. number of entries */
void
replace_push (
int c /* character that is replaced (NUL is none) */
)
{
- char_u *p;
-
if (replace_stack_nr < replace_offset) /* nothing to do */
return;
+
+ // TODO(philix): use xrealloc in replace_push()
if (replace_stack_len <= replace_stack_nr) {
replace_stack_len += 50;
- p = lalloc(sizeof(char_u) * replace_stack_len, TRUE);
+ void *aux = xmalloc(replace_stack_len);
if (replace_stack != NULL) {
- memmove(p, replace_stack,
- (size_t)(replace_stack_nr * sizeof(char_u)));
+ memmove(aux, replace_stack, replace_stack_nr);
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)
- memmove(p + 1, p, (size_t)(replace_offset * sizeof(char_u)));
- *p = c;
+ memmove(p + 1, p, replace_offset);
+ *p = (char_u)c;
++replace_stack_nr;
}
diff --git a/src/ex_cmds.c b/src/ex_cmds.c
index 6a6b2fc615..0ef98b4c2a 100644
--- a/src/ex_cmds.c
+++ b/src/ex_cmds.c
@@ -344,7 +344,6 @@ void ex_sort(exarg_T *eap)
int len;
linenr_T lnum;
long maxlen = 0;
- sorti_T *nrs;
size_t count = (size_t)(eap->line2 - eap->line1 + 1);
size_t i;
char_u *p;
@@ -367,9 +366,7 @@ void ex_sort(exarg_T *eap)
sortbuf1 = NULL;
sortbuf2 = NULL;
regmatch.regprog = NULL;
- nrs = (sorti_T *)lalloc((long_u)(count * sizeof(sorti_T)), TRUE);
- if (nrs == NULL)
- goto sortend;
+ sorti_T *nrs = xmalloc(count * sizeof(sorti_T));
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 = num_spaces + num_tabs;
old_len = (long)STRLEN(ptr);
- new_line = lalloc(old_len - col + start_col + len + 1,
- TRUE);
- if (new_line == NULL)
- break;
+ new_line = xmalloc(old_len - col + start_col + len + 1);
+
if (start_col > 0)
memmove(new_line, ptr, (size_t)start_col);
memmove(new_line + start_col + len,
@@ -1893,16 +1888,11 @@ viminfo_readstring (
{
char_u *retval;
char_u *s, *d;
- long len;
if (virp->vir_line[off] == Ctrl_V && vim_isdigit(virp->vir_line[off + 1])) {
- len = atol((char *)virp->vir_line + off + 1);
- retval = lalloc(len, TRUE);
- if (retval == NULL) {
- /* Line too long? File messed up? Skip next line. */
- (void)vim_fgets(virp->vir_line, 10, virp->vir_fd);
- return NULL;
- }
+ ssize_t len = atol((char *)virp->vir_line + off + 1);
+ retval = xmalloc(len);
+ // TODO(philix): change type of vim_fgets() size argument to size_t
(void)vim_fgets(retval, (int)len, virp->vir_fd);
s = retval + 1; /* Skip the leading '<' */
} else {
diff --git a/src/ex_getln.c b/src/ex_getln.c
index 5b6b3c0c27..8e2d7cc9ae 100644
--- a/src/ex_getln.c
+++ b/src/ex_getln.c
@@ -2791,7 +2791,6 @@ ExpandOne (
static char_u *orig_save = NULL; /* kept value of orig */
int orig_saved = FALSE;
int i;
- long_u len;
int non_suf_match; /* number without matching suffix */
/*
@@ -2910,6 +2909,7 @@ ExpandOne (
/* Find longest common part */
if (mode == WILD_LONGEST && xp->xp_numfiles > 0) {
+ size_t len;
for (len = 0; xp->xp_files[0][len]; ++len) {
for (i = 0; i < xp->xp_numfiles; ++i) {
if (p_fic && (xp->xp_context == EXPAND_DIRECTORIES
@@ -2928,25 +2928,22 @@ ExpandOne (
break;
}
}
- ss = alloc((unsigned)len + 1);
- if (ss)
- vim_strncpy(ss, xp->xp_files[0], (size_t)len);
+ ss = (char_u *)xstrndup((char *)xp->xp_files[0], len);
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) {
- len = 0;
+ size_t len = 0;
for (i = 0; i < xp->xp_numfiles; ++i)
- len += (long_u)STRLEN(xp->xp_files[i]) + 1;
- ss = lalloc(len, TRUE);
- if (ss != NULL) {
- *ss = NUL;
- for (i = 0; i < xp->xp_numfiles; ++i) {
- STRCAT(ss, xp->xp_files[i]);
- if (i != xp->xp_numfiles - 1)
- STRCAT(ss, (options & WILD_USE_NL) ? "\n" : " ");
- }
+ len += STRLEN(xp->xp_files[i]) + 1;
+ ss = xmalloc(len);
+ *ss = NUL;
+ for (i = 0; i < xp->xp_numfiles; ++i) {
+ STRCAT(ss, xp->xp_files[i]);
+ if (i != xp->xp_numfiles - 1)
+ 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)
{
- int newlen; /* new length of history table */
- histentry_T *temp;
- int i;
- int j;
- int type;
-
/*
* If size of history table changed, reallocate it
*/
- newlen = (int)p_hi;
- if (newlen != hislen) { /* history length changed */
- for (type = 0; type < HIST_COUNT; ++type) { /* adjust the tables */
+ ssize_t newlen = p_hi;
+ if (newlen != hislen) {
+ histentry_T *temp;
+ ssize_t i;
+ ssize_t j;
+
+ // adjust the tables
+ for (int type = 0; type < HIST_COUNT; ++type) {
if (newlen) {
- temp = (histentry_T *)lalloc(
- (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;
- }
+ temp = xmalloc(newlen * sizeof(*temp));
} else
temp = NULL;
if (newlen == 0 || temp != NULL) {
@@ -4969,29 +4953,26 @@ void prepare_viminfo_history(int asklen, int writing)
{
int i;
int num;
- int type;
- int len;
init_history();
viminfo_add_at_front = (asklen != 0 && !writing);
if (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
* from viminfo previously are also considered empty. If there are
* more spaces available than we request, then fill them up. */
for (i = 0, num = 0; i < hislen; i++)
if (history[type][i].hisstr == NULL || history[type][i].viminfo)
num++;
- len = asklen;
+ int len = asklen;
if (num > len)
len = num;
if (len <= 0)
viminfo_history[type] = NULL;
else
- viminfo_history[type] =
- (char_u **)lalloc((long_u)(len * sizeof(char_u *)), FALSE);
+ viminfo_history[type] = xmalloc(len * sizeof(char_u *));
if (viminfo_history[type] == NULL)
len = 0;
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 type;
- long_u len;
char_u *val;
- char_u *p;
type = hist_char2type(virp->vir_line[0]);
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),
viminfo_add_at_front, sep, writing)) {
/* Need to re-allocate to append the separator byte. */
- len = STRLEN(val);
- p = lalloc(len + 2, TRUE);
- if (p != NULL) {
- if (type == HIST_SEARCH) {
- /* Search entry: Move the separator from the first
- * column to after the NUL. */
- memmove(p, val + 1, (size_t)len);
- p[len] = sep;
- } else {
- /* Not a search entry: No separator in the viminfo
- * file, add a NUL separator. */
- memmove(p, val, (size_t)len + 1);
- p[len + 1] = NUL;
- }
- viminfo_history[type][viminfo_hisidx[type]++] = p;
+ size_t len = STRLEN(val);
+ char_u *p = xmalloc(len + 2);
+ if (type == HIST_SEARCH) {
+ /* Search entry: Move the separator from the first
+ * column to after the NUL. */
+ memmove(p, val + 1, len);
+ p[len] = sep;
+ } else {
+ /* Not a search entry: No separator in the viminfo
+ * file, add a NUL separator. */
+ memmove(p, val, len + 1);
+ p[len + 1] = NUL;
}
+ viminfo_history[type][viminfo_hisidx[type]++] = p;
}
}
free(val);
diff --git a/src/getchar.c b/src/getchar.c
index d6948ee671..99dbc11e4d 100644
--- a/src/getchar.c
+++ b/src/getchar.c
@@ -187,20 +187,19 @@ static char_u *get_buffcont(buffheader_T *buffer,
int dozero // count == zero is not an error
)
{
- long_u count = 0;
+ size_t count = 0;
char_u *p = NULL;
char_u *p2;
char_u *str;
- buffblock_T *bp;
/* compute the total length of the string */
- for (bp = buffer->bh_first.b_next; bp != NULL; bp = bp->b_next)
- count += (long_u)STRLEN(bp->b_str);
+ for (buffblock_T *bp = buffer->bh_first.b_next; bp != NULL; bp = bp->b_next)
+ count += STRLEN(bp->b_str);
if (count || dozero) {
- p = lalloc(count + 1, TRUE);
+ p = xmalloc(count + 1);
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; )
*p2++ = *str++;
*p2 = NUL;
@@ -261,9 +260,6 @@ add_buff (
long slen /* length of "s" or -1 */
)
{
- buffblock_T *p;
- long_u len;
-
if (slen < 0)
slen = (long)STRLEN(s);
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);
buf->bh_index = 0;
+ ssize_t len;
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);
buf->bh_space -= slen;
} else {
@@ -290,7 +287,7 @@ add_buff (
len = MINIMAL_SIZE;
else
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);
vim_strncpy(p->b_str, s, (size_t)slen);
diff --git a/src/ops.c b/src/ops.c
index f729f4e06b..30606b077e 100644
--- a/src/ops.c
+++ b/src/ops.c
@@ -885,9 +885,6 @@ int do_record(int c)
*/
static int stuff_yank(int regname, char_u *p)
{
- char_u *lp;
- char_u **pp;
-
/* check for read-only register */
if (regname != 0 && !valid_yank_reg(regname, TRUE)) {
free(p);
@@ -899,9 +896,10 @@ static int stuff_yank(int regname, char_u *p)
}
get_yank_register(regname, TRUE);
if (y_append && y_current->y_array != NULL) {
- pp = &(y_current->y_array[y_current->y_size - 1]);
- lp = lalloc((long_u)(STRLEN(*pp) + STRLEN(p) + 1), TRUE);
+ char_u **pp = &(y_current->y_array[y_current->y_size - 1]);
+ char_u *lp = xmalloc(STRLEN(*pp) + STRLEN(p) + 1);
STRCPY(lp, *pp);
+ // TODO(philix): use xstpcpy() in stuff_yank()
STRCAT(lp, p);
free(p);
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 */
- new_ptr = (char_u **)lalloc(
- (long_u)(sizeof(char_u *) *
- (curr->y_size + y_current->y_size)),
- TRUE);
+ new_ptr = xmalloc(sizeof(char_u *) * (curr->y_size + y_current->y_size));
for (j = 0; j < curr->y_size; ++j)
new_ptr[j] = curr->y_array[j];
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
* the new block, unless being Vi compatible. */
if (curr->y_type == MCHAR && vim_strchr(p_cpo, CPO_REGAPPEND) == NULL) {
- pnew = lalloc((long_u)(STRLEN(curr->y_array[curr->y_size - 1])
- + STRLEN(y_current->y_array[0]) + 1), TRUE);
+ pnew = xmalloc(STRLEN(curr->y_array[curr->y_size - 1])
+ + STRLEN(y_current->y_array[0]) + 1);
STRCPY(pnew, curr->y_array[--j]);
STRCAT(pnew, y_current->y_array[0]);
free(curr->y_array[j]);
@@ -4676,7 +4671,6 @@ get_reg_contents (
long i;
char_u *retval;
int allocated;
- long len;
/* Don't allow using an expression register inside an expression */
if (regname == '=') {
@@ -4711,9 +4705,9 @@ get_reg_contents (
/*
* Compute length of resulting string.
*/
- len = 0;
+ size_t len = 0;
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
* y_type is MLINE.
@@ -4722,26 +4716,24 @@ get_reg_contents (
++len;
}
- retval = lalloc(len + 1, TRUE);
+ retval = xmalloc(len + 1);
/*
* Copy the lines of the yank register into the string.
*/
- if (retval != NULL) {
- len = 0;
- for (i = 0; i < y_current->y_size; ++i) {
- STRCPY(retval + len, y_current->y_array[i]);
- len += (long)STRLEN(retval + len);
+ len = 0;
+ for (i = 0; i < y_current->y_size; ++i) {
+ STRCPY(retval + len, y_current->y_array[i]);
+ len += STRLEN(retval + len);
- /*
- * Insert a NL between lines and after the last line if y_type is
- * MLINE.
- */
- if (y_current->y_type == MLINE || i < y_current->y_size - 1)
- retval[len++] = '\n';
- }
- retval[len] = NUL;
+ /*
+ * Insert a NL between lines and after the last line if y_type is
+ * MLINE.
+ */
+ if (y_current->y_type == MLINE || i < y_current->y_size - 1)
+ retval[len++] = '\n';
}
+ retval[len] = NUL;
return retval;
}
diff --git a/src/regexp.c b/src/regexp.c
index 73226065d8..35d8e30129 100644
--- a/src/regexp.c
+++ b/src/regexp.c
@@ -1184,7 +1184,6 @@ static void bt_regfree(regprog_T *prog);
*/
static regprog_T *bt_regcomp(char_u *expr, int re_flags)
{
- bt_regprog_T *r;
char_u *scan;
char_u *longest;
int len;
@@ -1211,7 +1210,7 @@ static regprog_T *bt_regcomp(char_u *expr, int re_flags)
#endif
/* 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.
@@ -6824,7 +6823,6 @@ char_u *reg_submatch(int no)
{
char_u *retval = NULL;
char_u *s;
- int len;
int round;
linenr_T lnum;
@@ -6832,6 +6830,8 @@ char_u *reg_submatch(int no)
return NULL;
if (submatch_match == NULL) {
+ ssize_t len;
+
/*
* First round: compute the length and allocate memory.
* Second round: copy the text.
@@ -6854,7 +6854,7 @@ char_u *reg_submatch(int no)
} else {
/* Multiple lines: take start line from start col, middle
* lines completely and end line up to end col. */
- len = (int)STRLEN(s);
+ len = STRLEN(s);
if (round == 2) {
STRCPY(retval, s);
retval[len] = '\n';
@@ -6865,7 +6865,7 @@ char_u *reg_submatch(int no)
s = reg_getline_submatch(lnum++);
if (round == 2)
STRCPY(retval + len, s);
- len += (int)STRLEN(s);
+ len += STRLEN(s);
if (round == 2)
retval[len] = '\n';
++len;
@@ -6880,7 +6880,7 @@ char_u *reg_submatch(int no)
}
if (retval == NULL) {
- retval = lalloc((long_u)len, TRUE);
+ retval = xmalloc(len);
}
}
} else {
diff --git a/src/regexp_nfa.c b/src/regexp_nfa.c
index 9d119a2bd3..0cd374d91f 100644
--- a/src/regexp_nfa.c
+++ b/src/regexp_nfa.c
@@ -2869,7 +2869,7 @@ static nfa_state_T *post2nfa(int *postfix, int *end, int nfa_calc_size)
if (nfa_calc_size == FALSE) {
/* 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;
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]
* values and clear them. */
if (*listids == NULL) {
- *listids = (int *)lalloc(sizeof(int) * nstate, TRUE);
+ *listids = xmalloc(sizeof(**listids) * nstate);
}
nfa_save_listids(prog, *listids);
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)
{
int result;
- int size = 0;
int flag = 0;
int go_to_nextline = FALSE;
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;
/* Allocate memory for the lists of nodes. */
- size = (nstate + 1) * sizeof(nfa_thread_T);
- list[0].t = (nfa_thread_T *)lalloc(size, TRUE);
+ size_t size = (nstate + 1) * sizeof(nfa_thread_T);
+ list[0].t = xmalloc(size);
list[0].len = nstate + 1;
- list[1].t = (nfa_thread_T *)lalloc(size, TRUE);
+ list[1].t = xmalloc(size);
list[1].len = nstate + 1;
#ifdef REGEXP_DEBUG
@@ -6231,7 +6230,6 @@ theend:
static regprog_T *nfa_regcomp(char_u *expr, int re_flags)
{
nfa_regprog_T *prog = NULL;
- size_t prog_size;
int *postfix;
if (expr == NULL)
@@ -6283,8 +6281,8 @@ static regprog_T *nfa_regcomp(char_u *expr, int re_flags)
post2nfa(postfix, post_ptr, TRUE);
/* allocate the regprog with space for the compiled regexp */
- prog_size = sizeof(nfa_regprog_T) + sizeof(nfa_state_T) * (nstate - 1);
- prog = (nfa_regprog_T *)lalloc(prog_size, TRUE);
+ size_t prog_size = sizeof(nfa_regprog_T) + sizeof(nfa_state_T) * (nstate - 1);
+ prog = xmalloc(prog_size);
state_ptr = prog->state;
/*
diff --git a/src/screen.c b/src/screen.c
index 794b35bef7..aa021c032e 100644
--- a/src/screen.c
+++ b/src/screen.c
@@ -288,23 +288,18 @@ int redraw_asap(int type)
/* Allocate space to save the text displayed in the command line area. */
rows = Rows - cmdline_row;
- screenline = (schar_T *)lalloc(
- (long_u)(rows * Columns * sizeof(schar_T)), FALSE);
- screenattr = (sattr_T *)lalloc(
- (long_u)(rows * Columns * sizeof(sattr_T)), FALSE);
+ screenline = xmalloc((size_t)(rows * Columns * sizeof(schar_T)));
+ screenattr = xmalloc((size_t)(rows * Columns * sizeof(sattr_T)));
if (enc_utf8) {
- screenlineUC = (u8char_T *)lalloc(
- (long_u)(rows * Columns * sizeof(u8char_T)), FALSE);
+ screenlineUC = xmalloc((size_t)(rows * Columns * sizeof(u8char_T)));
for (i = 0; i < p_mco; ++i) {
- screenlineC[i] = (u8char_T *)lalloc(
- (long_u)(rows * Columns * sizeof(u8char_T)), FALSE);
+ screenlineC[i] = xmalloc((size_t)(rows * Columns * sizeof(u8char_T)));
}
}
if (enc_dbcs == DBCS_JPNU) {
- screenline2 = (schar_T *)lalloc(
- (long_u)(rows * Columns * sizeof(schar_T)), FALSE);
+ screenline2 = xmalloc((size_t)(rows * Columns * sizeof(schar_T)));
}
/* Save the text displayed in the command line area. */
@@ -6258,24 +6253,21 @@ retry:
if (aucmd_win != NULL)
win_free_lsize(aucmd_win);
- new_ScreenLines = (schar_T *)lalloc((long_u)(
- (Rows + 1) * Columns * sizeof(schar_T)), FALSE);
+ new_ScreenLines = xmalloc((size_t)((Rows + 1) * Columns * sizeof(schar_T)));
memset(new_ScreenLinesC, 0, sizeof(u8char_T *) * MAX_MCO);
if (enc_utf8) {
- new_ScreenLinesUC = (u8char_T *)lalloc((long_u)(
- (Rows + 1) * Columns * sizeof(u8char_T)), FALSE);
+ new_ScreenLinesUC = xmalloc(
+ (size_t)((Rows + 1) * Columns * sizeof(u8char_T)));
for (i = 0; i < p_mco; ++i)
new_ScreenLinesC[i] = xcalloc((Rows + 1) * Columns, sizeof(u8char_T));
}
if (enc_dbcs == DBCS_JPNU)
- new_ScreenLines2 = (schar_T *)lalloc((long_u)(
- (Rows + 1) * Columns * sizeof(schar_T)), FALSE);
- new_ScreenAttrs = (sattr_T *)lalloc((long_u)(
- (Rows + 1) * Columns * sizeof(sattr_T)), FALSE);
- new_LineOffset = (unsigned *)lalloc((long_u)(
- Rows * sizeof(unsigned)), FALSE);
- new_LineWraps = (char_u *)lalloc((long_u)(Rows * sizeof(char_u)), FALSE);
- new_TabPageIdxs = (short *)lalloc((long_u)(Columns * sizeof(short)), FALSE);
+ new_ScreenLines2 = xmalloc(
+ (size_t)((Rows + 1) * Columns * sizeof(schar_T)));
+ new_ScreenAttrs = xmalloc((size_t)((Rows + 1) * Columns * sizeof(sattr_T)));
+ new_LineOffset = xmalloc((size_t)(Rows * sizeof(unsigned)));
+ new_LineWraps = xmalloc((size_t)(Rows * sizeof(char_u)));
+ new_TabPageIdxs = xmalloc((size_t)(Columns * sizeof(short)));
FOR_ALL_TAB_WINDOWS(tp, wp)
{
diff --git a/src/search.c b/src/search.c
index 3d153c433c..891db71549 100644
--- a/src/search.c
+++ b/src/search.c
@@ -4195,8 +4195,7 @@ find_pattern_in_path (
if (new_fname != NULL) {
/* Push the new file onto the file stack */
if (depth + 1 == old_files) {
- bigger = (SearchedFile *)lalloc((long_u)(
- max_path_depth * 2 * sizeof(SearchedFile)), TRUE);
+ bigger = xmalloc(max_path_depth * 2 * sizeof(SearchedFile));
for (i = 0; i <= depth; i++)
bigger[i] = files[i];
for (i = depth + 1; i < old_files + max_path_depth; i++) {
@@ -4217,10 +4216,8 @@ find_pattern_in_path (
free(new_fname);
else {
if (++depth == old_files) {
- /*
- * lalloc() for 'bigger' must have failed above. We
- * will forget one of our already visited files now.
- */
+ // Something wrong. We will forget one of our already visited files
+ // now.
free(files[old_files].name);
++old_files;
}
diff --git a/src/spell.c b/src/spell.c
index f06a1ccd04..5ee799ebf1 100644
--- a/src/spell.c
+++ b/src/spell.c
@@ -3493,19 +3493,18 @@ spell_read_tree (
int prefixcnt // when "prefixtree" is TRUE: prefix count
)
{
- int len;
int idx;
char_u *bp;
idx_T *ip;
// The tree size was computed when writing the file, so that we can
// allocate it as one long block. <nodecount>
- len = get4c(fd);
+ int len = get4c(fd);
if (len < 0)
return SP_TRUNCERROR;
if (len > 0) {
// Allocate the byte array.
- bp = lalloc((long_u)len, TRUE);
+ bp = xmalloc(len);
*bytsp = bp;
// 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).
#define CNT(a, b) cnt[(a) + (b) * (badlen + 1)]
- cnt = (int *)lalloc((long_u)(sizeof(int) * (badlen + 1) * (goodlen + 1)),
- TRUE);
+ cnt = xmalloc(sizeof(int) * (badlen + 1) * (goodlen + 1));
CNT(0, 0) = 0;
for (j = 1; j <= goodlen; ++j)
diff --git a/src/tag.c b/src/tag.c
index 4d287c4440..d97eb61ab4 100644
--- a/src/tag.c
+++ b/src/tag.c
@@ -1990,8 +1990,7 @@ findtag_end:
match_count = 0;
if (match_count > 0)
- matches = (char_u **)lalloc((long_u)(match_count * sizeof(char_u *)),
- TRUE);
+ matches = xmalloc(match_count * sizeof(char_u *));
else
matches = NULL;
match_count = 0;
diff --git a/src/undo.c b/src/undo.c
index 660fe83fdd..a17ba50255 100644
--- a/src/undo.c
+++ b/src/undo.c
@@ -135,7 +135,6 @@ static void serialize_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);
-#define U_ALLOC_LINE(size) lalloc((long_u)(size), FALSE)
static char_u *u_save_line(linenr_T);
/* 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
* 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
uhp->uh_magic = UH_MAGIC;
#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
*/
- uep = (u_entry_T *)U_ALLOC_LINE(sizeof(u_entry_T));
+ uep = xmalloc(sizeof(u_entry_T));
memset(uep, 0, sizeof(u_entry_T));
#ifdef U_DEBUG
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) {
- 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) {
fast_breakcheck();
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)
copy = small_buf; /* no malloc()/free() for short strings */
else {
- copy = lalloc(len, FALSE);
+ copy = xmalloc(len);
}
crypt_encode(ptr, len, copy);
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 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));
#ifdef U_DEBUG
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;
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));
#ifdef U_DEBUG
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_size = get4c(fp);
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);
} else
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.
* When there are no headers uhp_table is NULL. */
if (num_head > 0) {
- uhp_table = (u_header_T **)U_ALLOC_LINE(
- num_head * sizeof(u_header_T *));
+ uhp_table = xmalloc(num_head * sizeof(u_header_T *));
}
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 */
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 */
for (lnum = bot - 1, i = oldsize; --i >= 0; --lnum) {
/* what can we do when we run out of memory? */