Patch 9.0.0096
Problem:    Flag "new_value_alloced" is always true.
Solution:   Remove "new_value_alloced". (closes #10792)
Files:      src/option.c, src/optionstr.c, src/proto/optionstr.pro


*** ../vim-9.0.0095/src/option.c        2022-07-27 12:30:08.405165929 +0100
--- src/option.c        2022-07-27 18:22:48.915661161 +0100
***************
*** 1716,1723 ****
  #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
--- 1716,1721 ----
***************
*** 1785,1797 ****
                                    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
                        {
--- 1783,1793 ----
***************
*** 2060,2066 ****
  
                            if (save_arg != NULL)   // number for 'whichwrap'
                                arg = save_arg;
-                           new_value_alloced = TRUE;
                        }
  
                        /*
--- 2056,2061 ----
***************
*** 2109,2116 ****
                            // '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_flags, &value_checked);
  
                            secure = secure_saved;
--- 2104,2110 ----
                            // 'syntax' or 'filetype' autocommands may be
                            // triggered that can cause havoc.
                            errmsg = did_set_string_option(
!                                   opt_idx, (char_u **)varp, oldval, errbuf,
                                    opt_flags, &value_checked);
  
                            secure = secure_saved;
*** ../vim-9.0.0095/src/optionstr.c     2022-07-04 21:03:33.107829279 +0100
--- src/optionstr.c     2022-07-27 18:22:48.915661161 +0100
***************
*** 537,543 ****
            saved_newval = vim_strsave(s);
        }
  #endif
!       if ((errmsg = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
                                           opt_flags, &value_checked)) == NULL)
            did_set_option(opt_idx, opt_flags, TRUE, value_checked);
  
--- 537,543 ----
            saved_newval = vim_strsave(s);
        }
  #endif
!       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,651 ****
  
  /*
   * Handle string options that need some action to perform when changed.
   * 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
--- 639,651 ----
  
  /*
   * 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
      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,1197 ****
            // When setting the global value to empty, make it "zip".
            if (*p_cm == NUL)
            {
!               if (new_value_alloced)
!                   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
--- 1188,1195 ----
            // When setting the global value to empty, make it "zip".
            if (*p_cm == NUL)
            {
!               free_string_option(p_cm);
                p_cm = vim_strsave((char_u *)"zip");
            }
            // 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,1448 ****
                t_colors = colors;
                if (t_colors <= 1)
                {
!                   if (new_value_alloced)
!                       vim_free(T_CCO);
                    T_CCO = empty_option;
                }
  #if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
--- 1439,1445 ----
                t_colors = colors;
                if (t_colors <= 1)
                {
!                   vim_free(T_CCO);
                    T_CCO = empty_option;
                }
  #if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
***************
*** 1511,1522 ****
            if (STRCMP(p, "*") == 0)
            {
                p = gui_mch_font_dialog(oldval);
! 
!               if (new_value_alloced)
!                   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)
--- 1508,1515 ----
            if (STRCMP(p, "*") == 0)
            {
                p = gui_mch_font_dialog(oldval);
!               free_string_option(p_guifont);
                p_guifont = (p != NULL) ? p : vim_strsave(oldval);
            }
  # endif
            if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
***************
*** 1526,1535 ****
                {
                    // Dialog was cancelled: Keep the old value without giving
                    // an error message.
!                   if (new_value_alloced)
!                       free_string_option(p_guifont);
                    p_guifont = vim_strsave(oldval);
-                   new_value_alloced = TRUE;
                }
                else
  # endif
--- 1519,1526 ----
                {
                    // Dialog was cancelled: Keep the old value without giving
                    // an error message.
!                   free_string_option(p_guifont);
                    p_guifont = vim_strsave(oldval);
                }
                else
  # endif
***************
*** 1950,1959 ****
                                      REPTERM_FROM_PART | REPTERM_DO_LT, NULL);
            if (p != NULL)
            {
!               if (new_value_alloced)
!                   free_string_option(p_pt);
                p_pt = p;
-               new_value_alloced = TRUE;
            }
        }
      }
--- 1941,1948 ----
                                      REPTERM_FROM_PART | REPTERM_DO_LT, NULL);
            if (p != NULL)
            {
!               free_string_option(p_pt);
                p_pt = p;
            }
        }
      }
***************
*** 2369,2378 ****
            name = get_scriptlocal_funcname(*p_opt);
            if (name != NULL)
            {
!               if (new_value_alloced)
!                   free_string_option(*p_opt);
                *p_opt = name;
-               new_value_alloced = TRUE;
            }
        }
  
--- 2358,2365 ----
            name = get_scriptlocal_funcname(*p_opt);
            if (name != NULL)
            {
!               free_string_option(*p_opt);
                *p_opt = name;
            }
        }
  
***************
*** 2486,2493 ****
      // If error detected, restore the previous value.
      if (errmsg != NULL)
      {
!       if (new_value_alloced)
!           free_string_option(*varp);
        *varp = oldval;
        // When resetting some values, need to act on it.
        if (did_chartab)
--- 2473,2479 ----
      // If error detected, restore the previous value.
      if (errmsg != NULL)
      {
!       free_string_option(*varp);
        *varp = oldval;
        // When resetting some values, need to act on it.
        if (did_chartab)
***************
*** 2506,2515 ****
        // 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);
  
        if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
                && is_global_local_option(opt_idx))
--- 2492,2498 ----
        // our fingers (esp. init_highlight()).
        if (free_oldval)
            free_string_option(oldval);
!       set_option_flag(opt_idx, P_ALLOCED);
  
        if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
                && is_global_local_option(opt_idx))
*** ../vim-9.0.0095/src/proto/optionstr.pro     2022-06-27 23:15:18.000000000 
+0100
--- src/proto/optionstr.pro     2022-07-27 18:22:48.915661161 +0100
***************
*** 9,14 ****
  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);
  int check_ff_value(char_u *p);
  /* vim: set ft=c : */
--- 9,14 ----
  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, char_u *oldval, char 
*errbuf, int opt_flags, int *value_checked);
  int check_ff_value(char_u *p);
  /* vim: set ft=c : */
*** ../vim-9.0.0095/src/version.c       2022-07-27 15:48:42.343954974 +0100
--- src/version.c       2022-07-27 18:22:44.347707906 +0100
***************
*** 737,738 ****
--- 737,740 ----
  {   /* Add new patch number below this line */
+ /**/
+     96,
  /**/

-- 
hundred-and-one symptoms of being an internet addict:
153. You find yourself staring at your "inbox" waiting for new e-mail
     to arrive.

 /// 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/20220727172633.81F361C0A39%40moolenaar.net.

Raspunde prin e-mail lui