]> granicus.if.org Git - vim/commitdiff
patch 8.2.1482: Vim9: crash when using a nested lambda v8.2.1482
authorBram Moolenaar <Bram@vim.org>
Tue, 18 Aug 2020 20:32:03 +0000 (22:32 +0200)
committerBram Moolenaar <Bram@vim.org>
Tue, 18 Aug 2020 20:32:03 +0000 (22:32 +0200)
Problem:    Vim9: crash when using a nested lambda.
Solution:   Do not clear the growarray when not evaluating.  Correct pointer
when getting the next line. (closes #6731)

src/eval.c
src/scriptfile.c
src/testdir/test_vim9_expr.vim
src/version.c

index 585975a80892ad7228060b0e8f0989697a9039d8..69f9f21e8a12fd2536455f325158f7dc59390df4 100644 (file)
@@ -397,8 +397,10 @@ skip_expr_concatenate(
     int                vim9script = in_vim9script();
     garray_T    *gap = &evalarg->eval_ga;
     int                save_flags = evalarg == NULL ? 0 : evalarg->eval_flags;
+    int                evaluate = evalarg == NULL
+                              ? FALSE : (evalarg->eval_flags & EVAL_EVALUATE);
 
-    if (vim9script
+    if (vim9script && evaluate
               && (evalarg->eval_cookie != NULL || evalarg->eval_cctx != NULL))
     {
        ga_init2(gap, sizeof(char_u *), 10);
@@ -417,7 +419,7 @@ skip_expr_concatenate(
     if (evalarg != NULL)
        evalarg->eval_flags = save_flags;
 
-    if (vim9script
+    if (vim9script && evaluate
            && (evalarg->eval_cookie != NULL || evalarg->eval_cctx != NULL))
     {
        if (evalarg->eval_ga.ga_len == 1)
@@ -5425,6 +5427,7 @@ handle_subscript(
                                     && (p[2] == '{' || ASCII_ISALPHA(p[2])))))
        {
            *arg = eval_next_line(evalarg);
+           p = *arg;
            check_white = FALSE;
        }
 
index fee29712c51007f9175dc16b3ed43a115910e4ca..4df2c31fe6039ac8782ada4a2ffbe30d688cbe06 100644 (file)
@@ -1065,7 +1065,8 @@ source_level(void *cookie)
 }
 
 /*
- * Return the readahead line.
+ * Return the readahead line. Note that the pointer may become invalid when
+ * getting the next line, if it's concatenated with the next one.
  */
     char_u *
 source_nextline(void *cookie)
index db899ee4d0afaa4d37535b4084123d53cecad864..2c88efbac04126d359c712a02e37f6f71101ad24 100644 (file)
@@ -1624,6 +1624,15 @@ def Test_expr7_lambda_vim9script()
       assert_equal(12, v)
   END
   CheckScriptSuccess(lines)
+
+  # nested lambda with line breaks
+  lines =<< trim END
+      vim9script
+      search('"', 'cW', 0, 0, {->
+       synstack('.', col('.'))
+       ->map({_, v -> synIDattr(v, 'name')})->len()})
+  END
+  CheckScriptSuccess(lines)
 enddef
 
 def Test_expr7_dict()
index 130d4bc6f9f27f035d191f2825748b97734263c1..a7fe8d46a9a1f344bca1a40cfc26ea204e90fd3b 100644 (file)
@@ -754,6 +754,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1482,
 /**/
     1481,
 /**/