This looks wrong - the first item now has index (u_int)-1?

idx will still be 0 if there was nothing added, so why not just this?

Index: cmd-choose-list.c
===================================================================
RCS file: /cvs/src/usr.bin/tmux/cmd-choose-list.c,v
retrieving revision 1.2
diff -u -p -r1.2 cmd-choose-list.c
--- cmd-choose-list.c   3 Sep 2012 10:02:39 -0000       1.2
+++ cmd-choose-list.c   5 Sep 2012 10:04:00 -0000
@@ -86,6 +86,12 @@ cmd_choose_list_exec(struct cmd *self, s
        }
        free(copy);
 
+       if (idx == 0) {
+               free(template);
+               window_pane_reset_mode(wl->window->active);
+               return (CMD_RETURN_ERROR);
+       }
+
        window_choose_ready(wl->window->active, 0, cmd_choose_list_callback,
            cmd_choose_list_free);
 
 
 




On Wed, Sep 05, 2012 at 10:35:53AM +0100, Thomas Adam wrote:
> Even though we skip empty entries separated with commas when we're looking
> at each item, an input such as:
> 
> choose-list -l ,,,,,,
> 
> would still mean we go on to display a blank line, resulting in a segfault
> as there's no data associated with that entry.
> ---
>  cmd-choose-list.c | 15 ++++++++++++---
>  1 file changed, 12 insertions(+), 3 deletions(-)
> 
> diff --git a/cmd-choose-list.c b/cmd-choose-list.c
> index 15c644e..ef05de5 100644
> --- a/cmd-choose-list.c
> +++ b/cmd-choose-list.c
> @@ -75,7 +75,7 @@ cmd_choose_list_exec(struct cmd *self, struct cmd_ctx *ctx)
>               template = xstrdup(CMD_CHOOSE_LIST_DEFAULT_TEMPLATE);
>  
>       copy = list = xstrdup(list1);
> -     idx = 0;
> +     idx = -1;
>       while ((item = strsep(&list, ",")) != NULL)
>       {
>               if (*item == '\0') /* no empty entries */
> @@ -86,8 +86,17 @@ cmd_choose_list_exec(struct cmd *self, struct cmd_ctx *ctx)
>       }
>       free(copy);
>  
> -     window_choose_ready(wl->window->active, 0, cmd_choose_list_callback,
> -         cmd_choose_list_free);
> +     /* Even though we skip empty entries separated by commas, an entirely
> +      * empty list means we do nothing.
> +      */
> +     if ((int)idx < 0) {
> +             free(template);
> +             window_pane_reset_mode(wl->window->active);
> +             return (CMD_RETURN_ERROR);
> +     }
> +
> +     window_choose_ready(wl->window->active, 0,
> +             cmd_choose_list_callback, cmd_choose_list_free);
>  
>       free(template);
>  
> -- 
> 1.7.11.4
> 
> 
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and 
> threat landscape has changed and how IT managers can respond. Discussions 
> will include endpoint security, mobile security and the latest in malware 
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> tmux-users mailing list
> tmux-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/tmux-users

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
tmux-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users

Reply via email to