package bash
tags 345861 + patch
thankyou

Hi,

it turned out to be a one-liner. The first part of
subst.c:parameter_brace_expand() contains an if-block that is to take care of
some "special cases" like ${!VAR}, $# and even things like ${!#}...  but it is
also entered for plain length expansions like ${#VAR}:

]  5795   sindex = *indexp;
]  5796   t_index = ++sindex;
]  5797   name = string_extract (string, &t_index, "#%:-=?+/}", EX_VARNAME);
]  5798 
]  5799   ret = 0;
]  5800   tflag = 0;
]  5801 
]  5802   /* If the name really consists of a special variable, then make sure
]  5803      that we have the entire name.  We don't allow indirect references
]  5804      to special variables except `#', `?', `@' and `*'. */
]  5805   if ((sindex == t_index &&
]  5806         (string[t_index] == '-' ||
]  5807          string[t_index] == '?' ||
]  5808          string[t_index] == '#')) ||
]  5809       (sindex == t_index - 1 && string[sindex] == '!' &&
]  5810         (string[t_index] == '#' ||
]  5811          string[t_index] == '?' ||
]  5812          string[t_index] == '@' ||
]  5813          string[t_index] == '*')))
]  5814     {
]  5815       t_index++;
]  5816       free (name);
]  5817       temp1 = string_extract (string, &t_index, "#%:-=?+/}", 0);
]  5818       name = (char *)xmalloc (3 + (strlen (temp1)));
]  5819       *name = string[sindex];
]  5820       if (string[sindex] == '!')
]  5821         {
]  5822           /* indirect reference of $#, $?, $@, or $* */
]  5823           name[1] = string[sindex + 1];
]  5824           strcpy (name + 2, temp1);
]  5825         }
]  5826       else      
]  5827         strcpy (name + 1, temp1);
]  5828       free (temp1);
]  5829     }

In my problem case above, while trying to expand ${#LOGNAME[$(( 0+0 ))]}:

] 5797: name = ""                // first character is '#'
] [...]
] 5817: temp1 = "LOGNAME[$(( 0"  // '+' is in the delimiter list

I've changed the fourth parameter in 5817 to EX_VARNAME, so everything inside []
is skipped - this is already done in 5797, and I can see no reason why it
shouldn't be there in 5817 (at least I can see no harm arising from having
it there).

Diff and dpatch attached, has already been tested locally (no obvious
regressions, and fixes my bug).


HTH,

Jan

-- 
Jan C. Nordholz
<jckn At gmx net>
--- ../bash-3.1/subst.c     2006-01-14 01:12:02.000000000 +0100
+++ subst.c     2006-01-14 01:12:39.000000000 +0100
@@ -5814,7 +5814,7 @@
     {
       t_index++;
       free (name);
-      temp1 = string_extract (string, &t_index, "#%:-=?+/}", 0);
+      temp1 = string_extract (string, &t_index, "#%:-=?+/}", EX_VARNAME);
       name = (char *)xmalloc (3 + (strlen (temp1)));
       *name = string[sindex];
       if (string[sindex] == '!')
#! /bin/sh -e

if [ $# -eq 3 -a "$2" = '-d' ]; then
    pdir="-d $3"
elif [ $# -ne 1 ]; then
    echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
    exit 1
fi
case "$1" in
    -patch) patch $pdir -f --no-backup-if-mismatch -p0 < $0;;
    -unpatch) patch $pdir -f --no-backup-if-mismatch -R -p0 < $0;;
    *)
        echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
        exit 1
esac
exit 0

DP: ignore array subscript while determining variable name for length
DP: substitution
DP: (#345861)

--- ../bash-3.1/subst.c     2006-01-14 01:12:02.000000000 +0100
+++ subst.c     2006-01-14 01:12:39.000000000 +0100
@@ -5814,7 +5814,7 @@
     {
       t_index++;
       free (name);
-      temp1 = string_extract (string, &t_index, "#%:-=?+/}", 0);
+      temp1 = string_extract (string, &t_index, "#%:-=?+/}", EX_VARNAME);
       name = (char *)xmalloc (3 + (strlen (temp1)));
       *name = string[sindex];
       if (string[sindex] == '!')

Attachment: signature.asc
Description: Digital signature

Reply via email to