1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-07-28 00:21:52 +03:00

Replace check_mul_overflow_size_t with __builtin_mul_overflow

Checked on x86_64-linux-gnu and i686-linux-gnu.

	* malloc/alloc_buffer_alloc_array.c (__libc_alloc_buffer_alloc_array):
	Use __builtin_mul_overflow in place of check_mul_overflow_size_t.
	* malloc/dynarray_emplace_enlarge.c (__libc_dynarray_emplace_enlarge):
	Likewise.
	* malloc/dynarray_resize.c (__libc_dynarray_resize): Likewise.
	* malloc/reallocarray.c (__libc_reallocarray): Likewise.
	* malloc/malloc-internal.h (check_mul_overflow_size_t): Remove
	function.
	* support/blob_repeat.c (check_mul_overflow_size_t,
	(minimum_stride_size, support_blob_repeat_allocate): Likewise.
This commit is contained in:
Adhemerval Zanella
2018-12-21 09:49:37 -02:00
parent 09104e5ba4
commit 0253580a75
7 changed files with 21 additions and 53 deletions

View File

@ -74,24 +74,4 @@ void __malloc_fork_unlock_child (void) attribute_hidden;
/* Called as part of the thread shutdown sequence. */
void __malloc_arena_thread_freeres (void) attribute_hidden;
/* Set *RESULT to LEFT * RIGHT. Return true if the multiplication
overflowed. */
static inline bool
check_mul_overflow_size_t (size_t left, size_t right, size_t *result)
{
#if __GNUC__ >= 5
return __builtin_mul_overflow (left, right, result);
#else
/* size_t is unsigned so the behavior on overflow is defined. */
*result = left * right;
size_t half_size_t = ((size_t) 1) << (8 * sizeof (size_t) / 2);
if (__glibc_unlikely ((left | right) >= half_size_t))
{
if (__glibc_unlikely (right != 0 && *result / right != left))
return true;
}
return false;
#endif
}
#endif /* _MALLOC_INTERNAL_H */