On Sat, Aug 13, 2016 at 2:42 PM, Christoph M. Becker <cmbecke...@gmx.de> wrote:
> Hi Nikita! > > You have commented on <https://bugs.php.net/bug.php?id=72828>: > > | Unless the allocations explicitly use the system allocator (i.e. do > | not use emalloc and variants), do NOT introduce NULL checks. > > Can you please elaborate, why that shouldn't be done. > > Actually, the allocations use safe_emalloc() and emalloc(), > respectively[1]. However, the only client of the function does > explicitly check for a NULL return[2], which can only happen, if > safe_emalloc() fails. So if no NULL checks should be done, this one > should be removed as well. > > [1] > <https://github.com/php/php-src/blob/php-5.6.24/ext/ > standard/string.c#L2926-L2927> > [2] > <https://github.com/php/php-src/blob/php-5.6.24/ext/ > standard/string.c#L3133-L3134> > If that's the only failure condition of the function, the check can indeed be dropped. ZMM is an infallible allocator, it will bail out (or abort) if the allocation fails. The return value should never be checked -- if it is checked, it's a mistake. If you are concerned about USE_ZEND_ALLOC=0 using a fallible allocator, the system allocator hooks in ZMM should be adjusted to check for NULL and abort instead (use __zend_malloc instead of malloc, for example). Nikita