On 3 August 2013, Bram Moolenaar <[email protected]> wrote:
> 
> lcd wrote:
> 
> >     The easy way to describe this is by an example:
> > 
> >         :echo system('printf "a\0b\n"')
> > 
> > prints "a".  The output of "system(command)" is truncated at the first
> > NUL character in command's output.
> > 
> >     This affects all functions calling get_cmd_output(), including
> > "make", "grep", and friends, and that's particularly annoying since some
> > compilers (f.i. ghc-mod Haskell compiler) include NULs in their error
> > messages.
> > 
> >     Now, looking at get_cmd_output() it's pretty clear why this happens.
> > It isn't obvious how to fix that though, since once we're out of the
> > said function we lose all information about the real length of command's
> > output.
> 
> I suppose truncation is never useful.  How about changing the NUL (0x00)
> into SOH (0x01)?  SOH hardly ever appears, thus it can still be
> recognized as probably having been a NUL.

    Seems like a good idea.  Ok, patch below.

    /lcd


diff -Nrc vim.d154f5cf7f53/runtime/doc/eval.txt vim/runtime/doc/eval.txt
*** vim.d154f5cf7f53/runtime/doc/eval.txt       Sat Aug  3 16:08:45 2013
--- vim/runtime/doc/eval.txt    Sat Aug  3 16:08:45 2013
***************
*** 5884,5889 ****
--- 5884,5890 ----
  <             To make the result more system-independent, the shell output
                is filtered to replace <CR> with <NL> for Macintosh, and
                <CR><NL> with <NL> for DOS-like systems.
+               <Nul> characters are converted to \001 or CTRL-A.
                The command executed is constructed using several options:
        'shell' 'shellcmdflag' 'shellxquote' {expr} 'shellredir' {tmp} 
'shellxquote'
                ({tmp} is an automatically generated file name).
diff -Nrc vim.d154f5cf7f53/src/ascii.h vim/src/ascii.h
*** vim.d154f5cf7f53/src/ascii.h        Sat Aug  3 16:08:45 2013
--- vim/src/ascii.h     Sat Aug  3 16:08:45 2013
***************
*** 22,27 ****
--- 22,28 ----
  #define ROT13(c, a)   (((((c) - (a)) + 13) % 26) + (a))
  
  #define NUL           '\000'
+ #define SOH           '\001'
  #define BELL          '\007'
  #define BS            '\010'
  #define TAB           '\011'
diff -Nrc vim.d154f5cf7f53/src/misc1.c vim/src/misc1.c
*** vim.d154f5cf7f53/src/misc1.c        Sat Aug  3 16:08:45 2013
--- vim/src/misc1.c     Sat Aug  3 16:08:45 2013
***************
*** 10887,10893 ****
--- 10887,10898 ----
        buffer = NULL;
      }
      else
+     {
        buffer[len] = NUL;      /* make sure the buffer is terminated */
+       for (i = 0; i < len; i++)
+           if (buffer[i] == NUL)
+               buffer[i] = SOH;
+     }
  
  done:
      vim_free(tempname);

-- 
-- 
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/groups/opt_out.


Raspunde prin e-mail lui