Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: getopts fails on empty string



We used to have new getopts bugs turning up just about every
week... this is just like old times.  We really need a test.

If getopts encounters an empty string on the command line, it will
ignore the argument and go on to the next one.  Typically this means
$OPTIND is one too large, but if the next word looks like an option
other things could happen.

By the way, I've committed Dan's xtrace patch.

Index: Src/builtin.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/builtin.c,v
retrieving revision 1.78
diff -u -r1.78 builtin.c
--- Src/builtin.c	1 Aug 2002 15:06:25 -0000	1.78
+++ Src/builtin.c	1 Aug 2002 15:39:42 -0000
@@ -3518,6 +3518,8 @@
 
     /* find place in relevant argument */
     str = unmetafy(dupstring(args[zoptind - 1]), &lenstr);
+    if (!lenstr)		/* Definitely not an option. */
+	return 1;
     if(optcind >= lenstr) {
 	optcind = 0;
 	if(!args[zoptind++])

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 392070


**********************************************************************
The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential 
and/or privileged material. 
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by 
persons or entities other than the intended recipient is 
prohibited.  
If you received this in error, please contact the sender and 
delete the material from any computer.
**********************************************************************



Messages sorted by: Reverse Date, Date, Thread, Author