Repository navigation
Guard against zero size allocations - #2087
Merged
charles-lunarg merged 1 commit intoOct 28, 2026
Merged
Conversation
|
CI Vulkan-Loader build queued with queue ID 173219. |
|
CI Vulkan-Loader build queued with queue ID 173236. |
|
CI Vulkan-Loader build # 3919 running. |
|
CI Vulkan-Loader build # 3919 passed. |
charles-lunarg
force-pushed
the
guard_zero_size_allocations
branch
from
October 27, 2026 22:47
773ce92 to
253d64c
Compare
|
CI Vulkan-Loader build queued with queue ID 173260. |
|
CI Vulkan-Loader build queued with queue ID 173277. |
With the recent replacement of alloca with calloc & realloc, several places in the codebase needed extra checks to prevent calling calloc & realloc with a size of zero. Alloca() is defined to return a non-null pointer that is invalid to dereference. Calloc & realloc make no such guarantees. Some platforms return NULL, which the loader would wrongly interpret as out-of-host-memory. Fixes are to check the count before calling the allocation function and add assertions inside the allocation functions to catch the situation in debug builds.
charles-lunarg
force-pushed
the
guard_zero_size_allocations
branch
from
October 27, 2026 22:49
253d64c to
47052da
Compare
|
CI Vulkan-Loader build queued with queue ID 173278. |
|
CI Vulkan-Loader build # 3922 running. |
|
CI Vulkan-Loader build queued with queue ID 173315. |
|
CI Vulkan-Loader build # 3923 running. |
|
CI Vulkan-Loader build # 3923 passed. |
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.
With the recent replacement of alloca with calloc & realloc, several places in the codebase needed extra checks to prevent calling calloc & realloc with a size of zero. Alloca() is defined to return a non-null pointer that is invalid to dereference. Calloc & realloc make no such guarantees. Some platforms return NULL, which the loader would wrongly interpret as out-of-host-memory.
Fixes are to check the count before calling the allocation function, add assertions inside the allocation functions to catch the situation in debug builds, and enable the optin.portability.UnixAPI check in clang-tidy. Clang-tidy is not robust however because of internal limits to its search depth/breadth, so was unable to find all instances of this issue.