Ozaki Kiichi wrote:

> When starting job with options, out_io=buffer and out_mode=raw,
> output-buffer gets garbage output.
> 
> [repro steps]
> 
> test.vim:
> 
> -------
> function! s:tm(timer) abort
>   for i in range(1000)
>     let a = 1
>   endfor
>   if job_status(get(s:, 'job')) !=# 'run'
>     call timer_stop(a:timer)
>   endif
> endfunction
> 
> let s:options = {
>       \ 'out_mode': 'raw',
>       \ 'out_io': 'buffer',
>       \ 'out_name': 'output',
>       \ }
> 
> function! Job() abort
>   let s:job = job_start(['python3', '-c', 'for _ in range(10000): print(".", 
> end="", flush=True)'], s:options)
>   call timer_start(3, function('s:tm'), {'repeat': -1})
> endfunction
> 
> call Job()
> buffer output
> -------
> 
> vim -Nu NONE -S test.vim
> 
> result example:
> 
> https://cloud.githubusercontent.com/assets/3213998/16155322/cfc561da-34e9-11e6-868e-6239b76a5107.png
> 
> got garbage at end-of-line.
> 
> [cause]
> 
> https://github.com/vim/vim/blob/688e3d1/src/channel.c#L1619
> 
> It sets 'len' to 1,
> 
> https://github.com/vim/vim/blob/688e3d1/src/channel.c#L1639
> https://github.com/vim/vim/blob/688e3d1/src/channel.c#L1649-L1654
> 
> so NUL terminator (of '*p') is overwritten by NL, and it causes 
> buffer-overrun.
> 
> [patch]
> 
> fix and test.
> 
> https://gist.github.com/ichizok/5cb23d48135235983380b97b70b9978a

Thanks for the test and fix!  I'll change the sleep to waiting for the
text to have arrived, that's quicker and more reliable.

> [additional issue]
> 
> test.vim of above outputs multiple lines to buffer, but maybe it is
> unexpected and undesired behavior for users.
> I think it should not add extra linefeeds; in this case, output should
> be one line.

Raw I/O is a bit of a problem, since Vim doesn't know where any message
starts or ends.  It's not really meant for writing to a buffer, since
buffers are line oriented.

Is there a practical application for using raw I/O to write to a buffer?

Looking at write_buf_line() we should perhaps replace NL with NUL there
to make it symmetrical.

-- 
hundred-and-one symptoms of being an internet addict:
151. You find yourself engaged to someone you've never actually met,
     except through e-mail.

 /// 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