1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-10-26 00:57:39 +03:00

malloc: Improve checked_request2size

Change checked_request2size to return SIZE_MAX for huge inputs.  This
ensures large allocation requests stay large and can't be confused with a
small allocation.  As a result several existing checks against PTRDIFF_MAX
become redundant.

Reviewed-by: DJ Delorie <dj@redhat.com>
This commit is contained in:
Wilco Dijkstra
2025-06-06 17:11:36 +00:00
parent 21fda179c2
commit b68b125ad1
2 changed files with 13 additions and 28 deletions

View File

@@ -275,12 +275,12 @@ realloc_check (void *oldmem, size_t bytes)
malloc_printerr ("realloc(): invalid pointer");
const INTERNAL_SIZE_T oldsize = chunksize (oldp);
chnb = checked_request2size (rb);
if (chnb == 0)
if (rb > PTRDIFF_MAX)
{
__set_errno (ENOMEM);
goto invert;
}
chnb = checked_request2size (rb);
__libc_lock_lock (main_arena.mutex);