Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/ex_cmds2.c
Original file line number Diff line number Diff line change
Expand Up @@ -1834,6 +1834,22 @@ script_dump_profile(FILE *fd)
{
if (vim_fgets(IObuff, IOSIZE, sfd))
break;
/* When a line has been truncated, append '\n'. */
if (IObuff[IOSIZE - 2] != NUL && IObuff[IOSIZE - 2] != '\n')
{
int n = IOSIZE - 2;
# ifdef FEAT_MBYTE
if (has_mbyte)
{
int l = 1;

for (n = 0; l > 0 && n + l <= IOSIZE - 2; n += l)
l = (*mb_ptr2len)(IObuff + n);
}
# endif
IObuff[n] = '\n';
IObuff[n + 1] = NUL;
}
if (i < si->sn_prl_ga.ga_len
&& (pp = &PRL_ITEM(si, i))->snp_count > 0)
{
Expand Down
39 changes: 39 additions & 0 deletions src/testdir/test_profile.vim
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,42 @@ func Test_profile_errors()
call assert_fails("profile pause", 'E750:')
call assert_fails("profile continue", 'E750:')
endfunc

func Test_profile_truncate_mbyte()
if !has('multi_byte') || &enc !=# 'utf-8'
return
endif

let lines = [
\ 'scriptencoding utf-8',
\ 'func! Foo()',
\ ' return [',
\ ' \ "' . join(map(range(0x4E00, 0x4E00 + 340), 'nr2char(v:val)'), '') . '",',
\ ' \ "' . join(map(range(0x4F00, 0x4F00 + 340), 'nr2char(v:val)'), '') . '",',
\ ' \ ]',
\ 'endfunc',
\ 'call Foo()',
\ ]

call writefile(lines, 'Xprofile_file.vim')
call system(v:progpath
\ . ' -es --clean --cmd "set enc=utf-8"'
\ . ' -c "profile start Xprofile_file.log"'
\ . ' -c "profile file Xprofile_file.vim"'
\ . ' -c "so Xprofile_file.vim"'
\ . ' -c "qall!"')
call assert_equal(0, v:shell_error)

new Xprofile_file.log
call assert_equal('utf-8', &fenc)
/func! Foo()
let lnum = line('.')
call assert_match('^\s*return \[$', getline(lnum + 1))
call assert_match("\u4F52$", getline(lnum + 2))
call assert_match("\u5052$", getline(lnum + 3))
call assert_match('^\s*\\ \]$', getline(lnum + 4))
bwipe!

call delete('Xprofile_file.vim')
call delete('Xprofile_file.log')
endfunc