Index: unixutil.pp
===================================================================
RCS file: /FPC/CVS/fpc/rtl/unix/unixutil.pp,v
retrieving revision 1.5
diff -u -r1.5 unixutil.pp
--- unixutil.pp	15 Mar 2004 20:43:07 -0000	1.5
+++ unixutil.pp	6 May 2004 01:54:31 -0000
@@ -227,19 +227,25 @@
       '?' : Found:=(j<=LenName);
       '*' : Begin
             {find the next character in pattern, different of ? and *}
-              while Found and (i<LenPat) do
+              while Found do
                 begin
                 inc(i);
+                if i>LenPat then Break;
                 case Pattern[i] of
                   '*' : ;
                   '?' : begin
+                          if j>LenName then 
+                          begin
+                           DoFNMatch:=false;
+                           Exit;
+                          end;
                           inc(j);
-                          Found:=(j<=LenName);
                         end;
                 else
                   Found:=false;
                 end;
                end;
+              Assert((i>LenPat) or ( (Pattern[i]<>'*') and (Pattern[i]<>'?') ));
             {Now, find in name the character which i points to, if the * or ?
              wasn't the last character in the pattern, else, use up all the
              chars in name}
@@ -250,6 +256,8 @@
                 {find a letter (not only first !) which maches pattern[i]}
                 while (j<=LenName) and (name[j]<>pattern[i]) do
                   inc (j);
+                 if (j>LenName) then
+                  Found:=false else
                  if (j<LenName) then
                   begin
                     if DoFnMatch(i+1,j+1) then
