Patch 9.0.0540
Problem:    Assigning stack variable to argument confuses Coverity.
Solution:   Use a local pointer, also makes the code simpler.
Files:      src/option.c


*** ../vim-9.0.0539/src/option.c        2022-09-21 21:12:49.565277810 +0100
--- src/option.c        2022-09-22 12:43:47.610688098 +0100
***************
*** 1220,1226 ****
  do_set_string(
        int         opt_idx,
        int         opt_flags,
!       char_u      **arg,
        int         nextchar,
        set_op_T    op_arg,
        int         flags,
--- 1220,1226 ----
  do_set_string(
        int         opt_idx,
        int         opt_flags,
!       char_u      **argp,
        int         nextchar,
        set_op_T    op_arg,
        int         flags,
***************
*** 1230,1235 ****
--- 1230,1236 ----
        int         *value_checked,
        char        **errmsg)
  {
+     char_u    *arg = *argp;
      set_op_T    op = op_arg;
      char_u    *varp = varp_arg;
      char_u    *save_arg = NULL;
***************
*** 1317,1334 ****
      }
      else
      {
!       ++*arg; // jump to after the '=' or ':'
  
        /*
         * Set 'keywordprg' to ":help" if an empty
         * value was passed to :set by the user.
         * Misuse errbuf[] for the resulting string.
         */
!       if (varp == (char_u *)&p_kp && (**arg == NUL || **arg == ' '))
        {
            STRCPY(errbuf, ":help");
!           save_arg = *arg;
!           *arg = (char_u *)errbuf;
        }
        /*
         * Convert 'backspace' number to string, for
--- 1318,1335 ----
      }
      else
      {
!       ++arg;  // jump to after the '=' or ':'
  
        /*
         * Set 'keywordprg' to ":help" if an empty
         * value was passed to :set by the user.
         * Misuse errbuf[] for the resulting string.
         */
!       if (varp == (char_u *)&p_kp && (*arg == NUL || *arg == ' '))
        {
            STRCPY(errbuf, ":help");
!           save_arg = arg;
!           arg = (char_u *)errbuf;
        }
        /*
         * Convert 'backspace' number to string, for
***************
*** 1368,1377 ****
         * Convert 'whichwrap' number to string, for backwards compatibility
         * with Vim 3.0.
         */
!       else if (varp == (char_u *)&p_ww && VIM_ISDIGIT(**arg))
        {
            *whichwrap = NUL;
!           int i = getdigits(arg);
            if (i & 1)
                STRCAT(whichwrap, "b,");
            if (i & 2)
--- 1369,1378 ----
         * Convert 'whichwrap' number to string, for backwards compatibility
         * with Vim 3.0.
         */
!       else if (varp == (char_u *)&p_ww && VIM_ISDIGIT(*arg))
        {
            *whichwrap = NUL;
!           int i = getdigits(&arg);
            if (i & 1)
                STRCAT(whichwrap, "b,");
            if (i & 2)
***************
*** 1384,1399 ****
                STRCAT(whichwrap, "[,],");
            if (*whichwrap != NUL)      // remove trailing ,
                whichwrap[STRLEN(whichwrap) - 1] = NUL;
!           save_arg = *arg;
!           *arg = (char_u *)whichwrap;
        }
        /*
         * Remove '>' before 'dir' and 'bdir', for backwards compatibility with
         * version 3.0
         */
!       else if (  **arg == '>' && (varp == (char_u *)&p_dir
                                                 || varp == (char_u *)&p_bdir))
!           ++*arg;
  
        /*
         * Copy the new string into allocated memory.
--- 1385,1400 ----
                STRCAT(whichwrap, "[,],");
            if (*whichwrap != NUL)      // remove trailing ,
                whichwrap[STRLEN(whichwrap) - 1] = NUL;
!           save_arg = arg;
!           arg = (char_u *)whichwrap;
        }
        /*
         * Remove '>' before 'dir' and 'bdir', for backwards compatibility with
         * version 3.0
         */
!       else if (*arg == '>' && (varp == (char_u *)&p_dir
                                                 || varp == (char_u *)&p_bdir))
!           ++arg;
  
        /*
         * Copy the new string into allocated memory.
***************
*** 1401,1407 ****
         * backslashes.
         */
        // get a bit too much
!       newlen = (unsigned)STRLEN(*arg) + 1;
        if (op != OP_NONE)
            newlen += (unsigned)STRLEN(origval) + 1;
        newval = alloc(newlen);
--- 1402,1408 ----
         * backslashes.
         */
        // get a bit too much
!       newlen = (unsigned)STRLEN(arg) + 1;
        if (op != OP_NONE)
            newlen += (unsigned)STRLEN(origval) + 1;
        newval = alloc(newlen);
***************
*** 1416,1444 ****
         * but do remove it for "\\\\machine\\path".
         * The reverse is found in ExpandOldSetting().
         */
!       while (**arg && !VIM_ISWHITE(**arg))
        {
            int i;
  
!           if (**arg == '\\' && (*arg)[1] != NUL
  #ifdef BACKSLASH_IN_FILENAME
                    && !((flags & P_EXPAND)
!                           && vim_isfilec((*arg)[1])
!                           && !VIM_ISWHITE((*arg)[1])
!                           && ((*arg)[1] != '\\'
!                                       || (s == newval && (*arg)[2] != '\\')))
  #endif
                                                )
!               ++*arg; // remove backslash
!           if (has_mbyte && (i = (*mb_ptr2len)(*arg)) > 1)
            {
                // copy multibyte char
!               mch_memmove(s, *arg, (size_t)i);
!               *arg += i;
                s += i;
            }
            else
!               *s++ = *(*arg)++;
        }
        *s = NUL;
  
--- 1417,1445 ----
         * but do remove it for "\\\\machine\\path".
         * The reverse is found in ExpandOldSetting().
         */
!       while (*arg && !VIM_ISWHITE(*arg))
        {
            int i;
  
!           if (*arg == '\\' && arg[1] != NUL
  #ifdef BACKSLASH_IN_FILENAME
                    && !((flags & P_EXPAND)
!                           && vim_isfilec(arg[1])
!                           && !VIM_ISWHITE(arg[1])
!                           && (arg[1] != '\\'
!                                       || (s == newval && arg[2] != '\\')))
  #endif
                                                )
!               ++arg;  // remove backslash
!           if (has_mbyte && (i = (*mb_ptr2len)(arg)) > 1)
            {
                // copy multibyte char
!               mch_memmove(s, arg, (size_t)i);
!               arg += i;
                s += i;
            }
            else
!               *s++ = *arg++;
        }
        *s = NUL;
  
***************
*** 1565,1571 ****
        }
  
        if (save_arg != NULL)   // number for 'whichwrap'
!           *arg = save_arg;
      }
  
      /*
--- 1566,1572 ----
        }
  
        if (save_arg != NULL)   // number for 'whichwrap'
!           arg = save_arg;
      }
  
      /*
***************
*** 1627,1632 ****
--- 1628,1634 ----
      vim_free(saved_newval);
  #endif
  
+     *argp = arg;
      return *errmsg == NULL ? OK : FAIL;
  }
  
*** ../vim-9.0.0539/src/version.c       2022-09-22 12:01:27.254151371 +0100
--- src/version.c       2022-09-22 12:48:27.506436105 +0100
***************
*** 701,702 ****
--- 701,704 ----
  {   /* Add new patch number below this line */
+ /**/
+     540,
  /**/

-- 
hundred-and-one symptoms of being an internet addict:
129. You cancel your newspaper subscription.

 /// 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/20220922114929.6FE161C0602%40moolenaar.net.

Raspunde prin e-mail lui