This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Avoid undefined behaviour for -DPERL_MEM_LOG by not using a direct
authorNicholas Clark <nick@ccl4.org>
Sat, 14 Oct 2006 22:40:00 +0000 (22:40 +0000)
committerNicholas Clark <nick@ccl4.org>
Sat, 14 Oct 2006 22:40:00 +0000 (22:40 +0000)
dereference of member of the structure being reallocated as part of
the size calculation. (There may be other similar bugs).

p4raw-id: //depot/perl@29016

regcomp.c

index 89ce420..7661432 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -3629,10 +3629,11 @@ STATIC I32
 S_add_data(RExC_state_t *pRExC_state, I32 n, const char *s)
 {
     if (RExC_rx->data) {
 S_add_data(RExC_state_t *pRExC_state, I32 n, const char *s)
 {
     if (RExC_rx->data) {
+       const U32 count = RExC_rx->data->count;
        Renewc(RExC_rx->data,
        Renewc(RExC_rx->data,
-              sizeof(*RExC_rx->data) + sizeof(void*) * (RExC_rx->data->count + n - 1),
+              sizeof(*RExC_rx->data) + sizeof(void*) * (count + n - 1),
               char, struct reg_data);
               char, struct reg_data);
-       Renew(RExC_rx->data->what, RExC_rx->data->count + n, U8);
+       Renew(RExC_rx->data->what, count + n, U8);
        RExC_rx->data->count += n;
     }
     else {
        RExC_rx->data->count += n;
     }
     else {