summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2023-04-23 21:42:25 +0100
committerBram Moolenaar <Bram@vim.org>2023-04-23 21:42:25 +0100
commit2354b66ac52a8a9165e8bd0d642e19e757ba12c3 (patch)
tree1233f7470292cf4b72583d7ad9fbe0595a290f93
parentaae583441bcdbb0bfef3b8a1d193e04ae09ca95d (diff)
downloadvim-git-9.0.1482.tar.gz
patch 9.0.1482: crash when textprop has a very large "padding" valuev9.0.1482
Problem: Crash when textprop has a very large "padding" value. (Yegappan Lakshmanan) Solution: Avoid the "after" count to go negative.
-rw-r--r--src/drawline.c6
-rw-r--r--src/testdir/dumps/Test_prop_above_padding_1.dump8
-rw-r--r--src/testdir/test_textprop.vim20
-rw-r--r--src/version.c2
4 files changed, 36 insertions, 0 deletions
diff --git a/src/drawline.c b/src/drawline.c
index c7510a65a..f3d70ed83 100644
--- a/src/drawline.c
+++ b/src/drawline.c
@@ -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
index 000000000..1940542eb
--- /dev/null
+++ b/src/testdir/dumps/Test_prop_above_padding_1.dump
@@ -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|
diff --git a/src/testdir/test_textprop.vim b/src/testdir/test_textprop.vim
index 9cd09bd1b..550a0e5af 100644
--- a/src/testdir/test_textprop.vim
+++ b/src/testdir/test_textprop.vim
@@ -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'])
diff --git a/src/version.c b/src/version.c
index a87121f90..aa480c169 100644
--- a/src/version.c
+++ b/src/version.c
@@ -696,6 +696,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1482,
+/**/
1481,
/**/
1480,