bug-findutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug #15235] Leading directories are misparsed as expressions


From: Eric Blake
Subject: [bug #15235] Leading directories are misparsed as expressions
Date: Tue, 20 Dec 2005 06:14:16 -0700
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8) Gecko/20051111 Firefox/1.5

Follow-up Comment #5, bug #15235 (project findutils):

Your patch is not quite right:

+boolean 
+looks_like_expression(const char *arg)
+{
+  switch (arg[0])
+    {
+    case '-':
+      if (arg[1])              /* "-foo" is an expression.  */
+       return true;
+      else
+       return false;           /* Just "-" is a filename. */
+      break;

Hmm, I thought that "-" starts with a '-', so it should be treated as an
invalid option, but I guess you are okay in saying that the POSIX wording of
"starts with" implies improper substring, therefore "-" is a filename since
it is an exact match rather than a prefix.

Which raises the question - if you treat "-" as a filename, is it the file
./-, or is it shorthand for stdin (on systems where stdin can be redirected
from a directory)?

+      
+      /* According to the POSIX standard, we have to assume that a leading
')' 
is a 
+       * filename argument.   Hence it does not matter if the ')' is
followed b
y any
+       * other characters.
+       */
+    case ')':
+      return false;
+      
+      /* (, ) and ! are part of an expression,
+       * but (2, )3 and !foo are filenames.
+       */
+    case '!':
+    case '(':
+    case ',':

Wrong - you need to treat ',' like you did ')'; a leading comma is always
treated as a filename before the first expression is found.

+      if (arg[1])
+       return false;
+      else
+       return true;
+
+    default:
+      return false;

Why not combine the code for case ')': (and as I pointed out, case ',':),
with default:?

+    }
+}


Thanks for working on this.


    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?func=detailitem&item_id=15235>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/





reply via email to

[Prev in Thread] Current Thread [Next in Thread]