Skip to content

Commit

Permalink
Remove duplicate update of iter in Perl_hv_iternext_flags().
Browse files Browse the repository at this point in the history
Because`iter` points to a structure immediately after of HvARRAY(), it needs
updating if HvARRAY() has moved because it has been expanded.

Code was added for VMS in Aug 2005 to address a specific instance of this
bug with commit 03026e6:
    [patch@25334] hv.c vms environment fix.
    From: "John E. Malmberg" <wb8tyw@qsl.net>
    Message-ID: <4310F552.8050401@qsl.net>

see https://www.nntp.perl.org/group/perl.perl5.porters/2005/08/msg104261.html

However, this code was duplicated by and hence made redundant with a more
general fix added in March 2014 by commit 339441e:
    make core safe against HvAUX() realloc

    Since the HvAUX structure is just tacked onto the end of the HvARRAY()
    struct, code like this can do bad things:

        aux = HvAUX();
        ... something that might split hv ...
        aux->foo = ...; /* SEGV! */

    So I've visually audited core for places where HbAUX() is saved and then
    re-used, and re-initialised the var if it looks like HvARRAY() could
    have changed in the meantime.

    I've been very conservative about what might be unsafe. For example,
    destructors or __WARN__ handlers could call perl code that modifies the
    hash.

Hence remove the redundant code.
  • Loading branch information
nwc10 committed Sep 8, 2021
1 parent 0ae3a5c commit 926f084
Showing 1 changed file with 0 additions and 8 deletions.
8 changes: 0 additions & 8 deletions hv.c
Expand Up @@ -2737,14 +2737,6 @@ Perl_hv_iternext_flags(pTHX_ HV *hv, I32 flags)
if (!entry && SvRMAGICAL((const SV *)hv)
&& mg_find((const SV *)hv, PERL_MAGIC_env)) {
prime_env_iter();
#ifdef VMS
/* The prime_env_iter() on VMS just loaded up new hash values
* so the iteration count needs to be reset back to the beginning
*/
hv_iterinit(hv);
iter = HvAUX(hv);
oldentry = entry = iter->xhv_eiter; /* HvEITER(hv) */
#endif
}
#endif

Expand Down

0 comments on commit 926f084

Please sign in to comment.