]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: fix long options with arguments in gcore-1.in and gstack-1.in
authorSimon Marchi <simon.marchi@efficios.com>
Fri, 19 Sep 2025 20:44:13 +0000 (16:44 -0400)
committerSimon Marchi <simon.marchi@polymtl.ca>
Sat, 20 Sep 2025 00:28:57 +0000 (20:28 -0400)
Shellcheck 0.11.0 produces the same warning for gcore-1.in and
gstack-1.in:

In gcore-1.in line 74:
        OPTARG="${OPTARG#'$OPT'}"
                         ^----^ SC2016 (info): Expressions don't expand in single quotes, use double quotes for that.

In gstack-1.in line 67:
        OPTARG="${OPTARG#$OPT}"
                         ^--^ SC2295 (info): Expansions inside ${..} need to be quoted separately, otherwise they match as patterns.

The code in question exists to handle long option with arguments by
hand, like `--foo=bar`, since that is not supported natively by getopts.

At that line, OPTARG would contain `foo=bar`, OPT would contain `foo`,
and we're trying to strip `$OPT` from the beginning of `$OPTARG`.  For
this to work, OPT needs to be expanded, and therefore needs double
quotes (or no quotes at all, but then shellcheck complains).

This bug is harmless right now because we don't use long options with
arguments.  I tested this by temporarily making gcore support
-o|--output:

        o | output)
            prefix=$OPTARG
            ;;

And verified that this works:

    $ ./gcore --output=salut 51286
    ...
    Saved corefile salut.51286
    ...

Change-Id: I025be574699d67b18ada9d73ce8f2aa0c87d5a0d
Reviewed-By: Sébastien Darche <sdarche@efficios.com>
Reviewed-By: Keith Seitz <keiths@redhat.com>
gdb/gcore-1.in
gdb/gstack-1.in

index d733682704d0c1520280f0c6c3af64836032ab8e..c8da3c6d3ac65e646bda54a331729c3e78f237f3 100755 (executable)
@@ -71,7 +71,7 @@ function print_version() {
 while getopts vhao:g:d:-: OPT; do
     if [ "$OPT" = "-" ]; then
        OPT="${OPTARG%%=*}"
-       OPTARG="${OPTARG#'$OPT'}"
+       OPTARG="${OPTARG#"$OPT"}"
        OPTARG="${OPTARG#=}"
     fi
 
index 25339d9877d9916341c9b2252f35b77a60f307ee..f2ed6b804c9f91e14061a93e4f8dd41a86bd97bf 100755 (executable)
@@ -64,7 +64,7 @@ function print_version() {
 while getopts hv-: OPT; do
     if [ "$OPT" = "-" ]; then
        OPT="${OPTARG%%=*}"
-       OPTARG="${OPTARG#'$OPT'}"
+       OPTARG="${OPTARG#"$OPT"}"
        OPTARG="${OPTARG#=}"
     fi