Dominique Pelle wrote:

> Vim calls realloc(NULL, size) which is fine in ANSI C: calling it with
> NULL as first argument is equivalent to calling malloc(size).
> 
> However, it causes a crash when compiling Vim with -DMEM_PROFILE
> since function mem_realloc(ptr, size) does not handle NULL as
> first argument.
> 
> Steps to reproduce:
> 
> 1) Compile Vim with -DMEM_PROFILE
> 2) Run:
>    $ touch foo; ./vim -u NONE -c "call readfile('foo')"
>    Vim: Caught deadly signal SEGV
>    Vim: Finished.
>    Segmentation fault (core dumped)
> 
> Program received signal SIGSEGV, Segmentation fault.
> 0x081538c2 in mem_pre_free (pp=0xbfffe174) at misc2.c:756
> 756       size = *(size_t *)*pp;
> (gdb) bt
> #0  0x081538c2 in mem_pre_free (pp=0xbfffe174) at misc2.c:756
[...]
> 
> Attached "fix-mem_pre_free-7.3.515.patch" fixes it.
> 
> Furthermore, even if realloc(NULL, size) is fine in ANSI C, it may
> not be fully portable on pre-ANSI C according to this link:
> 
>   http://c-faq.com/malloc/reallocnull.html
> 
> So second attached patch "fix-realloc-7.3.515.patch" makes Vim
> more portable on systems where realloc(NULL, ...) may not work.
> It fixes the call to vim_realloc() in f_readfile() rather than the
> implementation of vim_realloc() since I think it's  the only place
> where vim_realloc() is called with NULL as first argument. But it
> could be safer to change vim_realloc() to handle NULL as first
> argument.

Thanks for the patches.  I'll look into it soon.

-- 
ARTHUR: It is I, Arthur, son of Uther Pendragon, from the castle of Camelot.
        King of all Britons, defeator of the Saxons, sovereign of all England!
   [Pause]
SOLDIER: Get away!
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

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

Raspunde prin e-mail lui