zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@cambridgesiliconradio.com>
To: zsh-workers@sunsite.auc.dk (Zsh hackers list)
Subject: Re: List of unresolved issues (update)
Date: Tue, 02 May 2000 10:50:52 +0100	[thread overview]
Message-ID: <0FTX00MCWFCRAU@la-la.cambridgesiliconradio.com> (raw)
In-Reply-To: "Your message of Mon, 01 May 2000 05:21:27 -0000." <1000501052127.ZM8590@candle.brasslantern.com>

> Of those, I think 9095 is the only really crucial one.  The others might
> warrant mention on the BUGS list or some such.

The bug was this:

function oops {
    while getopts :m: f
    do
        echo $OPTIND is $f with $OPTARG
        shift $((OPTIND - 1))
    done
    print -r - $*
}

% oops -m 664
2 is m with 664
2 is ? with k
funky

(Note that the apparently correct display of `funky' is a coincidence, it
comes from incorrectly shifting by 2-1 twice.)

The fix looks easy, which in this particular chunk of code makes me very
suspicious (see the comment).  However, I'll commit it anyway until we find
the drawback.  We need comprehensive tests for getopts, including nested
functions, asap.

I now get:

% oops -m 664 funky
3 is m with 664
funky
% oops -m664 funky
2 is m with 664
funky

which I think is right.

Index: Src/builtin.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/builtin.c,v
retrieving revision 1.10
diff -u -r1.10 builtin.c
--- Src/builtin.c	2000/04/30 14:48:49	1.10
+++ Src/builtin.c	2000/05/02 09:47:05
@@ -3077,7 +3077,15 @@
 	    p = ztrdup(args[zoptind++]);
 	} else
 	    p = metafy(str+optcind, lenstr-optcind, META_DUP);
-	optcind = ztrlen(args[zoptind - 1]);
+	/*
+	 * Careful:  I've just changed the following two lines from
+	 *   optcind = ztrlen(args[zoptind - 1]);
+	 * and it's a rigorous theorem that every change in getopts breaks
+	 * something.  See zsh-workers/9095 for the bug fixed here.
+	 *   PWS 2000/05/02
+	 */
+	optcind = 0;
+	zoptind++;
 	zsfree(zoptarg);
 	zoptarg = p;
     } else {

-- 
Peter Stephenson <pws@cambridgesiliconradio.com>
Cambridge Silicon Radio, Unit 300, Science Park, Milton Road,
Cambridge, CB4 0XL, UK                          Tel: +44 (0)1223 392070


      parent reply	other threads:[~2000-05-02  9:51 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-04-12  6:14 List of unresolved issues Bart Schaefer
2000-04-12 15:56 ` Andrej Borsenkow
2000-04-12 20:55 ` Peter Stephenson
2000-04-13  0:26   ` Bart Schaefer
2000-04-13  8:56     ` Peter Stephenson
2000-04-13 14:10       ` PATCH: local exports Peter Stephenson
2000-04-13 15:42         ` Bart Schaefer
2000-04-13 17:54           ` PATCH: " Peter Stephenson
2000-05-01  5:21 ` List of unresolved issues (update) Bart Schaefer
2000-05-01  9:09   ` Adam Spiers
2000-05-02  9:50   ` Peter Stephenson [this message]

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=0FTX00MCWFCRAU@la-la.cambridgesiliconradio.com \
    --to=pws@cambridgesiliconradio.com \
    --cc=zsh-workers@sunsite.auc.dk \
    /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/zsh/

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).