vec: remove capacity == 0 early return - #176
Merged
Merged
Conversation
*_with_capacity(0) allocates, and malloc may return a valid pointer that needs to be freed, even when 0 size is specified.
Collaborator
|
Thanks for making me aware. I will accept the commit, but will modify the code to test if the data pointer is NULL instead of removing the test. This is to avoid calling the user-provided free-function with NULL argument. free() does allows this, but the user may assume there is a non-NULL pointer passed, which may lead to UB (like memset(NULL, 0, 0)). Next commit updates the other relevant containers the same way. |
tylov
added a commit
that referenced
this pull request
Sep 28, 2026
- Fixes the _drop()/_clear() functions for other contiguous data containers than vec.h and updates the original PR for vec.h.
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_capacity(0) allocates, and malloc may return a valid pointer that needs to be freed, even when 0 size is specified. This behavior might be valgrind-specifiec? but malloc(0) is indeed implemenation-defined. An alternative would be to have
cap ? _i_new_n(_m_value, cap) : NULLin the*_with_capacityimplementation, and a few other places.