mirror of
https://sourceware.org/git/glibc.git
synced 2025-07-29 11:41:21 +03:00
malloc: Simplify checked_request2size interface
In-band signaling avoids an uninitialized variable warning when building with -Og and GCC 12. Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
This commit is contained in:
@ -275,7 +275,8 @@ realloc_check (void *oldmem, size_t bytes)
|
|||||||
malloc_printerr ("realloc(): invalid pointer");
|
malloc_printerr ("realloc(): invalid pointer");
|
||||||
const INTERNAL_SIZE_T oldsize = chunksize (oldp);
|
const INTERNAL_SIZE_T oldsize = chunksize (oldp);
|
||||||
|
|
||||||
if (!checked_request2size (rb, &chnb))
|
chnb = checked_request2size (rb);
|
||||||
|
if (chnb == 0)
|
||||||
{
|
{
|
||||||
__set_errno (ENOMEM);
|
__set_errno (ENOMEM);
|
||||||
goto invert;
|
goto invert;
|
||||||
|
@ -1333,15 +1333,15 @@ nextchunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|||||||
MINSIZE : \
|
MINSIZE : \
|
||||||
((req) + SIZE_SZ + MALLOC_ALIGN_MASK) & ~MALLOC_ALIGN_MASK)
|
((req) + SIZE_SZ + MALLOC_ALIGN_MASK) & ~MALLOC_ALIGN_MASK)
|
||||||
|
|
||||||
/* Check if REQ overflows when padded and aligned and if the resulting value
|
/* Check if REQ overflows when padded and aligned and if the resulting
|
||||||
is less than PTRDIFF_T. Returns TRUE and the requested size or MINSIZE in
|
value is less than PTRDIFF_T. Returns the requested size or
|
||||||
case the value is less than MINSIZE on SZ or false if any of the previous
|
MINSIZE in case the value is less than MINSIZE, or 0 if any of the
|
||||||
check fail. */
|
previous checks fail. */
|
||||||
static inline bool
|
static inline size_t
|
||||||
checked_request2size (size_t req, size_t *sz) __nonnull (1)
|
checked_request2size (size_t req) __nonnull (1)
|
||||||
{
|
{
|
||||||
if (__glibc_unlikely (req > PTRDIFF_MAX))
|
if (__glibc_unlikely (req > PTRDIFF_MAX))
|
||||||
return false;
|
return 0;
|
||||||
|
|
||||||
/* When using tagged memory, we cannot share the end of the user
|
/* When using tagged memory, we cannot share the end of the user
|
||||||
block with the header for the next chunk, so ensure that we
|
block with the header for the next chunk, so ensure that we
|
||||||
@ -1359,8 +1359,7 @@ checked_request2size (size_t req, size_t *sz) __nonnull (1)
|
|||||||
~(size_t)(__MTAG_GRANULE_SIZE - 1);
|
~(size_t)(__MTAG_GRANULE_SIZE - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
*sz = request2size (req);
|
return request2size (req);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -3295,8 +3294,8 @@ __libc_malloc (size_t bytes)
|
|||||||
ptmalloc_init ();
|
ptmalloc_init ();
|
||||||
#if USE_TCACHE
|
#if USE_TCACHE
|
||||||
/* int_free also calls request2size, be careful to not pad twice. */
|
/* int_free also calls request2size, be careful to not pad twice. */
|
||||||
size_t tbytes;
|
size_t tbytes = checked_request2size (bytes);
|
||||||
if (!checked_request2size (bytes, &tbytes))
|
if (tbytes == 0)
|
||||||
{
|
{
|
||||||
__set_errno (ENOMEM);
|
__set_errno (ENOMEM);
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -3443,7 +3442,8 @@ __libc_realloc (void *oldmem, size_t bytes)
|
|||||||
|| __builtin_expect (misaligned_chunk (oldp), 0)))
|
|| __builtin_expect (misaligned_chunk (oldp), 0)))
|
||||||
malloc_printerr ("realloc(): invalid pointer");
|
malloc_printerr ("realloc(): invalid pointer");
|
||||||
|
|
||||||
if (!checked_request2size (bytes, &nb))
|
nb = checked_request2size (bytes);
|
||||||
|
if (nb == 0)
|
||||||
{
|
{
|
||||||
__set_errno (ENOMEM);
|
__set_errno (ENOMEM);
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -3800,7 +3800,8 @@ _int_malloc (mstate av, size_t bytes)
|
|||||||
aligned.
|
aligned.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!checked_request2size (bytes, &nb))
|
nb = checked_request2size (bytes);
|
||||||
|
if (nb == 0)
|
||||||
{
|
{
|
||||||
__set_errno (ENOMEM);
|
__set_errno (ENOMEM);
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -4952,7 +4953,8 @@ _int_memalign (mstate av, size_t alignment, size_t bytes)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (!checked_request2size (bytes, &nb))
|
nb = checked_request2size (bytes);
|
||||||
|
if (nb == 0)
|
||||||
{
|
{
|
||||||
__set_errno (ENOMEM);
|
__set_errno (ENOMEM);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
Reference in New Issue
Block a user