Subject: Re: [PATCH] enable number argument for transpose-words
From: Kamil Dudka <[email-masked]>
To: [email-masked]
Cc: Peter Stephenson <[email-masked]>
Date: Fri, 12 Aug 2016 12:25:55 +0200
List-Id: Zsh Workers List <zsh-workers.zsh.org>

On Friday, August 12, 2016 10:29:18 Peter Stephenson wrote:
> On Fri, 12 Aug 2016 10:54:02 +0800
> 
> Han Pingtian <[email-masked]> wrote:
> > Any suggestions to this one, please? Thanks in advance.
> 
> Thanks, I've committed that.  This describes what it does.
> 
> pws
> 
> diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo
> index eaca1b3..aa219dc 100644
> --- a/Doc/Zsh/zle.yo
> +++ b/Doc/Zsh/zle.yo
> @@ -1948,6 +1948,12 @@ to the left.
>  tindex(transpose-words)
>  item(tt(transpose-words) (tt(ESC-T ESC-t)) (unbound) (unbound))(
>  Exchange the current word with the one before it.
> +
> +With a positive numeric argument em(N), the word before the cursor is
> +transposed with the following em(N) words.
> +
> +With a negative numeric argument em(-N), the word after the cursor
> +is transposed with the preceding em(N) words.
>  )
>  tindex(vi-unindent)
>  item(tt(vi-unindent) (unbound) (tt(<)) (unbound))(

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.  I would suggest to initialize explicitly or add assert for the value
of 'n'.  The following warnings started to be reported after this commit:

Error: CLANG_WARNING:
Src/Zle/zle_word.c:747:43: warning: The right operand of '-' is a garbage value
#    pp = temp = (ZLE_STRING_T)zhalloc((p4 - p1)*ZLE_CHAR_SIZE);
#                                          ^ ~~
#  745|       }
#  746|   
#  747|->     pp = temp = (ZLE_STRING_T)zhalloc((p4 - p1)*ZLE_CHAR_SIZE);
#  748|       len = p4 - p3;
#  749|       ZS_memcpy(pp, zleline + p3, len);

Error: COMPILER_WARNING:
Src/Zle/zle_word.c:747:43: warning: ‘p1’ may be used uninitialized in this function [-Wuninitialized]
#  745|       }
#  746|   
#  747|->     pp = temp = (ZLE_STRING_T)zhalloc((p4 - p1)*ZLE_CHAR_SIZE);
#  748|       len = p4 - p3;
#  749|       ZS_memcpy(pp, zleline + p3, len);

Error: COMPILER_WARNING:
Src/Zle/zle_word.c: scope_hint: In function ‘transposewords’
Src/Zle/zle_word.c:751:9: warning: ‘p2’ may be used uninitialized in this function [-Wuninitialized]
#  749|       ZS_memcpy(pp, zleline + p3, len);
#  750|       pp += len;
#  751|->     len = p3 - p2;
#  752|       ZS_memcpy(pp, zleline + p2, len);
#  753|       pp += len;

Full build log at: https://travis-ci.org/kdudka/csbuild-zsh/builds/151747546

Kamil