Bug#465163: After 7.1.226, cmdline completion hangs

Bram Moolenaar Bram at moolenaar.net
Sun Feb 24 21:50:25 UTC 2008


James -

> Patch 7.1.226 relaxed the restrictions on cmdline completion.  This
> can cause Vim to hang while performing cmdline completion if <space> is
> added to 'isfname'.
> 
>   vim -N -u NONE -c "set isfname+=3D32"
>   :r !ls /<C-l>
> 
> An infinite loop happens in set_one_cmd_context as shown by the
> following code which I've trimmed down to the relevant path.
> 
> 	while (*p !=3D NUL)
> 	{
> 	    [snip]
> 	    /* An argument can contain just about everything, except
> 	     * characters that end the command and white space. */
> 	    else if (c =3D=3D '|' || c =3D=3D '\n' || c =3D=3D '"' || (vim_iswhite=
> (c)
> #ifdef SPACE_IN_FILENAME
> 					 && (!(ea.argt & NOSPC) || usefilter)
> #endif
> 		    ))
> 	    {
> 		while (*p !=3D NUL)
> 		{
> 		    [snip]
> 		    if (c =3D=3D '`' || vim_isfilec_or_wc(c))
> 			break;
> 		    [snip]
> **		    mb_ptr_adv(p);
> 		}
> 		[snip]
> 		p -=3D len;
> 	    }
> 	    mb_ptr_adv(p);
> 	}
> 
> The code never leaves the outer while loop.  It would seem that Vim
> either shouldn't be entering the else if branch (and was the previous
> behavior) or it shouldn't be breaking out of the inner while loop so
> that the ** marked line is run.
> 
> What's currently happening is that p is decremented by len (1 in this
> case) and then incremented again immediately outside of the inner while
> loop.  So Vim loops forever examining the exact same string.

That's a bug.  Resetting "len" to zero at the start of the loop fixes
it.

Note that adding a space to 'isfname' is bad, it will break lots of
things.  Vim doesn't know where a file name starts or ends.

> I also have to wonder why os_unix.h doesn't define SPACE_IN_FILENAME.

Because in Unix file names normally don't have a space in the name.  On
MS-Windows it's much more common.  E.g., "C:/program files/".

On Unix a file name can contain any character except "/", but making
"gf" and completion work on that doesn't make sense.

- Bram

-- 
hundred-and-one symptoms of being an internet addict:
39. You move into a new house and decide to Netscape before you landscape.

 /// Bram Moolenaar -- Bram at Moolenaar.net -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\        download, build and distribute -- http://www.A-A-P.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///





More information about the pkg-vim-maintainers mailing list