Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't pass NULL to qsort() #297

Merged
merged 2 commits into from
Apr 6, 2024
Merged

Don't pass NULL to qsort() #297

merged 2 commits into from
Apr 6, 2024

Conversation

gperciva
Copy link
Member

@gperciva gperciva commented Mar 5, 2024

No description provided.

Technically, we're not allowed to pass NULL to qsort(), even if
nmemb==0:
    Where an argument declared as size_t nmemb specifies the length of
    the array for a function, nmemb can have the value zero...
    Pointer arguments on such a call shall still have valid values, as
    described in 7.1.4.
    C99, 7.20.5/1 Searching and sorting utilities
and:
    If an argument to a function has an invalid value (such as...
    a null pointer...) ... the behavior is undefined.
    C99, 7.1.4/1 Use of library functions
@gperciva
Copy link
Member Author

gperciva commented Mar 5, 2024

In C99, we need to have valid pointers for qsort(), even if we have 0 items.

@cperciva cperciva merged commit 62cb40e into master Apr 6, 2024
2 checks passed
@gperciva gperciva deleted the qsort-no-null branch April 7, 2024 18:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants