Merge pull request #4259 from Feuris/fix/libc-realloc-null-zero

fix(libc): allocate from realloc(NULL, 0) as malloc(0) does
This commit is contained in:
Dean 2026-10-12 21:35:03 +13:00 committed by GitHub
commit 8f71e3010a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 1 deletions

View File

@ -176,7 +176,7 @@ void ApplicationHeapFree_nid_no_patch(void* pointer) {
}
void* ApplicationHeapReallocate_nid_no_patch(void* pointer, std::size_t bytes) {
if (bytes == 0) {
if (bytes == 0 && pointer != nullptr) {
ApplicationHeapFree_nid_no_patch(pointer);
return nullptr;
}

View File

@ -167,6 +167,12 @@ int main(int argc, char** argv) {
reject([pointer] { ApplicationHeapUsableSize_nid_no_patch(pointer); });
*__error_nid_postfix() = 0;
require(reallocf_nid_postfix(nullptr, SIZE_MAX) == nullptr && *__error_nid_postfix() == 12);
void* empty = ApplicationHeapAllocate_nid_no_patch(0);
require(empty != nullptr);
ApplicationHeapFree_nid_no_patch(empty);
empty = ApplicationHeapReallocate_nid_no_patch(nullptr, 0);
require(empty != nullptr);
ApplicationHeapFree_nid_no_patch(empty);
for (std::size_t alignment : {16, 64, 4096}) {
auto* aligned = ApplicationHeapAlign_nid_no_patch(alignment, 37);
require(reinterpret_cast<std::uintptr_t>(aligned) % alignment == 0);