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:
Frank Denis
2016-03-25 16:26:37 +01:00
parent 811bdb2c5f
commit 2aa703fcc7
2 changed files with 3 additions and 3 deletions
+2 -2
View File
@@ -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);
+1 -1
View File
@@ -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) {