mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: musl@lists.openwall.com
Subject: Re: [PATCH] implement glibc's glob_pattern_p
Date: Mon, 21 Jul 2014 10:33:23 -0400	[thread overview]
Message-ID: <20140721143323.GP17402@brightrain.aerifal.cx> (raw)
In-Reply-To: <1405588375-24435-1-git-send-email-glommer@cloudius-systems.com>

On Thu, Jul 17, 2014 at 01:12:55PM +0400, Glauber Costa wrote:
> Currently, glob is implemented but glob_pattern_p is not. This function
> can trivially be implemented with existing glob machinery, since all it
> does is to tell whether or not the string contains special symbols. This
> is basically the same logic as is_literal, but with inverted return value.
> 
> The value of the "quote" parameter should also be inverted, since the man
> page states that when the quote parameter is *non*-zero, then backslashes
> are ignored. is_literal ignores them when useesc is *zero*.

Upon reviewing this patch, I'm not sure if it's correct. It wrote this
code (glob.c) roughly 10 years ago and barely touched it since, but
from what I can tell, the existing is_literal looks like a premature
optimization to avoid calling fnmatch when it's not necessary than an
accurate predicate. In other words, it's designed to reliably return 0
if the string is a glob, but there are also cases where it returns 0
when the string is not a "glob pattern" but not purely a literal
either (e.g. anything containing backslash when useesc is nonzero,
since such strings cannot be processed with strcmp and need fnmatch).

My leaning would be to remove this "optimization" from glob.c entirely
(it shouldn't be needed if fnmatch is efficient) and move the code to
a separate file for glob_pattern_p, but then we need to make sure it
gets things right with no false positives or false negatives.

Rich


  parent reply	other threads:[~2014-07-21 14:33 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-17  9:12 Glauber Costa
2014-07-19 20:11 ` Rich Felker
2014-07-19 23:17   ` Glauber Costa
2014-07-19 23:45     ` Rich Felker
2014-07-20 20:01       ` Thomas Petazzoni
2014-07-21 10:19         ` Glauber Costa
2014-07-20 20:36 ` Szabolcs Nagy
2014-07-21 10:29   ` Glauber Costa
2014-07-21 14:11     ` Rich Felker
2014-07-21 23:45       ` John Spencer
2014-07-21 14:33 ` Rich Felker [this message]
2014-07-21 22:44   ` Glauber Costa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140721143323.GP17402@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).