Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm
Precedence: bulk
X-No-Archive: yes
List-Id: Zsh Workers List <zsh-workers.zsh.org>
List-Post: <mailto:zsh-workers@zsh.org>
List-Help: <mailto:zsh-workers-help@zsh.org>
X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au
X-Spam-Level: 
X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,T_DKIM_INVALID
	autolearn=ham autolearn_force=no version=3.4.1
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=brasslantern-com.20150623.gappssmtp.com; s=20150623;
        h=from:message-id:date:in-reply-to:comments:references:to:subject
         :mime-version;
        bh=5Sk0/JXXhse8izqXStXR6RYAT3jXAijmJEo6ACJaT88=;
        b=OfCIW9TFF3BLI1roQFxGHH75cfr/qObXTVkIhlxhPwfJJfmql4a8KeLF+jzhK2RhHO
         SAPUdVObWeCaQUicNkJZ+76QPE5bTd+G9ORn3XBdPLE73/FMmreszCdFyrAyesHRthIZ
         PFA5KlNVWyhUHAwx3XU68FXw1em63bw+gq5AkndAxzwZTlk0vWUAo9qmvoQeJDYxwjRm
         ods3e2gjIwFGZhvD4dEIetZZr7l5EiW+C3qjKOeqkpw3QHsYEkiqIMtBgJLh5YyWbt0J
         R+SBMFAsWksm5p8uVIelwmtRKnY2ioYDE+8e04Z9BGX7sSS9bcx0HBFJmwhtJA5cbFUh
         +KAg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:from:message-id:date:in-reply-to:comments
         :references:to:subject:mime-version;
        bh=5Sk0/JXXhse8izqXStXR6RYAT3jXAijmJEo6ACJaT88=;
        b=QaJTZ2+nb1fzr5SENS3xejZyxmpKqf1rCNk/GiNImTQuG3+flsnAyheZkeGa74WePh
         MWfWZaqVCVkT80S79PZ8FeVWlpTl10XtADq37HVog3ZzcMVjtCYRtAsqE+1/9KeQDbSX
         mwqgKlOSd3IyJKzadwR8rPuWvxK8P+GnTkJymqAO0vBs1BFmIyx/3wLBHZlhYw7uQlsA
         lLZguqRq/cW4xHUC8LwAzC4ZhsCdgraU7wTUkiUgiZC4q1CFVc3dG0NyR9XDFsXTDci6
         zUXNHSBDg7yoVTEMn9QjMuUbfjYsJtwu1I3LGiDyOZQNEBHRmWlkF+ypPsrBQIzU2r6/
         7a+Q==
X-Gm-Message-State: ALyK8tI3WBDxKjFuHiYFUenEqbQUTsS+8l2M+3ZTuCUDGWAm/KJQpRbU1McV4s+h66jECg==
X-Received: by 10.98.43.7 with SMTP id r7mr31600478pfr.65.1468213083813;
        Sun, 10 Jul 2016 21:58:03 -0700 (PDT)
From: Bart Schaefer <schaefer@brasslantern.com>
Message-Id: <160710215821.ZM11734@torch.brasslantern.com>
Date: Sun, 10 Jul 2016 21:58:21 -0700
In-Reply-To: <6ED44F4D-7D51-4F0B-935D-4A3868E0C5C3@gmail.com>
Comments: In reply to Zhiming Wang <zmwangx@gmail.com>
        "Re: [BUG] Directory glob picks up running or already-run scripts on OS X" (Jul 11,  8:48am)
References: <CEE58D57-A237-4451-8882-0AE0CE21DD58@gmail.com> 
	<CAH+w=7Y6GEJxa5LS4AeG5V5hsyUYJkSEEEMRnMSSJpLpRfLPXA@mail.gmail.com> 
	<B17666ED-6D14-477C-B45D-3B7F064B5F24@gmail.com> 
	<CAH+w=7Zr8T2b7hMhjj1K0oJ_KaWE2MBAfwBzmKnZzjOfvYjn5Q@mail.gmail.com> 
	<6ED44F4D-7D51-4F0B-935D-4A3868E0C5C3@gmail.com>
X-Mailer: OpenZMail Classic (0.9.2 24April2005)
To: zsh-workers@zsh.org
Subject: Re: [BUG] Directory glob picks up running or already-run scripts on OS X
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
X-Seq: zsh-workers 38821

I'm not sure whether this was introduced when adding the (Y) qualifier,
or if it was already lurking.  With the following DPUTS() added and zsh
compiled with debugging, Test/D02glob.ztst will fail (on any platform).

diff --git a/Src/glob.c b/Src/glob.c
index 2051016..5260b63 100644
--- a/Src/glob.c
+++ b/Src/glob.c
@@ -318,6 +318,8 @@ insert(char *s, int checked)
     char *news = s;
     int statted = 0;
 
+    DPUTS(!s || !*s, "BUG: adding empty string as glob match");
+
     queue_signals();
     inserts = NULL;
 

The problem seems to be that scanner() calls recursively one extra
time when looking at "notadirectory/".

In that case statfullpath("") is called and, for reasons I haven't
figured out, that returns success on MacOS when called in exactly
the circumstances that Zhiming describes.

This will eventually correct itself, which leads me to suspect it has
something to do with re-using the global static "pathbuf".

The simple fix would be for insert() to be a no-op when called on the
empty string, but it might be useful to examine scanner() in more
detail to try to avoid the extra recursion.

