From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22722 invoked by alias); 30 Dec 2017 02:40:55 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: X-Seq: 42185 Received: (qmail 16454 invoked by uid 1010); 30 Dec 2017 02:40:55 -0000 X-Qmail-Scanner-Diagnostics: from mail-qk0-f180.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(209.85.220.180):SA:0(-1.9/5.0):. Processed in 3.876508 secs); 30 Dec 2017 02:40:55 -0000 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,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_PASS,T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1 X-Envelope-From: schaefer@brasslantern.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=L1uAmxOALw4UzqpBYcgk0+tUQW5lTgSX5+K5rCgLdxM=; b=iVfBREZrSTlf0C1DgIL+Oc8/1hn4Y51R6hhpBCqIvJvrPaUT+aq9tr4YAoONILUc2B 1JZmxGabspz7Zpp8JWgOVFO/SRRgrCWg1lcGJXexpPiLszsr0YRZ4++4llaXjZioimjn IJlcyJrqGHeVrDDSKsmfWL3DpcEXTiv7sBibNdypda2I60QVxQL003jKWIKzT+uX1bKb AKY9dywC47dz57Xmp+vmv/3owkkc9qwVHv+CqHtOKPJxY8A6xTek8QvXBGlbMdBcpaMu oWrgPO1ZheqOMUTAzLNId48eXiXAt0vg+9hU5tzQY8fA7uXMd1OZJ1rTCp+AkooL1JnF HOZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=L1uAmxOALw4UzqpBYcgk0+tUQW5lTgSX5+K5rCgLdxM=; b=ow0NkBI/+H2fsPyv47cbWID71h626QFjn/v7lhB548++ZbCN9g3sXxlf4jLqWAm8AR PJlWQkf9q9tf+ORvvYgfVKhx97lknktlZBuW8EKqm+5W8RsqYTaqTWQ56O64y4b1J8SH no1cqLezrJdzeRAxxeKEWjHoDYlIcqQy/kaI1pxaI8gop+up8a8ucVk57fP1aaWjECBr JGmwLBuefEuamrcKMzlILjzhfrsbMBbqoP+lvSbHVD8uUrD991yl2BSZ5iH0vikzatMs IXhTAmwdD+9X6LYaMKWzQLwxoLcZi3xe+O52wVzU+7nNr0IuaPKwwfGwe30Xd5hpjdTy cNqw== X-Gm-Message-State: AKGB3mJqYL1dduSPaTGYEVo8Vtf7UwBn8RlyYXCksJNoYbyplB/mDDgs kk+/waI4S6+E8n1PRrUYXD7RyxIVN/2jE6k9ObSgmw== X-Google-Smtp-Source: ACJfBov1ljfjkQ9KTHf/TU2rbLaafjd4l8FXQaYQiu2VFL3/Tytcc9qCKizvQqnAoaSe/Bp55z4a8aE4Git1GcsaoCc= X-Received: by 10.55.179.135 with SMTP id c129mr44238044qkf.254.1514601647965; Fri, 29 Dec 2017 18:40:47 -0800 (PST) MIME-Version: 1.0 In-Reply-To: References: From: Bart Schaefer Date: Fri, 29 Dec 2017 18:40:47 -0800 Message-ID: Subject: Re: Incorrect evaluation of ~ test in ternary conditional To: Felix Uhl Cc: "zsh-workers@zsh.org" Content-Type: text/plain; charset="UTF-8" Catching up on some old stuff ... On Mon, Dec 18, 2017 at 7:07 AM, Felix Uhl wrote: > >> - if (*ss++ == '/' && *ss) >> + if (*ss && *ss++ == '/' && *ss) >> arg--; >> >> I'm not sure whether (*ss == '/' && *++ss) would be equivalent, i.e., >> I don't know why the original formulation skips over the first >> character whether or not it is a '/'. Possibly to skip a leading '~'? > > The original implementation doesn't skip the first character, does it? It does, because it increments ss regardless of whether or not the first character is '/'. So if ss = "a", (*ss++ == '/' && *ss) is false because 'a' != '/', but ss now points at '\0' instead of at 'a'. > So the whole condition checks whether the first character is '/' and > whether the second character is not 0. Correct, but it has the side-effect of always advancing ss by one position. > I'd probably write that as (*ss == '/' && *(++ss)), seems much clearer > to me. That avoids the side-effect, but I'm not sure if that side-effect was intentional. > I fail to understand why your fix should work, the expressions (*ss && > *ss++ == '/') and (*ss++ == '/') on their own are logically equivalent Not when ss = "". If ss points to empty string, the first of those does not move ss past the null byte into garbage, but the second one does. The question is what should happen when ss is neither the empty string nor begins with a slash. > to (*ss == '/') and have equivalent side-effects as well. This is incorrect with respect to the side-effects. > Did you actually test it? Yes.