Patch 9.0.0259
Problem:    Crash with mouse click when not initialized.
Solution:   Check TabPageIdxs[] is not NULL.
Files:      src/mouse.c, src/testdir/test_tabline.vim


*** ../vim-9.0.0258/src/mouse.c 2022-08-14 14:16:07.995582211 +0100
--- src/mouse.c 2022-08-24 19:26:29.221604345 +0100
***************
*** 471,544 ****
  
      start_visual.lnum = 0;
  
!     // Check for clicking in the tab page line.
!     if (mouse_row == 0 && firstwin->w_winrow > 0)
      {
!       if (is_drag)
        {
!           if (in_tab_line)
            {
!               c1 = TabPageIdxs[mouse_col];
!               tabpage_move(c1 <= 0 ? 9999 : c1 < tabpage_index(curtab)
!                                                               ? c1 - 1 : c1);
            }
-           return FALSE;
-       }
  
!       // click in a tab selects that tab page
!       if (is_click
  # ifdef FEAT_CMDWIN
!               && cmdwin_type == 0
  # endif
!               && mouse_col < Columns)
!       {
!           in_tab_line = TRUE;
!           c1 = TabPageIdxs[mouse_col];
!           if (c1 >= 0)
            {
!               if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK)
!               {
!                   // double click opens new page
!                   end_visual_mode_keep_button();
!                   tabpage_new();
!                   tabpage_move(c1 == 0 ? 9999 : c1 - 1);
!               }
!               else
                {
!                   // Go to specified tab page, or next one if not clicking
!                   // on a label.
!                   goto_tabpage(c1);
! 
!                   // It's like clicking on the status line of a window.
!                   if (curwin != old_curwin)
                        end_visual_mode_keep_button();
                }
-           }
-           else
-           {
-               tabpage_T       *tp;
- 
-               // Close the current or specified tab page.
-               if (c1 == -999)
-                   tp = curtab;
                else
-                   tp = find_tabpage(-c1);
-               if (tp == curtab)
                {
!                   if (first_tabpage->tp_next != NULL)
!                       tabpage_close(FALSE);
                }
-               else if (tp != NULL)
-                   tabpage_close_other(tp, FALSE);
            }
        }
-       return TRUE;
-     }
-     else if (is_drag && in_tab_line)
-     {
-       c1 = TabPageIdxs[mouse_col];
-       tabpage_move(c1 <= 0 ? 9999 : c1 - 1);
-       return FALSE;
      }
  
      // When 'mousemodel' is "popup" or "popup_setpos", translate mouse events:
--- 471,547 ----
  
      start_visual.lnum = 0;
  
!     if (TabPageIdxs != NULL)  // only when initialized
      {
!       // Check for clicking in the tab page line.
!       if (mouse_row == 0 && firstwin->w_winrow > 0)
        {
!           if (is_drag)
            {
!               if (in_tab_line)
!               {
!                   c1 = TabPageIdxs[mouse_col];
!                   tabpage_move(c1 <= 0 ? 9999 : c1 < tabpage_index(curtab)
!                                                                   ? c1 - 1 : 
c1);
!               }
!               return FALSE;
            }
  
!           // click in a tab selects that tab page
!           if (is_click
  # ifdef FEAT_CMDWIN
!                   && cmdwin_type == 0
  # endif
!                   && mouse_col < Columns)
            {
!               in_tab_line = TRUE;
!               c1 = TabPageIdxs[mouse_col];
!               if (c1 >= 0)
                {
!                   if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK)
!                   {
!                       // double click opens new page
                        end_visual_mode_keep_button();
+                       tabpage_new();
+                       tabpage_move(c1 == 0 ? 9999 : c1 - 1);
+                   }
+                   else
+                   {
+                       // Go to specified tab page, or next one if not clicking
+                       // on a label.
+                       goto_tabpage(c1);
+ 
+                       // It's like clicking on the status line of a window.
+                       if (curwin != old_curwin)
+                           end_visual_mode_keep_button();
+                   }
                }
                else
                {
!                   tabpage_T   *tp;
! 
!                   // Close the current or specified tab page.
!                   if (c1 == -999)
!                       tp = curtab;
!                   else
!                       tp = find_tabpage(-c1);
!                   if (tp == curtab)
!                   {
!                       if (first_tabpage->tp_next != NULL)
!                           tabpage_close(FALSE);
!                   }
!                   else if (tp != NULL)
!                       tabpage_close_other(tp, FALSE);
                }
            }
+           return TRUE;
+       }
+       else if (is_drag && in_tab_line)
+       {
+           c1 = TabPageIdxs[mouse_col];
+           tabpage_move(c1 <= 0 ? 9999 : c1 - 1);
+           return FALSE;
        }
      }
  
      // When 'mousemodel' is "popup" or "popup_setpos", translate mouse events:
*** ../vim-9.0.0258/src/testdir/test_tabline.vim        2022-02-19 
11:31:34.000000000 +0000
--- src/testdir/test_tabline.vim        2022-08-24 19:25:09.194773256 +0100
***************
*** 147,150 ****
--- 147,164 ----
    set showtabline& tabline&
  endfunc
  
+ func Test_mouse_click_in_tab()
+   " This used to crash because TabPageIdxs[] was not initialized
+   let lines =<< trim END
+       tabnew
+       set mouse=a
+       exe "norm \<LeftMouse>"
+   END
+   call writefile(lines, 'Xclickscript')
+   call RunVim([], [], "-e -s -S Xclickscript -c qa")
+ 
+   call delete('Xclickscript')
+ endfunc
+ 
+ 
  " vim: shiftwidth=2 sts=2 expandtab
*** ../vim-9.0.0258/src/version.c       2022-08-24 18:07:56.889586310 +0100
--- src/version.c       2022-08-24 19:20:23.320070728 +0100
***************
*** 733,734 ****
--- 733,736 ----
  {   /* Add new patch number below this line */
+ /**/
+     259,
  /**/

-- 
ROBIN:  (warily) And if you get a question wrong?
ARTHUR: You are cast into the Gorge of Eternal Peril.
ROBIN:  Oh ... wacho!
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20220824182837.009771C0D30%40moolenaar.net.

Raspunde prin e-mail lui