diff src/regexp_nfa.c @ 16825:ce04ebdf26b8 v8.1.1414

patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts commit https://github.com/vim/vim/commit/c799fe206e61f2e2c1231bc46cbe4bb354f3da69 Author: Bram Moolenaar <Bram@vim.org> Date: Tue May 28 23:08:19 2019 +0200 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.
author Bram Moolenaar <Bram@vim.org>
date Tue, 28 May 2019 23:15:10 +0200
parents fc58fee685e2
children 9e6d5a4abb1c
line wrap: on
line diff
--- a/src/regexp_nfa.c
+++ b/src/regexp_nfa.c
@@ -300,7 +300,7 @@ nfa_regcomp_start(
     /* 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 @@ realloc_post_list(void)
     // 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 @@ post2nfa(int *postfix, int *end, int nfa
     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 @@ addstate_here(
 		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 @@ recursive_regmatch(
 	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 @@ nfa_regmatch(
     /* 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 @@ nfa_regcomp(char_u *expr, int re_flags)
 
     /* 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;