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

Re: Segfault in completion code



Haakon Riiser wrote:
> But, there are still problems when SH_WORD_SPLIT is set.  Here's an
> example that should not depend on my local zsh configuration
> (assuming that "zsh -f" only tries to load /etc/zshenv, which
> does not exist on my system):
> 
>   % /path/to/patched/zsh -f
>   % unset IFS
>   % setopt SH_WORD_SPLIT
>   % autoload -U compinit
>   % compinit
>   % <press completion key>
>   (eval):setopt:1: no such option: globbareglobqualnullglobrcexpand\
>   paramextendedglobunsetNO_markdirsNO_globsubstNO_shwordsplitNO_shglob\
>   NO_kshglobNO_ksharraysNO_cshnullglobNO_allexportNO_aliasesNO_errexit\
>   NO_octalzeroes

The combined effect of shwordsplit and unsetting IFS causes the values
in the list of options to be joined together with no spaces between.
It looks harmless to put it back (IFS might be anything).

However, my patch last night was wrong --- I've checked SUS/Posix 2003
and it says:

IFS (Input Field Separators.) A string treated as a list of characters
    that is used for field splitting and to split lines into fields with
    the read command. If IFS is not set, the shell shall behave as if
    the value of IFS is <space>, <tab>, and <newline>; see Field
    Splitting . Implementations may ignore the value of IFS in the
    environment at the time the shell is invoked, treating IFS as if it
    were not set.

so we should use space to join words.  I don't know why it doesn't allow
you to use no separator, but it doesn't.  This is already handled
correctly in other parts of the shell --- we use a default IFS.  That
fixes the immediate problem above, but as I said IFS might be something
else, so I've still supplied the other hunk.  The following patch
applies on top of last night's fix (now committed).

Index: Src/utils.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/utils.c,v
retrieving revision 1.52
diff -u -r1.52 utils.c
--- Src/utils.c	1 Aug 2003 09:55:41 -0000	1.52
+++ Src/utils.c	1 Aug 2003 10:56:54 -0000
@@ -2058,6 +2058,8 @@
 	if (ifs) {
 	    *p++ = *ifs;
 	    *p++ = *ifs == Meta ? ifs[1] ^ 32 : '\0';
+	} else {
+	    *p++ = ' ';
 	}
 	*p = '\0';
     }
Index: Completion/Base/Core/_main_complete
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Base/Core/_main_complete,v
retrieving revision 1.7
diff -u -r1.7 _main_complete
--- Completion/Base/Core/_main_complete	26 Feb 2003 16:36:06 -0000	1.7
+++ Completion/Base/Core/_main_complete	1 Aug 2003 10:45:31 -0000
@@ -3,6 +3,8 @@
 # The main loop of the completion code. This is what is called when 
 # completion is attempted from the command line.
 
+# In case non-standard separators are in use.
+local IFS=$' \t\n\0'
 
 # If you want to complete only set or unset options for the unsetopt
 # and setopt builtin, un-comment these lines:

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


**********************************************************************
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