aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Desaulniers <ndesaulniers@google.com>2024-04-18 16:09:05 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2024-04-18 16:09:05 +0000
commit5716586cf576f5bdea0655673c12a4b8deac5305 (patch)
tree311497c33ac2b76f79cec5521dc5dca899f2d8c5
parent0be8f184c2de976b1370e668ce2bf2e49d6c8a5b (diff)
parentceed466d605f597375adca8cdc98f7eaa65f7d43 (diff)
downloadbionic-5716586cf576f5bdea0655673c12a4b8deac5305.tar.gz
Merge "libc: remove __size_mul_overflow" into main
-rw-r--r--libc/bionic/fortify.cpp8
-rw-r--r--libc/include/sys/cdefs.h21
2 files changed, 7 insertions, 22 deletions
diff --git a/libc/bionic/fortify.cpp b/libc/bionic/fortify.cpp
index 7dee5e305..80f7c20ac 100644
--- a/libc/bionic/fortify.cpp
+++ b/libc/bionic/fortify.cpp
@@ -99,8 +99,8 @@ char* __fgets_chk(char* dst, int supplied_size, FILE* stream, size_t dst_len_fro
}
size_t __fread_chk(void* buf, size_t size, size_t count, FILE* stream, size_t buf_size) {
- size_t total;
- if (__predict_false(__size_mul_overflow(size, count, &total))) {
+ unsigned long total;
+ if (__predict_false(__builtin_umull_overflow(size, count, &total))) {
// overflow: trigger the error path in fread
return fread(buf, size, count, stream);
}
@@ -109,8 +109,8 @@ size_t __fread_chk(void* buf, size_t size, size_t count, FILE* stream, size_t bu
}
size_t __fwrite_chk(const void* buf, size_t size, size_t count, FILE* stream, size_t buf_size) {
- size_t total;
- if (__predict_false(__size_mul_overflow(size, count, &total))) {
+ unsigned long total;
+ if (__predict_false(__builtin_umull_overflow(size, count, &total))) {
// overflow: trigger the error path in fwrite
return fwrite(buf, size, count, stream);
}
diff --git a/libc/include/sys/cdefs.h b/libc/include/sys/cdefs.h
index a19ce2619..e587fe713 100644
--- a/libc/include/sys/cdefs.h
+++ b/libc/include/sys/cdefs.h
@@ -320,27 +320,12 @@
/* Used to rename functions so that the compiler emits a call to 'x' rather than the function this was applied to. */
#define __RENAME(x) __asm__(#x)
-#if __has_builtin(__builtin_umul_overflow) || __GNUC__ >= 5
-#if defined(__LP64__)
-#define __size_mul_overflow(a, b, result) __builtin_umull_overflow(a, b, result)
-#else
-#define __size_mul_overflow(a, b, result) __builtin_umul_overflow(a, b, result)
-#endif
-#else
-extern inline __always_inline __attribute__((gnu_inline))
-int __size_mul_overflow(__SIZE_TYPE__ a, __SIZE_TYPE__ b, __SIZE_TYPE__ *result) {
- *result = a * b;
- static const __SIZE_TYPE__ mul_no_overflow = 1UL << (sizeof(__SIZE_TYPE__) * 4);
- return (a >= mul_no_overflow || b >= mul_no_overflow) && a > 0 && (__SIZE_TYPE__)-1 / a < b;
-}
-#endif
-
/*
* Used when we need to check for overflow when multiplying x and y. This
- * should only be used where __size_mul_overflow can not work, because it makes
- * assumptions that __size_mul_overflow doesn't (x and y are positive, ...),
+ * should only be used where __builtin_umull_overflow can not work, because it makes
+ * assumptions that __builtin_umull_overflow doesn't (x and y are positive, ...),
* *and* doesn't make use of compiler intrinsics, so it's probably slower than
- * __size_mul_overflow.
+ * __builtin_umull_overflow.
*/
#define __unsafe_check_mul_overflow(x, y) ((__SIZE_TYPE__)-1 / (x) < (y))