mirror of
https://github.com/jedisct1/libsodium.git
synced 2026-08-26 11:47:13 +09:00
Make sodium_malloc(0) well-defined. It always returns NULL.
This commit is contained in:
@@ -577,8 +577,8 @@ sodium_malloc(const size_t size)
|
||||
{
|
||||
void *ptr;
|
||||
|
||||
if ((ptr = _sodium_malloc(size)) == NULL) {
|
||||
return NULL; /* LCOV_EXCL_LINE */
|
||||
if (size == (size_t) 0 || (ptr = _sodium_malloc(size)) == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
memset(ptr, (int) GARBAGE_VALUE, size);
|
||||
|
||||
|
||||
@@ -39,6 +39,9 @@ int main(void)
|
||||
if (sodium_malloc(SIZE_MAX - 1U) != NULL) {
|
||||
return 1;
|
||||
}
|
||||
if (sodium_malloc(0U) != NULL) {
|
||||
return 1;
|
||||
}
|
||||
if (sodium_allocarray(SIZE_MAX / 2U + 1U, SIZE_MAX / 2U) != NULL) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user