]> granicus.if.org Git - vim/commitdiff
patch 9.0.1286: Coverity warns for using a NULL pointer v9.0.1286
authorBram Moolenaar <Bram@vim.org>
Mon, 6 Feb 2023 16:40:49 +0000 (16:40 +0000)
committerBram Moolenaar <Bram@vim.org>
Mon, 6 Feb 2023 16:40:49 +0000 (16:40 +0000)
Problem:    Coverity warns for using a NULL pointer.
Solution:   Bail out whan "varp" is NULL.

src/option.c
src/version.c

index 420d36d05c239831255267d928403a502d736756..66d681e48fff57935b51ae4a5647757aa5961dd6 100644 (file)
@@ -1815,7 +1815,8 @@ do_set_string(
 }
 
 /*
- * Set a boolean option
+ * Set a boolean option.
+ * Returns an untranslated error message or NULL.
  */
     static char *
 do_set_option_bool(
@@ -1833,6 +1834,8 @@ do_set_option_bool(
 
     if (nextchar == '=' || nextchar == ':')
        return e_invalid_argument;
+    if (opt_idx < 0 || varp == NULL)
+       return NULL;  // "cannot happen"
 
     /*
      * ":set opt!": invert
@@ -1870,7 +1873,8 @@ do_set_option_bool(
 }
 
 /*
- * Set a numeric option
+ * Set a numeric option.
+ * Returns an untranslated error message or NULL.
  */
     static char *
 do_set_option_numeric(
@@ -1890,6 +1894,9 @@ do_set_option_numeric(
     int                        i;
     char               *errmsg = NULL;
 
+    if (opt_idx < 0 || varp == NULL)
+       return NULL;  // "cannot happen"
+                     //
     /*
      * Different ways to set a number option:
      * &           set to default value
@@ -2209,8 +2216,8 @@ do_set_option(
     }
 
     /*
-     * allow '=' and ':' for historical reasons (MSDOS command.com
-     * allows only one '=' character per "set" command line. grrr. (jw)
+     * Allow '=' and ':' for historical reasons (MSDOS command.com).
+     * Allows only one '=' character per "set" command line. grrr. (jw)
      */
     if (nextchar == '?'
            || (prefix == PREFIX_NONE
index 7c85a97e610bcf43e937dd4214e8ba4b45c57522..439698b32c5db1fb81fba1f5df7b19d66002e47f 100644 (file)
@@ -695,6 +695,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1286,
 /**/
     1285,
 /**/