From: Simon Marchi Date: Fri, 19 Sep 2025 20:44:13 +0000 (-0400) Subject: gdb: fix long options with arguments in gcore-1.in and gstack-1.in X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5a60265e41769b7e1d176bda075738326c9ee2d8;p=thirdparty%2Fbinutils-gdb.git gdb: fix long options with arguments in gcore-1.in and gstack-1.in 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 Reviewed-By: Keith Seitz --- diff --git a/gdb/gcore-1.in b/gdb/gcore-1.in index d733682704d..c8da3c6d3ac 100755 --- a/gdb/gcore-1.in +++ b/gdb/gcore-1.in @@ -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 diff --git a/gdb/gstack-1.in b/gdb/gstack-1.in index 25339d9877d..f2ed6b804c9 100755 --- a/gdb/gstack-1.in +++ b/gdb/gstack-1.in @@ -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