public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Ulrich Drepper <drepper@redhat.com>
Cc: Glibc hackers <libc-hacker@sources.redhat.com>
Subject: [PATCH] One more calloc fix
Date: Wed, 07 Aug 2002 03:21:00 -0000	[thread overview]
Message-ID: <20020807122148.U20867@sunsite.ms.mff.cuni.cz> (raw)

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

             reply	other threads:[~2002-08-07 10:21 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-08-07  3:21 Jakub Jelinek [this message]
2002-08-07 12:32 ` Roland McGrath

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20020807122148.U20867@sunsite.ms.mff.cuni.cz \
    --to=jakub@redhat.com \
    --cc=drepper@redhat.com \
    --cc=libc-hacker@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).