]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.0.1482: crash when textprop has a very large "padding" value v9.0.1482
authorBram Moolenaar <Bram@vim.org>
Sun, 23 Apr 2023 20:42:25 +0000 (21:42 +0100)
committerBram Moolenaar <Bram@vim.org>
Sun, 23 Apr 2023 20:42:25 +0000 (21:42 +0100)
Problem:    Crash when textprop has a very large "padding" value. (Yegappan
            Lakshmanan)
Solution:   Avoid the "after" count to go negative.

src/drawline.c
src/testdir/dumps/Test_prop_above_padding_1.dump [new file with mode: 0644]
src/testdir/test_textprop.vim
src/version.c

index c7510a65a2408fc5a910d502194bb00593114eb3..f3d70ed833e484c1fb02ac19b58d8883a38e7dab 100644 (file)
@@ -665,6 +665,12 @@ text_prop_position(
        {
            before = 0;
            after = wp->w_width - cells - win_col_off(wp) - padding;
+           if (after < 0)
+           {
+               // text "above" has too much padding to fit
+               padding += after;
+               after = 0;
+           }
        }
        else
        {
diff --git a/src/testdir/dumps/Test_prop_above_padding_1.dump b/src/testdir/dumps/Test_prop_above_padding_1.dump
new file mode 100644 (file)
index 0000000..1940542
--- /dev/null
@@ -0,0 +1,8 @@
+> +0&#ffffff0@74
+|s|k|y| |i|s| |b|l|u|e| @63
+@74|…
+|o|c|e|a|n| |i|s| |b|l|u|e| @61
+|~+0#4040ff13&| @73
+|~| @73
+|~| @73
+| +0#0000000&@56|1|,|0|-|1| @8|A|l@1| 
index 9cd09bd1bb2133ffeb0d2f7f5c5104e9d451e23c..550a0e5af570c6c2c5767a39dadb128505b5445d 100644 (file)
@@ -3199,6 +3199,26 @@ func Test_props_with_text_above()
   call StopVimInTerminal(buf)
 endfunc
 
+func Test_prop_with_text_above_padding()
+  CheckRunVimInTerminal
+
+  let lines =<< trim END
+      vim9script
+
+      setlocal tabstop=8 noexpandtab
+      setline(1, ['', 'sky is blue', 'ocean is blue'])
+      prop_type_add('DiagVirtualText', {highlight: 'Search', override: true})
+      prop_add(3, 0, {text: "┌─ start", text_align: "above",
+               type: 'DiagVirtualText',
+               text_padding_left: 200})
+  END
+  call writefile(lines, 'XscriptAbovePadding', 'D')
+  let buf = RunVimInTerminal('-S XscriptAbovePadding', #{rows: 8})
+  call VerifyScreenDump(buf, 'Test_prop_above_padding_1', {})
+
+  call StopVimInTerminal(buf)
+endfunc
+
 func Test_prop_above_with_indent()
   new
   call setline(1, ['first line', '    second line', '    line below'])
index a87121f908a92d8d44255646d29b8ba8fe123b1d..aa480c1699686c63458b2acb0fb4879a81b77e05 100644 (file)
@@ -695,6 +695,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1482,
 /**/
     1481,
 /**/