Tcl Source Code

View Ticket
Login
Ticket UUID: 1750300
Title: Unexpected [glob] result, when types list is empty
Type: Bug Created on: 2007-07-09 11:25:38
Submitter: matzek Assigned to: dgp
Subsystem: 37. File System Severity:
Priority: 9 Immediate Last modified: 2008-08-14 20:10:40
Status: Closed Closed by: dgp
Resolution: Fixed Closed on: 2008-08-14 13:10:40
Version: obsolete: 8.5.3
Description:
Hi *,

consider the following examples:

* there is a plain file TAGS in the current directory:

% glob -- TAGS tags Tags
TAGS
% glob -types {} -- TAGS tags Tags
TAGS tags Tags

* there is _no_ file "urgent" in the current directory:

% glob -types {} -- U*
no files matched glob pattern "*U*"
% glob -types {} -- URGENT Urgent
URGENT Urgent

Seems an empty types list together with queries without patterns just returns the queries...

% set tcl_patchLevel 
8.4.14

Operating systems: Linux, AIX, HP-UX and Solaris

kind regards
-- Matthias Kraft
User Comments:
matzek added on 2007-07-09 18:33:41:
Logged In: YES 
user_id=330806
Originator: YES

the second example: the query was *U* of cause.

Got one line too less with CnP and then typed the missing line :-/ ...

kind regards
-- Matthias Kraft

georgeps added on 2007-12-15 04:54:53:
Logged In: YES 
user_id=585068
Originator: NO

Cool bug:
% cd /  
% glob -types {} -- TMP tmp
TMP tmp
% file exists TMP
0
% glob -- TMP tmp
tmp

Here's a patch that fixes it:
Index: tclFileName.c
===================================================================
RCS file: /cvsroot/tcl/tcl/generic/tclFileName.c,v
retrieving revision 1.86
diff -u -r1.86 tclFileName.c
--- tclFileName.c       13 Dec 2007 15:23:17 -0000      1.86
+++ tclFileName.c       14 Dec 2007 21:46:51 -0000
@@ -1412,6 +1412,11 @@
         */
 
        Tcl_ListObjLength(interp, typePtr, &length);
+
+       if (length <= 0) {
+            goto skipTypes;
+       }       
+
        globTypes = (Tcl_GlobTypeData*)
                TclStackAlloc(interp,sizeof(Tcl_GlobTypeData));
        globTypes->type = 0;
@@ -1529,6 +1534,7 @@
        }
     }
 
+skipTypes:
     /*
      * Now we perform the actual glob below. This may involve joining together
      * the pattern arguments, dealing with particular file types etc. We use a

matzek added on 2008-07-01 23:00:42:
Logged In: YES 
user_id=330806
Originator: YES

This one still persists in 8.5.3 ... Maybe someone could fix it one way or another.

Thanks
-- Matthias Kraft

dgp added on 2008-08-14 01:15:21:
Logged In: YES 
user_id=80530
Originator: NO


fix committed to all active branches.

das added on 2008-08-14 06:57:52:
Logged In: YES 
user_id=90580
Originator: NO

the tests added for this bug depend on the filesystem being case sensitive, which is not the case everywhere, e.g. not with HFS+ on Mac OS X, it does not seem necessary to test for the fix in this way

==== fileName-20.1 Bug 1750300 FAILED
==== Contents of test case:

    llength [glob -nocomplain -directory $d -- TAGS tags Tags]

---- Result was:
3
---- Result should have been (exact matching):
1
==== fileName-20.1 FAILED



==== fileName-20.2 Bug 1750300 FAILED
==== Contents of test case:

    llength [glob -nocomplain -directory $d -types {} -- TAGS tags Tags]

---- Result was:
3
---- Result should have been (exact matching):
1
==== fileName-20.2 FAILED

dgp added on 2008-08-14 11:10:12:
Logged In: YES 
user_id=80530
Originator: NO


You're right; I simply copied the
test cases out of the bug report
being too lazy to invent my own.

I'll get these tests fixed tomorrow.

dgp added on 2008-08-14 20:10:40:
Logged In: YES 
user_id=80530
Originator: NO


more portable tests committed.