Skip to content

Commit 06461f3

Browse files
authored
4.4: Fix more pollution with global variables, improve handling of paths with whitespace (Trepan-Debuggers#47)
* Don't pollute global variables with "fullname" Also wraps the assigned value in quotes for better whitespace handling * Don't pollute global variables with "opt" * Don't pollute global variables with "prefix" Function declaration and call are on a single line because the line number is referenced by tests * Better handling of spaces in paths
1 parent d7877a9 commit 06461f3

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

bashdb-main.inc.in

+9-9
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,26 @@ typeset _Dbg_release='@PACKAGE_VERSION@'
2929
typeset _Dbg_bashdb_main='@DBGR_MAIN@'
3030

3131
# The short shell name. Helps keep code common in bash, zsh, and ksh debuggers.
32-
typeset _Dbg_shell_name=${_Dbg_shell##*/} # Equivalent to basename(_Dbg_shell)
32+
typeset _Dbg_shell_name="${_Dbg_shell##*/}" # Equivalent to basename(_Dbg_shell)
3333

3434
# Original $0. Note we can't set this in an include.
35-
typeset _Dbg_orig_0=$0
35+
typeset _Dbg_orig_0="$0"
3636

3737
# Equivalent to basename $0; the short program name
38-
typeset _Dbg_pname=${0##*/}
38+
typeset _Dbg_pname="${0##*/}"
3939

4040
## Stuff set by autoconf/configure ###
41-
typeset prefix=@prefix@ # @PKGDATADIR@ often uses $prefix
42-
typeset _Dbg_libdir=@PKGDATADIR@
41+
# @PKGDATADIR@ often uses $prefix, _Dbg_libdir must be a global variable
42+
_Dbg_assign_libdir() { typeset prefix="@prefix@"; _Dbg_libdir="@PKGDATADIR@"; }; _Dbg_assign_libdir
4343
###
4444

4545
# We agonize a bit over _Dbg_libdir: the root directory for where
4646
# debugger code is stored.
47-
[[ -d $_Dbg_libdir ]] || _Dbg_libdir=${_Dbg_bashdb_main%/*} # dirname(_Dbg_bashdb_main)
48-
[[ -d $_Dbg_libdir ]] || _Dbg_libdir='.'
47+
[[ -d "$_Dbg_libdir" ]] || _Dbg_libdir="${_Dbg_bashdb_main%/*}" # dirname(_Dbg_bashdb_main)
48+
[[ -d "$_Dbg_libdir" ]] || _Dbg_libdir='.'
4949

5050
typeset _Dbg_main="$_Dbg_libdir/dbg-main.sh"
51-
if [[ ! -r $_Dbg_main ]] ; then
51+
if [[ ! -r "$_Dbg_main" ]] ; then
5252
echo "${_Dbg_pname}: Can't read debugger library file '${_Dbg_main}'."
5353
echo "${_Dbg_pname}: Perhaps @PACKAGE@ is installed wrong (if its installed)." >&2
5454
echo "${_Dbg_pname}: Try running @PACKAGE@ using -L (with a different directory)." >&2
@@ -57,6 +57,6 @@ if [[ ! -r $_Dbg_main ]] ; then
5757
fi
5858

5959
# Pull in the rest of the debugger code.
60-
. $_Dbg_main
60+
. "$_Dbg_main"
6161

6262
trap '_Dbg_debug_trap_handler 0 "$BASH_COMMAND" "$@"' DEBUG

bashdb.in

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ typeset _Dbg_orig_0=$0
4949
typeset _Dbg_pname=${0##*/}
5050

5151
## Stuff set by autoconf/configure ###
52-
typeset prefix=@prefix@ # @PKGDATADIR@ often uses $prefix
53-
typeset _Dbg_libdir="@PKGDATADIR@"
52+
# @PKGDATADIR@ often uses $prefix, _Dbg_libdir must be a global variable
53+
_Dbg_assign_libdir() { typeset prefix="@prefix@"; _Dbg_libdir="@PKGDATADIR@"; }; _Dbg_assign_libdir
5454
###
5555

5656
# We agonize a bit over _Dbg_libdir: the root directory for where

command/info_sub/variables.sh

+1
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ function _Dbg_info_variables_parse_options {
142142

143143
typeset -i _Dbg_rc=0
144144
typeset OPTLIND=''
145+
typeset opt
145146
while getopts_long irxaAtp opt \
146147
integer no_argument \
147148
readonly no_argument \

lib/filecache.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,8 @@ function _Dbg_readin {
204204
if [[ -z "$filename" ]] || [[ "$filename" == "$_Dbg_bogus_file" ]] ; then
205205
eval "${_Dbg_source_array_var}[0]=\"$Dbg_EXECUTION_STRING\""
206206
else
207-
fullname=$(_Dbg_resolve_expand_filename "$filename")
207+
typeset fullname
208+
fullname="$(_Dbg_resolve_expand_filename "$filename")"
208209
if [[ -r "$fullname" ]] ; then
209210
typeset -r progress_prefix="Reading $filename"
210211
_Dbg_file2canonic["$filename"]="$fullname"

0 commit comments

Comments
 (0)