changeset 30409:aea53db7eeec v9.0.0540

patch 9.0.0540: assigning stack variable to argument confuses Coverity Commit: https://github.com/vim/vim/commit/6f98114e4a5db3917c4f9d2fec09e11b4b0d0be5 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Sep 22 12:48:58 2022 +0100 patch 9.0.0540: assigning stack variable to argument confuses Coverity Problem: Assigning stack variable to argument confuses Coverity. Solution: Use a local pointer, also makes the code simpler.
author Bram Moolenaar <Bram@vim.org>
date Thu, 22 Sep 2022 14:00:08 +0200
parents 6e69efa182cb
children dce60925aaba
files src/option.c src/version.c
diffstat 2 files changed, 28 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/src/option.c
+++ b/src/option.c
@@ -1220,7 +1220,7 @@ typedef enum {
 do_set_string(
 	int	    opt_idx,
 	int	    opt_flags,
-	char_u	    **arg,
+	char_u	    **argp,
 	int	    nextchar,
 	set_op_T    op_arg,
 	int	    flags,
@@ -1230,6 +1230,7 @@ do_set_string(
 	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,18 +1318,18 @@ do_set_string(
     }
     else
     {
-	++*arg;	// jump to after the '=' or ':'
+	++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 == ' '))
+	if (varp == (char_u *)&p_kp && (*arg == NUL || *arg == ' '))
 	{
 	    STRCPY(errbuf, ":help");
-	    save_arg = *arg;
-	    *arg = (char_u *)errbuf;
+	    save_arg = arg;
+	    arg = (char_u *)errbuf;
 	}
 	/*
 	 * Convert 'backspace' number to string, for
@@ -1368,10 +1369,10 @@ do_set_string(
 	 * Convert 'whichwrap' number to string, for backwards compatibility
 	 * with Vim 3.0.
 	 */
-	else if (varp == (char_u *)&p_ww && VIM_ISDIGIT(**arg))
+	else if (varp == (char_u *)&p_ww && VIM_ISDIGIT(*arg))
 	{
 	    *whichwrap = NUL;
-	    int i = getdigits(arg);
+	    int i = getdigits(&arg);
 	    if (i & 1)
 		STRCAT(whichwrap, "b,");
 	    if (i & 2)
@@ -1384,16 +1385,16 @@ do_set_string(
 		STRCAT(whichwrap, "[,],");
 	    if (*whichwrap != NUL)	// remove trailing ,
 		whichwrap[STRLEN(whichwrap) - 1] = NUL;
-	    save_arg = *arg;
-	    *arg = (char_u *)whichwrap;
+	    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
+	else if (*arg == '>' && (varp == (char_u *)&p_dir
 						 || varp == (char_u *)&p_bdir))
-	    ++*arg;
+	    ++arg;
 
 	/*
 	 * Copy the new string into allocated memory.
@@ -1401,7 +1402,7 @@ do_set_string(
 	 * backslashes.
 	 */
 	// get a bit too much
-	newlen = (unsigned)STRLEN(*arg) + 1;
+	newlen = (unsigned)STRLEN(arg) + 1;
 	if (op != OP_NONE)
 	    newlen += (unsigned)STRLEN(origval) + 1;
 	newval = alloc(newlen);
@@ -1416,29 +1417,29 @@ do_set_string(
 	 * but do remove it for "\\\\machine\\path".
 	 * The reverse is found in ExpandOldSetting().
 	 */
-	while (**arg && !VIM_ISWHITE(**arg))
+	while (*arg && !VIM_ISWHITE(*arg))
 	{
 	    int i;
 
-	    if (**arg == '\\' && (*arg)[1] != NUL
+	    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] != '\\')))
+			    && 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)
+		++arg;	// remove backslash
+	    if (has_mbyte && (i = (*mb_ptr2len)(arg)) > 1)
 	    {
 		// copy multibyte char
-		mch_memmove(s, *arg, (size_t)i);
-		*arg += i;
+		mch_memmove(s, arg, (size_t)i);
+		arg += i;
 		s += i;
 	    }
 	    else
-		*s++ = *(*arg)++;
+		*s++ = *arg++;
 	}
 	*s = NUL;
 
@@ -1565,7 +1566,7 @@ do_set_string(
 	}
 
 	if (save_arg != NULL)   // number for 'whichwrap'
-	    *arg = save_arg;
+	    arg = save_arg;
     }
 
     /*
@@ -1627,6 +1628,7 @@ do_set_string(
     vim_free(saved_newval);
 #endif
 
+    *argp = arg;
     return *errmsg == NULL ? OK : FAIL;
 }
 
--- a/src/version.c
+++ b/src/version.c
@@ -700,6 +700,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    540,
+/**/
     539,
 /**/
     538,