summaryrefslogtreecommitdiff
path: root/scope.c
diff options
context:
space:
mode:
authorHugo van der Sanden <hv@crypt.org>2017-02-28 11:23:09 +0000
committerDavid Mitchell <davem@iabyn.com>2017-03-15 09:17:08 +0000
commit00195859c65eccf9425faf45db543a12c7ad3874 (patch)
treecd04c70326c16ed06553a6608564bd8237b888b6 /scope.c
parentacfc2cc32784cce84bd781bc3822b14406b94db2 (diff)
downloadperl-00195859c65eccf9425faf45db543a12c7ad3874.tar.gz
update size after Renew
RT #130841 In general code, change this idiom: PL_foo_max += size; Renew(PL_foo, PL_foo_max, foo_t); to Renew(PL_foo, PL_foo_max + size, foo_t); PL_foo_max += size; so that if Renew dies, PL_foo_max won't be left hanging.
Diffstat (limited to 'scope.c')
-rw-r--r--scope.c29
1 files changed, 17 insertions, 12 deletions
diff --git a/scope.c b/scope.c
index 4b302e7665..c51a125dfa 100644
--- a/scope.c
+++ b/scope.c
@@ -90,11 +90,12 @@ I32
Perl_cxinc(pTHX)
{
const IV old_max = cxstack_max;
- cxstack_max = GROW(cxstack_max);
- Renew(cxstack, cxstack_max + 1, PERL_CONTEXT);
+ const IV new_max = GROW(cxstack_max);
+ Renew(cxstack, new_max + 1, PERL_CONTEXT);
+ cxstack_max = new_max;
/* Without any kind of initialising deep enough recursion
* will end up reading uninitialised PERL_CONTEXTs. */
- PoisonNew(cxstack + old_max + 1, cxstack_max - old_max, PERL_CONTEXT);
+ PoisonNew(cxstack + old_max + 1, new_max - old_max, PERL_CONTEXT);
return cxstack_ix + 1;
}
@@ -102,11 +103,12 @@ void
Perl_push_scope(pTHX)
{
if (UNLIKELY(PL_scopestack_ix == PL_scopestack_max)) {
- PL_scopestack_max = GROW(PL_scopestack_max);
- Renew(PL_scopestack, PL_scopestack_max, I32);
+ const IV new_max = GROW(PL_scopestack_max);
+ Renew(PL_scopestack, new_max, I32);
#ifdef DEBUGGING
- Renew(PL_scopestack_name, PL_scopestack_max, const char*);
+ Renew(PL_scopestack_name, new_max, const char*);
#endif
+ PL_scopestack_max = new_max;
}
#ifdef DEBUGGING
PL_scopestack_name[PL_scopestack_ix] = "unknown";
@@ -140,23 +142,26 @@ Perl_markstack_grow(pTHX)
void
Perl_savestack_grow(pTHX)
{
+ IV new_max;
#ifdef STRESS_REALLOC
- PL_savestack_max += SS_MAXPUSH;
+ new_max = PL_savestack_max + SS_MAXPUSH;
#else
- PL_savestack_max = GROW(PL_savestack_max);
+ new_max = GROW(PL_savestack_max);
#endif
/* Note that we allocate SS_MAXPUSH slots higher than ss_max
* so that SS_ADD_END(), SSGROW() etc can do a simper check */
- Renew(PL_savestack, PL_savestack_max + SS_MAXPUSH, ANY);
+ Renew(PL_savestack, new_max + SS_MAXPUSH, ANY);
+ PL_savestack_max = new_max;
}
void
Perl_savestack_grow_cnt(pTHX_ I32 need)
{
- PL_savestack_max = PL_savestack_ix + need;
+ const IV new_max = PL_savestack_ix + need;
/* Note that we allocate SS_MAXPUSH slots higher than ss_max
* so that SS_ADD_END(), SSGROW() etc can do a simper check */
- Renew(PL_savestack, PL_savestack_max + SS_MAXPUSH, ANY);
+ Renew(PL_savestack, new_max + SS_MAXPUSH, ANY);
+ PL_savestack_max = new_max;
}
#undef GROW
@@ -186,8 +191,8 @@ Perl_tmps_grow_p(pTHX_ SSize_t ix)
if (ix - PL_tmps_max < 128)
extend_to += (PL_tmps_max < 512) ? 128 : 512;
#endif
+ Renew(PL_tmps_stack, extend_to + 1, SV*);
PL_tmps_max = extend_to + 1;
- Renew(PL_tmps_stack, PL_tmps_max, SV*);
return ix;
}