mirror of
https://github.com/jedisct1/libsodium.git
synced 2026-08-25 08:37:13 +09:00
Restore the previous sodium_malloc(0) behavior
If aligned memory cannot be obtained, allocate 1 byte to always return a non-NULL pointer.
This commit is contained in:
@@ -526,7 +526,7 @@ _unprotected_ptr_from_user_ptr(void * const ptr)
|
||||
static __attribute__ ((malloc)) void *
|
||||
_sodium_malloc(const size_t size)
|
||||
{
|
||||
return malloc(size);
|
||||
return malloc(size > (size_t) 0U ? size : (size_t) 1U);
|
||||
}
|
||||
#else
|
||||
static __attribute__ ((malloc)) void *
|
||||
@@ -577,7 +577,7 @@ sodium_malloc(const size_t size)
|
||||
{
|
||||
void *ptr;
|
||||
|
||||
if (size == (size_t) 0 || (ptr = _sodium_malloc(size)) == NULL) {
|
||||
if ((ptr = _sodium_malloc(size)) == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
memset(ptr, (int) GARBAGE_VALUE, size);
|
||||
|
||||
@@ -39,7 +39,7 @@ int main(void)
|
||||
if (sodium_malloc(SIZE_MAX - 1U) != NULL) {
|
||||
return 1;
|
||||
}
|
||||
if (sodium_malloc(0U) != NULL) {
|
||||
if (sodium_malloc(0U) == NULL) {
|
||||
return 1;
|
||||
}
|
||||
if (sodium_allocarray(SIZE_MAX / 2U + 1U, SIZE_MAX / 2U) != NULL) {
|
||||
|
||||
Reference in New Issue
Block a user