Patch 8.0.1372
Problem:    Profile log may be truncated halfway a character.
Solution:   Find the start of the character. (Ozaki Kiichi, closes #2385)
Files:      src/ex_cmds2.c, src/testdir/test_profile.vim


*** ../vim-8.0.1371/src/ex_cmds2.c      2017-11-18 22:13:04.753908641 +0100
--- src/ex_cmds2.c      2017-12-05 16:41:36.600071172 +0100
***************
*** 1834,1839 ****
--- 1834,1859 ----
                {
                    if (vim_fgets(IObuff, IOSIZE, sfd))
                        break;
+                   /* When a line has been truncated, append NL, taking care
+                    * of multi-byte characters . */
+                   if (IObuff[IOSIZE - 2] != NUL && IObuff[IOSIZE - 2] != NL)
+                   {
+                       int n = IOSIZE - 2;
+ # ifdef FEAT_MBYTE
+                       if (enc_utf8)
+                       {
+                           /* Move to the first byte of this char.
+                            * utf_head_off() doesn't work, because it checks
+                            * for a truncated character. */
+                           while (n > 0 && (IObuff[n] & 0xc0) == 0x80)
+                               --n;
+                       }
+                       else if (has_mbyte)
+                           n -= mb_head_off(IObuff, IObuff + n);
+ # endif
+                       IObuff[n] = NL;
+                       IObuff[n + 1] = NUL;
+                   }
                    if (i < si->sn_prl_ga.ga_len
                                     && (pp = &PRL_ITEM(si, i))->snp_count > 0)
                    {
*** ../vim-8.0.1371/src/testdir/test_profile.vim        2017-10-19 
21:04:33.473886033 +0200
--- src/testdir/test_profile.vim        2017-12-05 16:42:08.667890320 +0100
***************
*** 181,183 ****
--- 181,224 ----
    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)
+ 
+   split Xprofile_file.log
+   if &fenc != ''
+     call assert_equal('utf-8', &fenc)
+   endif
+   /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
*** ../vim-8.0.1371/src/version.c       2017-12-05 15:14:39.195947423 +0100
--- src/version.c       2017-12-05 16:45:33.698741809 +0100
***************
*** 773,774 ****
--- 773,776 ----
  {   /* Add new patch number below this line */
+ /**/
+     1372,
  /**/

-- 
hundred-and-one symptoms of being an internet addict:
86. E-mail Deficiency Depression (EDD) forces you to e-mail yourself.

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Raspunde prin e-mail lui