Subject: Re: [PATCH] enable number argument for transpose-words
From: Peter Stephenson <[email-masked]>
To: [email-masked]
Date: Fri, 12 Aug 2016 11:41:42 +0100
List-Id: Zsh Workers List <zsh-workers.zsh.org>

On Fri, 12 Aug 2016 12:25:55 +0200
Kamil Dudka <[email-masked]> wrote:
> Is the body of 'while (n--)' loop guaranteed to be executed at least once?
> 
> Otherwise p1 and p2 may be used uninitialized by code following after the
> loop.

It's probably reasonable to do the following...

pws

diff --git a/Src/Zle/zle_word.c b/Src/Zle/zle_word.c
index 2a15171..e4a878e 100644
--- a/Src/Zle/zle_word.c
+++ b/Src/Zle/zle_word.c
@@ -722,7 +722,7 @@ transposewords(UNUSED(char **args))
     if (!p3)
 	return 1;
 
-    pt = p3;
+    p1 = p2 = pt = p3;
 
     while (n--) {
 	for (p2 = pt; p2; ) {