]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.1041: Vim9: out-of-bound access when echoing an enum v9.1.1041
authorYegappan Lakshmanan <yegappan@yahoo.com>
Mon, 20 Jan 2025 20:38:09 +0000 (21:38 +0100)
committerChristian Brabandt <cb@256bit.org>
Mon, 20 Jan 2025 20:38:09 +0000 (21:38 +0100)
Problem:  Vim9: out-of-bound access when echoing an enum
Solution: Add NUL to growarray, check that ufunc is non-null
          before accessing it to make Coverity happy
          (Yegappan Lakshmanan)

closes: #16488

Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/testdir/test_vim9_enum.vim
src/version.c
src/vim9class.c
src/vim9expr.c

index 74eb468805bcfb41b52ca17e3ebb6cb268f9c48f..de26259d49fe0f3a99df1729983bd3f0e14111e5 100644 (file)
@@ -1586,4 +1586,19 @@ def Test_lambda_block_in_enum()
   v9.CheckScriptSuccess(lines)
 enddef
 
+" Echo an enum
+def Test_enum_echo()
+  var lines =<< trim END
+    vim9script
+    enum Demo
+      one('tahi'),
+      two('rua'),
+      three('toru')
+      var alias: string
+    endenum
+    assert_equal('enum Demo.one {name: one, ordinal: 0, alias: tahi}', execute('echo Demo.one')->split("\n")[0])
+  END
+  v9.CheckScriptSuccess(lines)
+enddef
+
 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker
index 8e5315957980114c28f5ac0e220fc45a7e6ad9ea..5b3683ddd8165e711f1521e7a3edff8dc79bc696 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1041,
 /**/
     1040,
 /**/
index c3ccf0250a5fc772c12df0cf17be8ff71dc91a84..e847bf086407463cb740216706b7bdbb55572f06 100644 (file)
@@ -4054,6 +4054,7 @@ object2string(
        vim_free(ga.ga_data);
        return NULL;
     }
+    ga_append(&ga, NUL);
     return (char_u *)ga.ga_data;
 }
 
index 7b8c96adbd00bca3fd0a376c36acbaef96c3a44f..b76544869cce599621b219116c716a20971af9d9 100644 (file)
@@ -406,7 +406,7 @@ compile_class_object_index(cctx_T *cctx, char_u **arg, type_T *type)
            }
        }
 
-       if (is_super && IS_ABSTRACT_METHOD(ufunc))
+       if (is_super && ufunc != NULL && IS_ABSTRACT_METHOD(ufunc))
        {
            // Trying to invoke an abstract method in a super class is not
            // allowed.