patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Problem: Alloc() returning "char_u *" causes a lot of type casts.
Solution: Have it return "void *". (Mike Williams) Define ALLOC_ONE() to
check the simple allocations.
diff --git a/src/regexp_nfa.c b/src/regexp_nfa.c
index cb9c801..0712f4e 100644
--- a/src/regexp_nfa.c
+++ b/src/regexp_nfa.c
@@ -300,7 +300,7 @@
/* Size for postfix representation of expr. */
postfix_size = sizeof(int) * nstate_max;
- post_start = (int *)alloc(postfix_size);
+ post_start = alloc(postfix_size);
if (post_start == NULL)
return FAIL;
post_ptr = post_start;
@@ -516,7 +516,7 @@
// For weird patterns the number of states can be very high. Increasing by
// 50% seems a reasonable compromise between memory use and speed.
new_max = nstate_max * 3 / 2;
- new_start = (int *)alloc(new_max * sizeof(int));
+ new_start = ALLOC_MULT(int, new_max);
if (new_start == NULL)
return FAIL;
mch_memmove(new_start, post_start, nstate_max * sizeof(int));
@@ -3214,7 +3214,7 @@
if (nfa_calc_size == FALSE)
{
// Allocate space for the stack. Max states on the stack: "nstate'.
- stack = (Frag_T *)alloc((nstate + 1) * sizeof(Frag_T));
+ stack = ALLOC_MULT(Frag_T, nstate + 1);
if (stack == NULL)
return NULL;
stackp = stack;
@@ -4799,7 +4799,7 @@
emsg(_(e_maxmempat));
return NULL;
}
- newl = (nfa_thread_T *)alloc(newsize);
+ newl = alloc(newsize);
if (newl == NULL)
return NULL;
l->len = newlen;
@@ -5184,7 +5184,7 @@
if (*listids == NULL || *listids_len < prog->nstate)
{
vim_free(*listids);
- *listids = (int *)alloc(sizeof(int) * prog->nstate);
+ *listids = ALLOC_MULT(int, prog->nstate);
if (*listids == NULL)
{
emsg(_("E878: (NFA) Could not allocate memory for branch traversal!"));
@@ -5567,9 +5567,9 @@
/* Allocate memory for the lists of nodes. */
size = (prog->nstate + 1) * sizeof(nfa_thread_T);
- list[0].t = (nfa_thread_T *)alloc(size);
+ list[0].t = alloc(size);
list[0].len = prog->nstate + 1;
- list[1].t = (nfa_thread_T *)alloc(size);
+ list[1].t = alloc(size);
list[1].len = prog->nstate + 1;
if (list[0].t == NULL || list[1].t == NULL)
goto theend;
@@ -7276,7 +7276,7 @@
/* 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 *)alloc(prog_size);
+ prog = alloc(prog_size);
if (prog == NULL)
goto fail;
state_ptr = prog->state;