diff options
author | Bram Moolenaar <Bram@vim.org> | 2017-12-05 16:46:28 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2017-12-05 16:46:28 +0100 |
commit | ac112f01a6930c9d15cf0360b657373699916bfd (patch) | |
tree | 716c6cd53266a5e69aab17a3c2a4545d1acb59ce /src/ex_cmds2.c | |
parent | feeb4d0901c7b16958e8f02ffcdac83b605b0b43 (diff) |
patch 8.0.1372: profile log may be truncated halfway a characterv8.0.1372
Problem: Profile log may be truncated halfway a character.
Solution: Find the start of the character. (Ozaki Kiichi, closes #2385)
Diffstat (limited to 'src/ex_cmds2.c')
-rw-r--r-- | src/ex_cmds2.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/ex_cmds2.c b/src/ex_cmds2.c index e241605701..7b00ac2650 100644 --- a/src/ex_cmds2.c +++ b/src/ex_cmds2.c @@ -1834,6 +1834,26 @@ script_dump_profile(FILE *fd) { 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) { |