Skip to content

Commit 25fd267

Browse files
committed
patch 8.2.1039: cannot put NUL byte on clipboard
Problem: Cannot put NUL byte on clipboard. Solution: Use the text length. (Christian Brabandt, closes #6312, closes #6149)
1 parent b2b218d commit 25fd267

3 files changed

Lines changed: 22 additions & 2 deletions

File tree

src/testdir/test_registers.vim

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,4 +641,22 @@ func Test_execute_reg_as_ex_cmd()
641641
call assert_equal(repeat('abcdefghijklmnopqrstuvwxyz', 312), str)
642642
endfunc
643643

644+
" Test for clipboard registers with ASCII NUL
645+
func Test_clipboard_nul()
646+
CheckFeature clipboard_working
647+
new
648+
649+
" Test for putting ASCII NUL into the clipboard
650+
set clipboard=unnamed
651+
call append(0, "\ntest")
652+
normal ggyyp
653+
call assert_equal("^@test^@", strtrans(getreg('*')))
654+
call assert_equal(getline(1), getline(2))
655+
let b = split(execute(":reg *"), "\n")
656+
call assert_match('"\*\s*\^@test\^J',b[1])
657+
658+
set clipboard&vim
659+
bwipe!
660+
endfunc
661+
644662
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,8 @@ static char *(features[]) =
754754

755755
static int included_patches[] =
756756
{ /* Add new patch number below this line */
757+
/**/
758+
1039,
757759
/**/
758760
1038,
759761
/**/

src/winclip.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ clip_mch_request_selection(Clipboard_T *cbd)
422422
}
423423
}
424424

425-
if (str != NULL && *str != NUL)
425+
if (str != NULL && metadata.txtlen != 0)
426426
{
427427
char_u *temp_clipboard;
428428

@@ -543,7 +543,7 @@ clip_mch_set_selection(Clipboard_T *cbd)
543543

544544
if (lpszMem)
545545
{
546-
vim_strncpy((char_u *)lpszMem, str, metadata.txtlen);
546+
mch_memmove((char_u *)lpszMem, str, metadata.txtlen);
547547
GlobalUnlock(hMem);
548548
}
549549
}

0 commit comments

Comments
 (0)