PATCH: fix bug in getdirs

Ben Elliston <[email protected]>
Newsgroups gmane.comp.sysutils.dejagnu.general
Message-ID <[email protected]>
I discovered a quite nasty bug in getdirs. I'm surprised it has never
caused a major problem before. When looking for directories that match
a pattern, the existing code uses 'catch' to avoid an error if nothing
matches the glob. The output is saved in $tmp. When nothing matches,
the error output is saved instead:

% glob /not/here
no files matched glob pattern "/not/here"
% catch {glob /not/here} tmp
1
% puts $tmp
no files matched glob pattern "/not/here"

This is wrong. Instead, we should use glob -nocomplain. This sets $tmp
to empty if there are no matches. In addition, I see no reason why
getdirs should call perror if there are no matches--this path was
never executed before, of course.  Being a utility procedure, it is
fine to return "" and let the caller decide what to do.

I removed the if { $tmp ne "" } and else expressions and
reindented. The diff output below was generated with 'git diff
-w'.

OK?

Cheers, Ben


diff --git a/lib/utils.exp b/lib/utils.exp
index 57a6831..d397679 100644
--- a/lib/utils.exp
+++ b/lib/utils.exp
@@ -44,8 +44,7 @@ proc getdirs { args } {
 	set pattern "*"
     }
     verbose "Looking in $path for directories that match \"${pattern}\"" 3
-    catch "glob $path/$pattern" tmp
-    if { $tmp ne "" } {
+    set tmp [glob -nocomplain $path/$pattern]
     foreach i $tmp {
 	if {[file isdirectory $i]} {
 	    switch -- "[file tail $i]" {
@@ -72,10 +71,6 @@ proc getdirs { args } {
 	    }
 	}
     }
-    } else {
-	perror $tmp
-	return ""
-    }
 
     if {![info exists dirs]} {
 	return ""

_______________________________________________
DejaGnu mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/dejagnu
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCAAdFiEEFS8+rdM1/2KWERKFZ9rcPj90NkkFAlwNgKAACgkQZ9rcPj90
NknGEg//bd+vOVYPnT2ZiUPAJd4VhXwm8+Cz0JpX3cXujFUjhGd8FLL160BXFeIc
+B8sHHcJ94wyD8+/MgVFLzR1Kom6A0Lo5mHkfJCW6sUGAfsVmXwq7eXLqyO23vYS
CDDrFtPptgznnGxCxKJnN6zDFN1s4VYIhIF9mKjlT7rVZUq4BindLdeCNJrWcf3g
FF06gtB+3MLCptVlMj4Kd6aZ940VoMOvnUHWJYqmVbCYqiofNjxHwk9mm8ASzH3D
/e36f1+GN73q44sGae4B+YQKQdCezIWq+/DkcDgA+SyqYKlcU284d9nxQ8C4uucZ
ONdDA6VZp1dP5YiePX/T91tPgwx8goEKEUbTkMBIankRvngsg+PWYu+1eAvmY1Xv
DY8tyb3jPfyNRAfvVS5yGUk5sBbNRNWB4ryx3qXVFQKWT/lWXCDQjed6tB8FBWhQ
QEWGLQZqWPXjgFhlZDGoej6aQ3/uXjODzN8Y0itFrmEC4HOylmXg5n95ZDhpP0qR
i/SV1S7HjlZa1CZSmRN4IWM1ipzJNR42R8eGJ76zVBM8gWF6iQfpVy+rUVoH378m
S5ivAcOCDjqCgUQm9T9T+H+H08IhDNkvbbepgw/m5ebLdlJEpjUwlfdQsGiC7wNa
uptdeXU1Cqz83XuRxgcgoRgGpey5YV/LR3OQTGg+ur8AwzHqhPg=
=Dco/
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.