comparison src/popupwin.c @ 32741:19a9b8fe3b85 v9.0.1690

patch 9.0.1690: popup_create() not aborting on errors Commit: https://github.com/vim/vim/commit/f6cdab3704959379086d6a097fabdf6c55d73779 Author: Christian Brabandt <cb@256bit.org> Date: Fri Aug 11 23:42:02 2023 +0200 patch 9.0.1690: popup_create() not aborting on errors Problem: popup_create() not aborting on errors Solution: check for errors in arguments given and abort if an error occurred closes: #12711 Signed-off-by: Christian Brabandt <cb@256bit.org>
author Christian Brabandt <cb@256bit.org>
date Sat, 12 Aug 2023 00:00:03 +0200
parents 97255d909654
children abf161ce0c77
comparison
equal deleted inserted replaced
32740:a59357132983 32741:19a9b8fe3b85
90 if (n == 0) 90 if (n == 0)
91 n = -1; 91 n = -1;
92 return n; 92 return n;
93 } 93 }
94 94
95 static void 95 static int
96 set_padding_border(dict_T *dict, int *array, char *name, int max_val) 96 set_padding_border(dict_T *dict, int *array, char *name, int max_val)
97 { 97 {
98 dictitem_T *di; 98 dictitem_T *di;
99 99
100 di = dict_find(dict, (char_u *)name, -1); 100 di = dict_find(dict, (char_u *)name, -1);
101 if (di == NULL) 101 if (di == NULL)
102 return; 102 return OK;
103 103
104 if (di->di_tv.v_type != VAR_LIST) 104 if (di->di_tv.v_type != VAR_LIST)
105 { 105 {
106 emsg(_(e_list_required)); 106 emsg(_(e_list_required));
107 return; 107 return FAIL;
108 } 108 }
109 109
110 list_T *list = di->di_tv.vval.v_list; 110 list_T *list = di->di_tv.vval.v_list;
111 listitem_T *li; 111 listitem_T *li;
112 int i; 112 int i;
113 int nr; 113 int nr;
114 114
115 for (i = 0; i < 4; ++i) 115 for (i = 0; i < 4; ++i)
116 array[i] = 1; 116 array[i] = 1;
117 if (list == NULL) 117 if (list == NULL)
118 return; 118 return OK;
119 119
120 CHECK_LIST_MATERIALIZE(list); 120 CHECK_LIST_MATERIALIZE(list);
121 for (i = 0, li = list->lv_first; i < 4 && i < list->lv_len; 121 for (i = 0, li = list->lv_first; i < 4 && i < list->lv_len;
122 ++i, li = li->li_next) 122 ++i, li = li->li_next)
123 { 123 {
124 nr = (int)tv_get_number(&li->li_tv); 124 nr = (int)tv_get_number(&li->li_tv);
125 if (nr >= 0) 125 if (nr >= 0)
126 array[i] = nr > max_val ? max_val : nr; 126 array[i] = nr > max_val ? max_val : nr;
127 } 127 }
128
129 return OK;
128 } 130 }
129 131
130 /* 132 /*
131 * Used when popup options contain "moved": set default moved values. 133 * Used when popup options contain "moved": set default moved values.
132 */ 134 */
711 } 713 }
712 714
713 /* 715 /*
714 * Shared between popup_create() and f_popup_setoptions(). 716 * Shared between popup_create() and f_popup_setoptions().
715 */ 717 */
716 static void 718 static int
717 apply_general_options(win_T *wp, dict_T *dict) 719 apply_general_options(win_T *wp, dict_T *dict)
718 { 720 {
719 dictitem_T *di; 721 dictitem_T *di;
720 int nr; 722 int nr;
721 char_u *str; 723 char_u *str;
812 #ifdef FEAT_TERMINAL 814 #ifdef FEAT_TERMINAL
813 term_update_wincolor(wp); 815 term_update_wincolor(wp);
814 #endif 816 #endif
815 } 817 }
816 818
817 set_padding_border(dict, wp->w_popup_padding, "padding", 999); 819 if (set_padding_border(dict, wp->w_popup_padding, "padding", 999) == FAIL ||
818 set_padding_border(dict, wp->w_popup_border, "border", 1); 820 set_padding_border(dict, wp->w_popup_border, "border", 1) == FAIL)
821 return FAIL;
819 822
820 di = dict_find(dict, (char_u *)"borderhighlight", -1); 823 di = dict_find(dict, (char_u *)"borderhighlight", -1);
821 if (di != NULL) 824 if (di != NULL)
822 { 825 {
823 if (di->di_tv.v_type != VAR_LIST || di->di_tv.vval.v_list == NULL) 826 if (di->di_tv.v_type != VAR_LIST || di->di_tv.vval.v_list == NULL)
827 {
824 emsg(_(e_list_required)); 828 emsg(_(e_list_required));
829 return FAIL;
830 }
825 else 831 else
826 { 832 {
827 list_T *list = di->di_tv.vval.v_list; 833 list_T *list = di->di_tv.vval.v_list;
828 listitem_T *li; 834 listitem_T *li;
829 int i; 835 int i;
851 857
852 di = dict_find(dict, (char_u *)"borderchars", -1); 858 di = dict_find(dict, (char_u *)"borderchars", -1);
853 if (di != NULL) 859 if (di != NULL)
854 { 860 {
855 if (di->di_tv.v_type != VAR_LIST) 861 if (di->di_tv.v_type != VAR_LIST)
862 {
856 emsg(_(e_list_required)); 863 emsg(_(e_list_required));
864 return FAIL;
865 }
857 else 866 else
858 { 867 {
859 list_T *list = di->di_tv.vval.v_list; 868 list_T *list = di->di_tv.vval.v_list;
860 listitem_T *li; 869 listitem_T *li;
861 int i; 870 int i;
925 wp->w_popup_mask = di->di_tv.vval.v_list; 934 wp->w_popup_mask = di->di_tv.vval.v_list;
926 ++wp->w_popup_mask->lv_refcount; 935 ++wp->w_popup_mask->lv_refcount;
927 VIM_CLEAR(wp->w_popup_mask_cells); 936 VIM_CLEAR(wp->w_popup_mask_cells);
928 } 937 }
929 else 938 else
939 {
930 semsg(_(e_invalid_value_for_argument_str), "mask"); 940 semsg(_(e_invalid_value_for_argument_str), "mask");
941 return FAIL;
942 }
931 } 943 }
932 944
933 #if defined(FEAT_TIMERS) 945 #if defined(FEAT_TIMERS)
934 // Add timer to close the popup after some time. 946 // Add timer to close the popup after some time.
935 nr = dict_get_number(dict, "time"); 947 nr = dict_get_number(dict, "time");
991 wp->w_filter_mode = mode_str2flags(str); 1003 wp->w_filter_mode = mode_str2flags(str);
992 } 1004 }
993 1005
994 di = dict_find(dict, (char_u *)"callback", -1); 1006 di = dict_find(dict, (char_u *)"callback", -1);
995 if (di == NULL) 1007 if (di == NULL)
996 return; 1008 return OK;
997 1009
998 callback_T callback = get_callback(&di->di_tv); 1010 callback_T callback = get_callback(&di->di_tv);
999 if (callback.cb_name == NULL) 1011 if (callback.cb_name == NULL)
1000 return; 1012 return OK;
1001 1013
1002 free_callback(&wp->w_close_cb); 1014 free_callback(&wp->w_close_cb);
1003 set_callback(&wp->w_close_cb, &callback); 1015 set_callback(&wp->w_close_cb, &callback);
1004 if (callback.cb_free_name) 1016 if (callback.cb_free_name)
1005 vim_free(callback.cb_name); 1017 vim_free(callback.cb_name);
1018
1019 return OK;
1006 } 1020 }
1007 1021
1008 /* 1022 /*
1009 * Go through the options in "dict" and apply them to popup window "wp". 1023 * Go through the options in "dict" and apply them to popup window "wp".
1010 * "create" is TRUE when creating a new popup window. 1024 * "create" is TRUE when creating a new popup window.
1011 */ 1025 */
1012 static void 1026 static int
1013 apply_options(win_T *wp, dict_T *dict, int create) 1027 apply_options(win_T *wp, dict_T *dict, int create)
1014 { 1028 {
1015 int nr; 1029 int nr;
1016 1030
1017 apply_move_options(wp, dict); 1031 apply_move_options(wp, dict);
1018 1032
1019 if (create) 1033 if (create)
1020 set_string_option_direct_in_win(wp, (char_u *)"signcolumn", -1, 1034 set_string_option_direct_in_win(wp, (char_u *)"signcolumn", -1,
1021 (char_u *)"no", OPT_FREE|OPT_LOCAL, 0); 1035 (char_u *)"no", OPT_FREE|OPT_LOCAL, 0);
1022 1036
1023 apply_general_options(wp, dict); 1037 if (apply_general_options(wp, dict) == FAIL)
1038 return FAIL;
1024 1039
1025 nr = dict_get_bool(dict, "hidden", FALSE); 1040 nr = dict_get_bool(dict, "hidden", FALSE);
1026 if (nr > 0) 1041 if (nr > 0)
1027 wp->w_popup_flags |= POPF_HIDDEN | POPF_HIDDEN_FORCE; 1042 wp->w_popup_flags |= POPF_HIDDEN | POPF_HIDDEN_FORCE;
1028 1043
1039 wp->w_valid &= ~VALID_BOTLINE; 1054 wp->w_valid &= ~VALID_BOTLINE;
1040 } 1055 }
1041 1056
1042 popup_mask_refresh = TRUE; 1057 popup_mask_refresh = TRUE;
1043 popup_highlight_curline(wp); 1058 popup_highlight_curline(wp);
1059
1060 return OK;
1044 } 1061 }
1045 1062
1046 /* 1063 /*
1047 * Add lines to the popup from a list of strings. 1064 * Add lines to the popup from a list of strings.
1048 */ 1065 */
2277 wp->w_want_scrollbar = 1; 2294 wp->w_want_scrollbar = 1;
2278 wp->w_popup_fixed = 0; 2295 wp->w_popup_fixed = 0;
2279 wp->w_filter_mode = MODE_ALL; 2296 wp->w_filter_mode = MODE_ALL;
2280 2297
2281 if (d != NULL) 2298 if (d != NULL)
2299 {
2282 // Deal with options. 2300 // Deal with options.
2283 apply_options(wp, d, TRUE); 2301 if (apply_options(wp, d, TRUE) == FAIL)
2302 {
2303 (void)popup_close(wp->w_id, FALSE);
2304 return NULL;
2305 }
2306 }
2284 2307
2285 #ifdef FEAT_TIMERS 2308 #ifdef FEAT_TIMERS
2286 if (popup_is_notification(type) && wp->w_popup_timer == NULL) 2309 if (popup_is_notification(type) && wp->w_popup_timer == NULL)
2287 popup_add_timeout(wp, 3000, type == TYPE_NOTIFICATION); 2310 popup_add_timeout(wp, 3000, type == TYPE_NOTIFICATION);
2288 #endif 2311 #endif
2990 if (check_for_nonnull_dict_arg(argvars, 1) == FAIL) 3013 if (check_for_nonnull_dict_arg(argvars, 1) == FAIL)
2991 return; 3014 return;
2992 dict = argvars[1].vval.v_dict; 3015 dict = argvars[1].vval.v_dict;
2993 old_firstline = wp->w_firstline; 3016 old_firstline = wp->w_firstline;
2994 3017
2995 apply_options(wp, dict, FALSE); 3018 (void)apply_options(wp, dict, FALSE);
2996 3019
2997 if (old_firstline != wp->w_firstline) 3020 if (old_firstline != wp->w_firstline)
2998 redraw_win_later(wp, UPD_NOT_VALID); 3021 redraw_win_later(wp, UPD_NOT_VALID);
2999 popup_adjust_position(wp); 3022 popup_adjust_position(wp);
3000 } 3023 }