summaryrefslogtreecommitdiff
path: root/util.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 /util.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 'util.c')
-rw-r--r--util.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/util.c b/util.c
index bd568bc22a..b324af43ed 100644
--- a/util.c
+++ b/util.c
@@ -5352,9 +5352,11 @@ Perl_my_cxt_init(pTHX_ int *index, size_t size)
/* make sure the array is big enough */
if (PL_my_cxt_size <= *index) {
if (PL_my_cxt_size) {
- while (PL_my_cxt_size <= *index)
- PL_my_cxt_size *= 2;
- Renew(PL_my_cxt_list, PL_my_cxt_size, void *);
+ IV new_size = PL_my_cxt_size;
+ while (new_size <= *index)
+ new_size *= 2;
+ Renew(PL_my_cxt_list, new_size, void *);
+ PL_my_cxt_size = new_size;
}
else {
PL_my_cxt_size = 16;
@@ -5415,10 +5417,12 @@ Perl_my_cxt_init(pTHX_ const char *my_cxt_key, size_t size)
int old_size = PL_my_cxt_size;
int i;
if (PL_my_cxt_size) {
- while (PL_my_cxt_size <= index)
- PL_my_cxt_size *= 2;
- Renew(PL_my_cxt_list, PL_my_cxt_size, void *);
- Renew(PL_my_cxt_keys, PL_my_cxt_size, const char *);
+ IV new_size = PL_my_cxt_size;
+ while (new_size <= index)
+ new_size *= 2;
+ Renew(PL_my_cxt_list, new_size, void *);
+ Renew(PL_my_cxt_keys, new_size, const char *);
+ PL_my_cxt_size = new_size;
}
else {
PL_my_cxt_size = 16;