summaryrefslogtreecommitdiff
path: root/regexec.c
diff options
context:
space:
mode:
Diffstat (limited to 'regexec.c')
-rw-r--r--regexec.c48
1 files changed, 28 insertions, 20 deletions
diff --git a/regexec.c b/regexec.c
index 47fd67140e..b9947d8f93 100644
--- a/regexec.c
+++ b/regexec.c
@@ -178,16 +178,34 @@ onig_region_resize(OnigRegion* region, int n)
if (region->allocated == 0) {
region->beg = (int* )xmalloc(n * sizeof(int));
- region->end = (int* )xmalloc(n * sizeof(int));
+ if (region->beg == 0)
+ return ONIGERR_MEMORY;
- if (region->beg == 0 || region->end == 0)
+ region->end = (int* )xmalloc(n * sizeof(int));
+ if (region->end == 0) {
+ xfree(region->beg);
return ONIGERR_MEMORY;
+ }
region->allocated = n;
}
else if (region->allocated < n) {
- region->beg = (int* )xrealloc(region->beg, n * sizeof(int));
- region->end = (int* )xrealloc(region->end, n * sizeof(int));
+ int *tmp;
+
+ region->allocated = 0;
+ tmp = (int* )xrealloc(region->beg, n * sizeof(int));
+ if (tmp == 0) {
+ xfree(region->beg);
+ xfree(region->end);
+ return ONIGERR_MEMORY;
+ }
+ region->beg = tmp;
+ tmp = (int* )xrealloc(region->end, n * sizeof(int));
+ if (tmp == 0) {
+ xfree(region->beg);
+ return ONIGERR_MEMORY;
+ }
+ region->end = tmp;
if (region->beg == 0 || region->end == 0)
return ONIGERR_MEMORY;
@@ -240,7 +258,8 @@ onig_region_new(void)
OnigRegion* r;
r = (OnigRegion* )xmalloc(sizeof(OnigRegion));
- onig_region_init(r);
+ if (r)
+ onig_region_init(r);
return r;
}
@@ -268,19 +287,7 @@ onig_region_copy(OnigRegion* to, OnigRegion* from)
if (to == from) return;
- if (to->allocated == 0) {
- if (from->num_regs > 0) {
- to->beg = (int* )xmalloc(RREGC_SIZE);
- to->end = (int* )xmalloc(RREGC_SIZE);
- to->allocated = from->num_regs;
- }
- }
- else if (to->allocated < from->num_regs) {
- to->beg = (int* )xrealloc(to->beg, RREGC_SIZE);
- to->end = (int* )xrealloc(to->end, RREGC_SIZE);
- to->allocated = from->num_regs;
- }
-
+ onig_region_resize(to, from->num_regs);
for (i = 0; i < from->num_regs; i++) {
to->beg[i] = from->beg[i];
to->end[i] = from->end[i];
@@ -352,8 +359,10 @@ onig_region_copy(OnigRegion* to, OnigRegion* from)
unsigned int size = (unsigned int )(((str_len) + 1) * (state_num) + 7) >> 3;\
offset = ((offset) * (state_num)) >> 3;\
if (size > 0 && offset < size && size < STATE_CHECK_BUFF_MAX_SIZE) {\
- if (size >= STATE_CHECK_BUFF_MALLOC_THRESHOLD_SIZE) \
+ if (size >= STATE_CHECK_BUFF_MALLOC_THRESHOLD_SIZE) {\
(msa).state_check_buff = (void* )xmalloc(size);\
+ CHECK_NULL_RETURN_MEMERR((msa).state_check_buff);\
+ }\
else \
(msa).state_check_buff = (void* )xalloca(size);\
xmemset(((char* )((msa).state_check_buff)+(offset)), 0, \
@@ -378,7 +387,6 @@ onig_region_copy(OnigRegion* to, OnigRegion* from)
}\
} while(0)
#else
-#define STATE_CHECK_BUFF_INIT(msa, str_len, offset, state_num)
#define MATCH_ARG_FREE(msa) if ((msa).stack_p) xfree((msa).stack_p)
#endif