Skip to content

vec: remove capacity == 0 early return - #176

Open
wmww wants to merge 1 commit into
stclib:mainfrom
wmww:zero-size-malloc
Open

wmww wants to merge 1 commit into
stclib:mainfrom
wmww:zero-size-malloc

Conversation

@wmww

@wmww wmww commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

*_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) : NULL in the *_with_capacity implementation, and a few other places.

*_with_capacity(0) allocates, and malloc may return a valid pointer that
needs to be freed, even when 0 size is specified.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant