comparison 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
comparison
equal deleted inserted replaced
16824:1f6bb29738d2 16825:ce04ebdf26b8
298 nstate_max += 1000; 298 nstate_max += 1000;
299 299
300 /* Size for postfix representation of expr. */ 300 /* Size for postfix representation of expr. */
301 postfix_size = sizeof(int) * nstate_max; 301 postfix_size = sizeof(int) * nstate_max;
302 302
303 post_start = (int *)alloc(postfix_size); 303 post_start = alloc(postfix_size);
304 if (post_start == NULL) 304 if (post_start == NULL)
305 return FAIL; 305 return FAIL;
306 post_ptr = post_start; 306 post_ptr = post_start;
307 post_end = post_start + nstate_max; 307 post_end = post_start + nstate_max;
308 rex.nfa_has_zend = FALSE; 308 rex.nfa_has_zend = FALSE;
514 int *old_start; 514 int *old_start;
515 515
516 // For weird patterns the number of states can be very high. Increasing by 516 // For weird patterns the number of states can be very high. Increasing by
517 // 50% seems a reasonable compromise between memory use and speed. 517 // 50% seems a reasonable compromise between memory use and speed.
518 new_max = nstate_max * 3 / 2; 518 new_max = nstate_max * 3 / 2;
519 new_start = (int *)alloc(new_max * sizeof(int)); 519 new_start = ALLOC_MULT(int, new_max);
520 if (new_start == NULL) 520 if (new_start == NULL)
521 return FAIL; 521 return FAIL;
522 mch_memmove(new_start, post_start, nstate_max * sizeof(int)); 522 mch_memmove(new_start, post_start, nstate_max * sizeof(int));
523 old_start = post_start; 523 old_start = post_start;
524 post_start = new_start; 524 post_start = new_start;
3212 } 3212 }
3213 3213
3214 if (nfa_calc_size == FALSE) 3214 if (nfa_calc_size == FALSE)
3215 { 3215 {
3216 // Allocate space for the stack. Max states on the stack: "nstate'. 3216 // Allocate space for the stack. Max states on the stack: "nstate'.
3217 stack = (Frag_T *)alloc((nstate + 1) * sizeof(Frag_T)); 3217 stack = ALLOC_MULT(Frag_T, nstate + 1);
3218 if (stack == NULL) 3218 if (stack == NULL)
3219 return NULL; 3219 return NULL;
3220 stackp = stack; 3220 stackp = stack;
3221 stack_end = stack + (nstate + 1); 3221 stack_end = stack + (nstate + 1);
3222 } 3222 }
4797 if ((long)(newsize >> 10) >= p_mmp) 4797 if ((long)(newsize >> 10) >= p_mmp)
4798 { 4798 {
4799 emsg(_(e_maxmempat)); 4799 emsg(_(e_maxmempat));
4800 return NULL; 4800 return NULL;
4801 } 4801 }
4802 newl = (nfa_thread_T *)alloc(newsize); 4802 newl = alloc(newsize);
4803 if (newl == NULL) 4803 if (newl == NULL)
4804 return NULL; 4804 return NULL;
4805 l->len = newlen; 4805 l->len = newlen;
4806 mch_memmove(&(newl[0]), 4806 mch_memmove(&(newl[0]),
4807 &(l->t[0]), 4807 &(l->t[0]),
5182 /* Already calling nfa_regmatch() recursively. Save the lastlist[1] 5182 /* Already calling nfa_regmatch() recursively. Save the lastlist[1]
5183 * values and clear them. */ 5183 * values and clear them. */
5184 if (*listids == NULL || *listids_len < prog->nstate) 5184 if (*listids == NULL || *listids_len < prog->nstate)
5185 { 5185 {
5186 vim_free(*listids); 5186 vim_free(*listids);
5187 *listids = (int *)alloc(sizeof(int) * prog->nstate); 5187 *listids = ALLOC_MULT(int, prog->nstate);
5188 if (*listids == NULL) 5188 if (*listids == NULL)
5189 { 5189 {
5190 emsg(_("E878: (NFA) Could not allocate memory for branch traversal!")); 5190 emsg(_("E878: (NFA) Could not allocate memory for branch traversal!"));
5191 return 0; 5191 return 0;
5192 } 5192 }
5565 nfa_match = FALSE; 5565 nfa_match = FALSE;
5566 5566
5567 /* Allocate memory for the lists of nodes. */ 5567 /* Allocate memory for the lists of nodes. */
5568 size = (prog->nstate + 1) * sizeof(nfa_thread_T); 5568 size = (prog->nstate + 1) * sizeof(nfa_thread_T);
5569 5569
5570 list[0].t = (nfa_thread_T *)alloc(size); 5570 list[0].t = alloc(size);
5571 list[0].len = prog->nstate + 1; 5571 list[0].len = prog->nstate + 1;
5572 list[1].t = (nfa_thread_T *)alloc(size); 5572 list[1].t = alloc(size);
5573 list[1].len = prog->nstate + 1; 5573 list[1].len = prog->nstate + 1;
5574 if (list[0].t == NULL || list[1].t == NULL) 5574 if (list[0].t == NULL || list[1].t == NULL)
5575 goto theend; 5575 goto theend;
5576 5576
5577 #ifdef ENABLE_LOG 5577 #ifdef ENABLE_LOG
7274 */ 7274 */
7275 post2nfa(postfix, post_ptr, TRUE); 7275 post2nfa(postfix, post_ptr, TRUE);
7276 7276
7277 /* allocate the regprog with space for the compiled regexp */ 7277 /* allocate the regprog with space for the compiled regexp */
7278 prog_size = sizeof(nfa_regprog_T) + sizeof(nfa_state_T) * (nstate - 1); 7278 prog_size = sizeof(nfa_regprog_T) + sizeof(nfa_state_T) * (nstate - 1);
7279 prog = (nfa_regprog_T *)alloc(prog_size); 7279 prog = alloc(prog_size);
7280 if (prog == NULL) 7280 if (prog == NULL)
7281 goto fail; 7281 goto fail;
7282 state_ptr = prog->state; 7282 state_ptr = prog->state;
7283 prog->re_in_use = FALSE; 7283 prog->re_in_use = FALSE;
7284 7284