Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Zend/tests/zend_alloc_zero_size.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--TEST--
Zero-size allocations with the tracked allocator
--EXTENSIONS--
zend_test
--ENV--
USE_ZEND_ALLOC=0
USE_TRACKED_ALLOC=1
--FILE--
<?php
var_dump(pack(""));
var_dump(vsprintf("", []));
?>
--EXPECT--
string(0) ""
string(0) ""
4 changes: 4 additions & 0 deletions Zend/zend_alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -3291,6 +3291,10 @@ static zend_always_inline zend_result tracked_check_max_allocs(zend_mm_heap *hea
static void *tracked_malloc(size_t size ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC)
{
zend_mm_heap *heap = AG(mm_heap);

/* malloc(0) may return NULL, so allocate at least one byte. */
size = MAX(size, 1);

if (UNEXPECTED(tracked_check_limit(heap, size ZEND_FILE_LINE_CC) == FAILURE)) {
return NULL;
}
Expand Down
Loading