/* Check if REQ overflows when padded and aligned and if the resulting
value is less than PTRDIFF_T. Returns the requested size or
- MINSIZE in case the value is less than MINSIZE, or 0 if any of the
- previous checks fail. */
+ MINSIZE in case the value is less than MINSIZE, or SIZE_MAX if any
+ of the previous checks fail. */
static __always_inline size_t
checked_request2size (size_t req) __nonnull (1)
{
"PTRDIFF_MAX is not more than half of SIZE_MAX");
if (__glibc_unlikely (req > PTRDIFF_MAX))
- return 0;
+ return SIZE_MAX;
/* When using tagged memory, we cannot share the end of the user
block with the header for the next chunk, so ensure that we
{
#if USE_TCACHE
size_t nb = checked_request2size (bytes);
- if (nb == 0)
- {
- __set_errno (ENOMEM);
- return NULL;
- }
if (nb < mp_.tcache_max_bytes)
{
|| misaligned_chunk (oldp)))
malloc_printerr ("realloc(): invalid pointer");
- nb = checked_request2size (bytes);
- if (nb == 0)
+ if (bytes > PTRDIFF_MAX)
{
__set_errno (ENOMEM);
return NULL;
}
+ nb = checked_request2size (bytes);
if (chunk_is_mmapped (oldp))
{
}
#if USE_TCACHE
- size_t nb = checked_request2size (bytes);
- if (nb == 0)
- {
- __set_errno (ENOMEM);
- return NULL;
- }
- void *victim = tcache_get_align (nb, alignment);
+ void *victim = tcache_get_align (checked_request2size (bytes), alignment);
if (victim != NULL)
return tag_new_usable (victim);
#endif
#if USE_TCACHE
size_t nb = checked_request2size (bytes);
- if (nb == 0)
- {
- __set_errno (ENOMEM);
- return NULL;
- }
+
if (nb < mp_.tcache_max_bytes)
{
if (__glibc_unlikely (tcache == NULL))
aligned.
*/
- nb = checked_request2size (bytes);
- if (nb == 0)
+ if (bytes > PTRDIFF_MAX)
{
__set_errno (ENOMEM);
return NULL;
}
+ nb = checked_request2size (bytes);
/* There are no usable arenas. Fall back to sysmalloc to get a chunk from
mmap. */
unsigned long remainder_size; /* its size */
INTERNAL_SIZE_T size;
- nb = checked_request2size (bytes);
- if (nb == 0)
+ if (bytes > PTRDIFF_MAX)
{
__set_errno (ENOMEM);
return NULL;
}
+ nb = checked_request2size (bytes);
/* We can't check tcache here because we hold the arena lock, which
tcache doesn't expect. We expect it has been checked