From 0b5b06cb4777d1401fdf83e7d48d287662236e7e Mon Sep 17 00:00:00 2001
From: Bram Moolenaar <Bram@vim.org>
Date: Thu, 4 Nov 2021 15:10:11 +0000
Subject: [PATCH] patch 8.2.3581: reading character past end of line

Problem:    Reading character past end of line.
Solution:   Correct the cursor column.
---
 src/ex_docmd.c           | 1 +
 src/testdir/test_put.vim | 9 +++++++++
 2 files changed, 10 insertions(+)

diff --git a/src/ex_docmd.c b/src/ex_docmd.c
index 12554fa..203174a 100644
--- a/src/ex_docmd.c
+++ b/src/ex_docmd.c
@@ -6906,6 +6906,7 @@ ex_put(exarg_T *eap)
 	eap->forceit = TRUE;
     }
     curwin->w_cursor.lnum = eap->line2;
+    check_cursor_col();
     do_put(eap->regname, eap->forceit ? BACKWARD : FORWARD, 1L,
 						       PUT_LINE|PUT_CURSLINE);
 }
diff --git a/src/testdir/test_put.vim b/src/testdir/test_put.vim
index 225ebd1..f5037dc 100644
--- a/src/testdir/test_put.vim
+++ b/src/testdir/test_put.vim
@@ -113,3 +113,12 @@ func Test_put_p_indent_visual()
   call assert_equal('select that text', getline(2))
   bwipe!
 endfunc
+
+func Test_put_above_first_line()
+  new
+  let @" = 'text'
+  silent! normal 0o00
+  0put
+  call assert_equal('text', getline(1))
+  bwipe!
+endfunc
-- 
1.8.3.1

