Mercurial > vim
changeset 29509:d61007cc39b3 v9.0.0096
patch 9.0.0096: flag "new_value_alloced" is always true
Commit: https://github.com/vim/vim/commit/f6782732ab4acd02211923fbdccb457dacaf277e
Author: zeertzjq <zeertzjq@outlook.com>
Date: Wed Jul 27 18:26:03 2022 +0100
patch 9.0.0096: flag "new_value_alloced" is always true
Problem: Flag "new_value_alloced" is always true.
Solution: Remove "new_value_alloced". (closes https://github.com/vim/vim/issues/10792)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 27 Jul 2022 19:30:03 +0200 |
parents | 10d69d910f49 |
children | 0acbd5c55267 |
files | src/option.c src/optionstr.c src/proto/optionstr.pro src/version.c |
diffstat | 4 files changed, 14 insertions(+), 35 deletions(-) [+] |
line wrap: on
line diff
--- a/src/option.c +++ b/src/option.c @@ -1716,8 +1716,6 @@ do_set( #endif unsigned newlen; int comma; - int new_value_alloced; // new string option - // was allocated // When using ":set opt=val" for a global option // with a local value the local value will be @@ -1785,13 +1783,11 @@ do_set( s = newval; newval = vim_strsave(s); } - new_value_alloced = TRUE; } else if (nextchar == '<') // set to global val { newval = vim_strsave(*(char_u **)get_varp_scope( &(options[opt_idx]), OPT_GLOBAL)); - new_value_alloced = TRUE; } else { @@ -2060,7 +2056,6 @@ do_set( if (save_arg != NULL) // number for 'whichwrap' arg = save_arg; - new_value_alloced = TRUE; } /* @@ -2109,8 +2104,7 @@ do_set( // 'syntax' or 'filetype' autocommands may be // triggered that can cause havoc. errmsg = did_set_string_option( - opt_idx, (char_u **)varp, - new_value_alloced, oldval, errbuf, + opt_idx, (char_u **)varp, oldval, errbuf, opt_flags, &value_checked); secure = secure_saved;
--- a/src/optionstr.c +++ b/src/optionstr.c @@ -537,7 +537,7 @@ set_string_option( saved_newval = vim_strsave(s); } #endif - if ((errmsg = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL, + if ((errmsg = did_set_string_option(opt_idx, varp, oldval, NULL, opt_flags, &value_checked)) == NULL) did_set_option(opt_idx, opt_flags, TRUE, value_checked); @@ -639,13 +639,13 @@ check_stl_option(char_u *s) /* * Handle string options that need some action to perform when changed. + * The new value must be allocated. * Returns NULL for success, or an unstranslated error message for an error. */ char * did_set_string_option( int opt_idx, // index in options[] table char_u **varp, // pointer to the option variable - int new_value_alloced, // new value was allocated char_u *oldval, // previous value of the option char *errbuf, // buffer for errors, or NULL int opt_flags, // OPT_LOCAL and/or OPT_GLOBAL @@ -1188,10 +1188,8 @@ ambw_end: // When setting the global value to empty, make it "zip". if (*p_cm == NUL) { - if (new_value_alloced) - free_string_option(p_cm); + free_string_option(p_cm); p_cm = vim_strsave((char_u *)"zip"); - new_value_alloced = TRUE; } // When using ":set cm=name" the local value is going to be empty. // Do that here, otherwise the crypt functions will still use the @@ -1441,8 +1439,7 @@ ambw_end: t_colors = colors; if (t_colors <= 1) { - if (new_value_alloced) - vim_free(T_CCO); + vim_free(T_CCO); T_CCO = empty_option; } #if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS) @@ -1511,12 +1508,8 @@ ambw_end: if (STRCMP(p, "*") == 0) { p = gui_mch_font_dialog(oldval); - - if (new_value_alloced) - free_string_option(p_guifont); - + free_string_option(p_guifont); p_guifont = (p != NULL) ? p : vim_strsave(oldval); - new_value_alloced = TRUE; } # endif if (p != NULL && gui_init_font(p_guifont, FALSE) != OK) @@ -1526,10 +1519,8 @@ ambw_end: { // Dialog was cancelled: Keep the old value without giving // an error message. - if (new_value_alloced) - free_string_option(p_guifont); + free_string_option(p_guifont); p_guifont = vim_strsave(oldval); - new_value_alloced = TRUE; } else # endif @@ -1950,10 +1941,8 @@ ambw_end: REPTERM_FROM_PART | REPTERM_DO_LT, NULL); if (p != NULL) { - if (new_value_alloced) - free_string_option(p_pt); + free_string_option(p_pt); p_pt = p; - new_value_alloced = TRUE; } } } @@ -2369,10 +2358,8 @@ ambw_end: name = get_scriptlocal_funcname(*p_opt); if (name != NULL) { - if (new_value_alloced) - free_string_option(*p_opt); + free_string_option(*p_opt); *p_opt = name; - new_value_alloced = TRUE; } } @@ -2486,8 +2473,7 @@ ambw_end: // If error detected, restore the previous value. if (errmsg != NULL) { - if (new_value_alloced) - free_string_option(*varp); + free_string_option(*varp); *varp = oldval; // When resetting some values, need to act on it. if (did_chartab) @@ -2506,10 +2492,7 @@ ambw_end: // our fingers (esp. init_highlight()). if (free_oldval) free_string_option(oldval); - if (new_value_alloced) - set_option_flag(opt_idx, P_ALLOCED); - else - clear_option_flag(opt_idx, P_ALLOCED); + set_option_flag(opt_idx, P_ALLOCED); if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0 && is_global_local_option(opt_idx))
--- a/src/proto/optionstr.pro +++ b/src/proto/optionstr.pro @@ -9,6 +9,6 @@ void set_string_option_direct(char_u *na void set_string_option_direct_in_win(win_T *wp, char_u *name, int opt_idx, char_u *val, int opt_flags, int set_sid); void set_string_option_direct_in_buf(buf_T *buf, char_u *name, int opt_idx, char_u *val, int opt_flags, int set_sid); char *set_string_option(int opt_idx, char_u *value, int opt_flags); -char *did_set_string_option(int opt_idx, char_u **varp, int new_value_alloced, char_u *oldval, char *errbuf, int opt_flags, int *value_checked); +char *did_set_string_option(int opt_idx, char_u **varp, char_u *oldval, char *errbuf, int opt_flags, int *value_checked); int check_ff_value(char_u *p); /* vim: set ft=c : */