Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #14402

Re: segfault w/ localvar_inherit and associative array insert

From Grisha Levit <grishalevit@gmail.com>
Newsgroups gnu.bash.bug
Subject Re: segfault w/ localvar_inherit and associative array insert
Date 2018-07-26 15:15 -0400
Message-ID <mailman.4276.1532632548.1292.bug-bash@gnu.org> (permalink)
References <CAMu=BroMwXaqDTT3qusycRGRdXevmxiwC0RpR8+wGooo83pWgg@mail.gmail.com> <2e51ae31-5fb0-633b-6d7b-faab8df39585@case.edu>

Show all headers | View raw


It seems that in general the array type is inherited just fine, there is an
issue only in the case that:
   * the `A' attribute is inherited but not explicitly supplied
   * we are creating the local variable with the `declare' command
     (i.e. it is not already an existing local variable)
   * we are performing a compound assignment/append operation in the
     same declare command

For example, given:

    shopt -s localvar_inherit
    declare -A var=([X]=X)

These all work smoothly:

    ## no explicit `-A', no assignment in `declare':

    f() { declare var; declare -p var; }; f
    # declare -A var=([X]="X" )

    f() { declare var; var=([Y]=Y); declare -p var; }; f
    # declare -A var=([Y]="Y" )

    f() { declare var; var+=([Y]=Y); declare -p var; }; f
    # declare -A var=([X]="X" [Y]="Y" )

    ## explicit `-A', assignment in `declare':

    f() { declare -A var=([Y]=Y); declare -p var; }; f
    # declare -A var=([Y]="Y" )

    f() { declare -A var+=([Y]=Y); declare -p var; }; f
    # declare -A var=([X]="X" [Y]="Y" )

    ## non-compound assignment:

    f() { declare var[Y]=Y; declare -p var; }; f
    declare -A var=([X]="X" [Y]="Y" )

But here we have some issues:

    ## no explicit `-A', assignment in `declare':

    f() { declare var=([Y]=Y); declare -p var; }; f
    # Segmentation fault: 11

    f() { declare var+=([Y]=Y); declare -p var; }; f
    # Segmentation fault: 11

    f() { declare var+=(); declare -p var; }; f
    # declare -aA var=()

    f() { declare var=(); declare -p var; }; f
    declare -aA var=()

Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread


Thread

Re: segfault w/ localvar_inherit and associative array insert Grisha Levit <grishalevit@gmail.com> - 2018-07-26 15:15 -0400

csiph-web