[PATCH] One more calloc fix
Jakub Jelinek
jakub@redhat.com
Wed Aug 7 03:21:00 GMT 2002
Hi!
calloc (131072, 0) ought to work like malloc (0), but it will crash
on 32-bit arches.
The check is in the unlikely executed chunk of code, so it shouldn't
slow things down.
2002-08-07 Jakub Jelinek <jakub@redhat.com>
* malloc/malloc.c (public_cALLOc): Check elem_size != 0 before
division.
--- libc/malloc/malloc.c.jj 2002-08-05 08:44:17.000000000 +0200
+++ libc/malloc/malloc.c 2002-08-07 12:37:58.000000000 +0200
@@ -3474,7 +3474,7 @@ public_cALLOc(size_t n, size_t elem_size
#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) {
+ if (elem_size != 0 && bytes / elem_size != n) {
MALLOC_FAILURE_ACTION;
return 0;
}
Jakub
More information about the Libc-hacker
mailing list