Repository navigation
Conversation
malloc(0) may return NULL. Prevent it by allocating at least one byte. Otherwise PHP may think the system is out of memory because malloc returns NULL.
Member
|
The only unknown would be the more exotic platforms e.g. solaris/AIX. The change is probably not enough regardless. Edit: indeed realloc case needs to be taken in account too. |
Contributor
Author
|
Yes, I came to this by trying it on AIX. There
ZEND_API void * __zend_realloc(void *p, size_t len ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC)
{
p = realloc(p, len);
if (EXPECTED(p || !len)) {
return p;
}
zend_out_of_memory();
}So when |
Member
|
in that case, can this test be added ? +--TEST--
+Zero-size reallocations with the tracked allocator
+--EXTENSIONS--
+zend_test
+--ENV--
+USE_ZEND_ALLOC=0
+USE_TRACKED_ALLOC=1
+--FILE--
+<?php
+var_dump(zend_test_erealloc_block_size(16, 0));
+var_dump(zend_test_erealloc_block_size(16, 0));
+?>
+--EXPECT--
+array(2) {
+ [0]=>
+ int(1)
+ [1]=>
+ int(1)
+}
+array(2) {
+ [0]=>
+ int(1)
+ [1]=>
+ int(1)
+} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
malloc(0) may return NULL. Prevent it by allocating at least one byte. Otherwise PHP may think the system is out of memory because malloc returns NULL.