This is the mail archive of the libc-hacker@sources.redhat.com mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] One more calloc fix


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]