From cc36db45aecb3c39cb5368c3cf2a1203a18daba7 Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Mon, 11 Jul 2011 22:02:41 -0400 Subject: ensure local scoping of variables Also make sure that simple variables are declared as null strings. Signed-off-by: Dave Reisner --- functions | 12 +++++++++--- mkinitcpio | 4 ++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/functions b/functions index 8eef5b8..eb1bf01 100644 --- a/functions +++ b/functions @@ -115,6 +115,8 @@ _add_symlink() { auto_modules() { # Perform auto detection of modules via sysfs. + local mods= + IFS=$'\n' read -rd '' -a mods < \ <(find /sys/devices -name modalias -exec sort -u {} + | # delimit each input by a newline, expanded in place @@ -130,6 +132,8 @@ all_modules() { # $@: filter arguments to grep local -i count=0 + local mod= + while read -r -d '' mod; do (( ++count )) mod=${mod##*/} @@ -158,7 +162,7 @@ add_module() { # discovered and added. # $1: module name - local module path dep deps field value + local module= path= dep= deps= field= value= local -i ign_errors=0 if [[ $1 = -@(t|-try) ]]; then @@ -214,6 +218,8 @@ add_full_dir() { # No parsing is performed and the contents of the directory is added as is. # $1: path to directory + local f= + if [[ -n $1 && -d $1 ]]; then for f in "$1"/*; do if [[ -d "$f" ]]; then @@ -278,7 +284,7 @@ add_binary() { # $2: destination on initcpio (optional, defaults to same as source) local -a sodeps - local regex binary dest mode sodep resolved dirname + local line= regex= binary= dest= mode= sodep= resolved= dirname= if [[ ${1:0:1} != '/' ]]; then binary=$(pathlookup "$1") @@ -322,7 +328,7 @@ parse_hook() { # prior to the start of hook processing, and after each hook's build # function is run. - local item + local item= for item in $MODULES; do if [[ ${item:(-1)} = '?' ]]; then diff --git a/mkinitcpio b/mkinitcpio index 49dabbd..82faaaf 100755 --- a/mkinitcpio +++ b/mkinitcpio @@ -21,7 +21,7 @@ INSTDIR=install PRESETDIR=mkinitcpio.d COMPRESSION=gzip -declare TMPDIR BASEDIR MODULE_FILE GENIMG PRESET COMPRESSION_OPTIONS BUILDROOT +declare TMPDIR= BASEDIR= MODULE_FILE= GENIMG= PRESET= COMPRESSION_OPTIONS= BUILDROOT= declare NC= BOLD= BLUE= GREEN= RED= YELLOW= declare -i QUIET=1 SHOW_AUTOMODS=0 SAVELIST=0 COLOR=1 declare -a SKIPHOOKS ADDED_MODULES MODPATHS @@ -74,7 +74,7 @@ cleanup () } get_kernver() { - local kernel=$1 + local kernver= kernel=$1 if [[ "${kernel:0:1}" != / ]]; then echo $kernel -- cgit v1.2.3-24-g4f1b