summary refs log tree commit diff
path: root/support
diff options
context:
space:
mode:
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>2018-12-21 09:49:37 -0200
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>2018-12-28 15:39:45 -0200
commit0253580a75decdaf22b6abce60d8265b2adb7dea (patch)
tree9c2ff33657d7044ad615141eb2279abb166c757d /support
parent09104e5ba47de6691a371d214da48dd8493c39bd (diff)
downloadglibc-0253580a75decdaf22b6abce60d8265b2adb7dea.tar.gz
glibc-0253580a75decdaf22b6abce60d8265b2adb7dea.tar.xz
glibc-0253580a75decdaf22b6abce60d8265b2adb7dea.zip
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.
Diffstat (limited to 'support')
-rw-r--r--support/blob_repeat.c26
1 files changed, 3 insertions, 23 deletions
diff --git a/support/blob_repeat.c b/support/blob_repeat.c
index 718846d81d..daa1b7fd96 100644
--- a/support/blob_repeat.c
+++ b/support/blob_repeat.c
@@ -34,26 +34,6 @@
    optimization because mappings carry a lot of overhead.  */
 static const size_t maximum_small_size = 4 * 1024 * 1024;
 
-/* Set *RESULT to LEFT * RIGHT.  Return true if the multiplication
-   overflowed.  See <malloc/malloc-internal.h>.  */
-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
-}
-
 /* Internal helper for fill.  */
 static void
 fill0 (char *target, const char *element, size_t element_size,
@@ -138,8 +118,8 @@ minimum_stride_size (size_t page_size, size_t element_size)
      common multiple, it appears only once.  Therefore, shift one
      factor.  */
   size_t multiple;
-  if (check_mul_overflow_size_t (page_size >> common_zeros, element_size,
-                                 &multiple))
+  if (__builtin_mul_overflow (page_size >> common_zeros, element_size,
+			      &multiple))
     return 0;
   return multiple;
 }
@@ -275,7 +255,7 @@ support_blob_repeat_allocate (const void *element, size_t element_size,
                               size_t count)
 {
   size_t total_size;
-  if (check_mul_overflow_size_t (element_size, count, &total_size))
+  if (__builtin_mul_overflow (element_size, count, &total_size))
     {
       errno = EOVERFLOW;
       return (struct support_blob_repeat) { 0 };