More fixes identified by the Frink static analyser:
authorBen Elliston <bje@gnu.org>
Mon, 28 Mar 2016 23:52:29 +0000 (10:52 +1100)
committerBen Elliston <bje@gnu.org>
Mon, 28 Mar 2016 23:52:29 +0000 (10:52 +1100)
  (1) use -- in switch commands for safety,
  (2) add braces around exprs,
  (3) replace abbreviated "info proc" with "info procs",
  (4) use -- in regexp commands for safety where the expression is a
      variable that could begin with '-'.

ChangeLog
baseboards/androideabi.exp
baseboards/basic-sid.exp
baseboards/multi-sim.exp
config/adb.exp
config/vxworks.exp
lib/dg.exp
runtest.exp

index dbe5e26..d85a111 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2016-03-29  Ben Elliston  <bje@gnu.org>
+
+       * runtest.exp: More fixes identified by the Frink static analyser.
+       * lib/dg.exp: Likewise.
+       * config/adb.exp: Likewise.
+       * config/vxworks.exp: Likewise.
+       * baseboards/androideabi.exp: Likewise.
+       * baseboards/basic-sid.exp: Likewise.
+       * baseboards/multi-sim.exp: Likewise.
+
 2016-03-28  Dominik Vogt  <vogt@linux.vnet.ibm.com>
 
        * dg.exp (dg-do): Do not change the previously selected action if
index e84d150..aeadcde 100644 (file)
@@ -55,14 +55,14 @@ proc adb_load { dest prog args } {
        set inp ""
     }
 
-    if ![file exists $prog] then {
+    if {![file exists $prog]} then {
        # We call both here because this should never happen.
        perror "$prog does not exist in standard_load."
        verbose -log "$prog does not exist." 3
        return "untested"
     }
 
-    if [is_remote $dest] {
+    if {[is_remote $dest]} {
        set localfile "./[file tail $prog].[pid]"
        set remotefile "$android_tmp_dir/[file tail $prog].[pid]"
        set remotefile [remote_download $dest $prog $remotefile]
@@ -79,8 +79,8 @@ proc adb_load { dest prog args } {
                return "unresolved"
            }
        }
-       if [board_info $dest exists remote_link] {
-           if [[board_info $dest remote_link] $remotefile] {
+       if {[board_info $dest exists remote_link]} {
+           if {[[board_info $dest remote_link] $remotefile]} {
                verbose -log "Couldn't do remote link"
                # Can't use remote_file delete since /system/bin/rm does not
                # support -f on Android.
@@ -101,7 +101,7 @@ proc adb_load { dest prog args } {
     set status [lindex $status 0]
 
     verbose -log "Executed $prog, status $status" 2
-    if ![string match "" $output] {
+    if {![string match "" $output]} {
        verbose -log -- "$output" 2
     }
     if { $status == 0 } {
index 72397c7..b40718a 100644 (file)
@@ -67,7 +67,7 @@ proc find_rawsid { } {
        # srcdir=/..../sid/component/testsuite
        set tcl_library "$srcdir/tcl/library"
         global host_os
-       switch -glob $host_os {
+       switch -glob -- $host_os {
            {cygwin*} { set tcl_library [exec cygpath -w $tcl_library] }
         }
        set env(TCL_LIBRARY) $tcl_library
index 65c21c0..a1d668d 100644 (file)
@@ -78,24 +78,24 @@ proc rpath_flags { args } {
        # libraries, if testing a built but not installed compiler it will not
        # find libraries like libstdc++.so or libgfortran.so so we add the
        # extra hack/search so it can work.
-       if [string match "." $rpathdir] {
-           if [string match $i "libstdc++.so"] {
-               if [file exists "$gccpath/libstdc++-v3/src/.libs/libstdc++.so"] {
+       if {[string match "." $rpathdir]} {
+           if {[string match $i "libstdc++.so"]} {
+               if {[file exists "$gccpath/libstdc++-v3/src/.libs/libstdc++.so"]} {
                    set rpathflags "$rpathflags -Wl,-rpath=$gccpath/libstdc++-v3/src/.libs"
                }
            }
-           if [string match $i "libgfortran.so"] {
-               if [file exists "$gccpath/libgfortran/.libs/libgfortran.so"] {
+           if {[string match $i "libgfortran.so"]} {
+               if {[file exists "$gccpath/libgfortran/.libs/libgfortran.so"]} {
                    set rpathflags "$rpathflags -Wl,-rpath=$gccpath/libgfortran/.libs"
                }
            }
-           if [string match $i "libatomic.so"] {
-               if [file exists "$gccpath/libatomic/.libs/libatomic.so"] {
+           if {[string match $i "libatomic.so"]} {
+               if {[file exists "$gccpath/libatomic/.libs/libatomic.so"]} {
                    set rpathflags "$rpathflags -Wl,-rpath=$gccpath/libatomic/.libs"
                }
            }
-           if [string match $i "libgomp.so"] {
-               if [file exists "$gccpath/libgomp/.libs/libgomp.so"] {
+           if {[string match $i "libgomp.so"]} {
+               if {[file exists "$gccpath/libgomp/.libs/libgomp.so"]} {
                    set rpathflags "$rpathflags -Wl,-rpath=$gccpath/libgomp/.libs"
                }
            }
index b5e5d6c..4326fa4 100644 (file)
@@ -43,13 +43,13 @@ proc adb_open { hostname } {
     set tries 0
     set result -1
 
-    if [board_info ${hostname} exists shell_prompt] {
+    if {[board_info ${hostname} exists shell_prompt]} {
        set shell_prompt [board_info ${hostname} shell_prompt]
     } else {
        set shell_prompt "root@android:/ # "
     }
 
-    if [board_info $hostname exists fileid] {
+    if {[board_info $hostname exists fileid]} {
        unset board_info($hostname,fileid)
     }
 
@@ -116,7 +116,7 @@ proc adb_download {desthost srcfile destfile} {
 proc adb_file {dest op args} {
     set file [lindex $args 0]
     verbose "Executing command: $op $args" 2
-    switch $op {
+    switch -- $op {
        exists {
            set status [catch "exec adb [adb_serial] shell ls |& cat" out]
        }
@@ -185,5 +185,5 @@ proc adb_exec { boardname cmd args } {
     # Delete one trailing \n because that is what `exec' will do and we want
     # to behave identical to it.
     regsub "\n$" $output "" output
-    return [list [expr $status != 0] $output]
+    return [list [expr {$status != 0}] $output]
 }
index 05f8810..f93ea3b 100644 (file)
@@ -179,7 +179,7 @@ proc vxworks_file { dest op args } {
     set file [lindex $args 0]
     if {[board_info $dest exists vxworks_homedir]} {
        set dir "[board_info $dest vxworks_homedir]"
-       switch $op {
+       switch -- $op {
            exists {
                set file "${dir}/[file tail $file]"
                return [file exists $file]
@@ -191,7 +191,7 @@ proc vxworks_file { dest op args } {
                        file delete -force -- $x
                    }
                }
-               return
+               return {}
            }
        }
     }
index 6a54b46..ab5816d 100644 (file)
@@ -569,7 +569,7 @@ proc dg-runtest { testcases options default-extra-options } {
 #
 proc dg-trim-dirname { dir_name file_name } {
     set special_character "\[\?\+\-\.\(\)\$\|\]"
-    regsub -all $special_character $dir_name "\\\\&" dir_name
+    regsub -all -- $special_character $dir_name "\\\\&" dir_name
     regsub "^$dir_name/?" $file_name "" file_name
     return $file_name
 }
@@ -587,7 +587,7 @@ proc dg-test { args } {
     global dg-do-what-default dg-interpreter-batch-mode dg-linenum-format
     global errorCode errorInfo
     global tool
-    global srcdir              ;# eg: /calvin/dje/build/gcc/./testsuite/
+    global srcdir
     global host_triplet target_triplet
 
     set keep 0
index 56865c2..d05952b 100644 (file)
@@ -398,7 +398,7 @@ proc usage { } {
     send_user "\t--D\[0-1\]\t\tTcl debugger\n"
     send_user "\tscript.exp\[=arg(s)\]\tRun these tests only\n"
     if { [info exists tool] } {
-       if { [info proc ${tool}_option_help] != "" } {
+       if { [info procs ${tool}_option_help] != "" } {
            ${tool}_option_help
        }
     }