Skip to content

Commit

Permalink
additional fix for #24
Browse files Browse the repository at this point in the history
Use xalloca() to allocate a stack.
(cherry picked from commit a0efc0a)
  • Loading branch information
k-takata committed Apr 12, 2014
1 parent c5908bc commit cd2f04c
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions regexec.c
Original file line number Diff line number Diff line change
Expand Up @@ -401,15 +401,19 @@ onig_region_copy(OnigRegion* to, OnigRegion* from)

#define STACK_INIT(alloc_addr, heap_addr, ptr_num, stack_num) do {\
if (ptr_num > MAX_PTR_NUM) {\
if (msa->stack_p) xfree(msa->stack_p);\
alloc_addr = (char* )xmalloc(sizeof(OnigStackIndex) * (ptr_num));\
heap_addr = alloc_addr;\
stk_alloc = NULL;\
stk_base = (OnigStackType* )xmalloc(sizeof(OnigStackIndex) * (stack_num));\
stk = stk_base;\
stk_end = stk_base + (stack_num);\
msa->stack_p = stk_base;\
msa->stack_n = stk_end - stk_base;\
if (msa->stack_p) {\
stk_alloc = (OnigStackType* )(msa->stack_p);\
stk_base = stk_alloc;\
stk = stk_base;\
stk_end = stk_base + msa->stack_n;\
} else {\
stk_alloc = (OnigStackType* )xalloca(sizeof(OnigStackType) * (stack_num));\
stk_base = stk_alloc;\
stk = stk_base;\
stk_end = stk_base + (stack_num);\
}\
} else if (msa->stack_p) {\
alloc_addr = (char* )xalloca(sizeof(OnigStackIndex) * (ptr_num));\
heap_addr = NULL;\
Expand Down

0 comments on commit cd2f04c

Please sign in to comment.