aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2002-08-03 18:59:41 +0000
committerUlrich Drepper <drepper@redhat.com>2002-08-03 18:59:41 +0000
commitd9af917d070a049f6d3b50fadeed6883df0d4b9a (patch)
treed9bcecebb94e28e2f46cee04e1e7632941143172
parent7abb683a13860d04d1c20cce1dde0f44f2aa4a3f (diff)
downloadglibc-d9af917d070a049f6d3b50fadeed6883df0d4b9a.zip
glibc-d9af917d070a049f6d3b50fadeed6883df0d4b9a.tar.gz
glibc-d9af917d070a049f6d3b50fadeed6883df0d4b9a.tar.bz2
Update.
2002-08-03 Jakub Jelinek <jakub@redhat.com> Ulrich Drepper <drepper@redhat.com> * malloc/malloc.c (public_cALLOc): Only divide if at least one of arguments is big enough to cause an overflow.
-rw-r--r--ChangeLog6
-rw-r--r--malloc/malloc.c13
2 files changed, 16 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index c256a53..1f43736 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2002-08-03 Jakub Jelinek <jakub@redhat.com>
+ Ulrich Drepper <drepper@redhat.com>
+
+ * malloc/malloc.c (public_cALLOc): Only divide if at least one of
+ arguments is big enough to cause an overflow.
+
2002-08-03 Ulrich Drepper <drepper@redhat.com>
* assert/assert.c: Use hidden_def not INTDEF.
diff --git a/malloc/malloc.c b/malloc/malloc.c
index 0440be5..08b8e86 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -488,6 +488,9 @@ Void_t *(*__morecore)(ptrdiff_t) = __default_morecore;
#endif /* _LIBC */
#endif /* USE_DL_PREFIX */
+#ifndef _LIBC
+#define __builtin_expect(expr, val) (expr)
+#endif
/*
HAVE_MEMCPY should be defined if you are not otherwise using
@@ -3466,9 +3469,13 @@ public_cALLOc(size_t n, size_t elem_size)
/* size_t is unsigned so the behavior on overflow is defined. */
bytes = n * elem_size;
- if (bytes / elem_size != n) {
- MALLOC_FAILURE_ACTION;
- return 0;
+#define HALF_INTERNAL_SIZE_T \
+ (((INTERNAL_SIZE_T) 1) << (8 * sizeof (INTERNAL_SIZE_T) / 2))
+ if (__builtin_expect ((n | elem_size) >= HALF_INTERNAL_SIZE_T, 0)) {
+ if (bytes / elem_size != n) {
+ MALLOC_FAILURE_ACTION;
+ return 0;
+ }
}
if (hook != NULL) {