mailing list of musl libc
 help / color / mirror / code / Atom feed
From: aep <aep@exys.org>
To: <musl@lists.openwall.com>
Subject: Re: [PATCH] properly terminate linked link of dsos
Date: Wed, 12 Oct 2011 16:46:30 +0200	[thread overview]
Message-ID: <05e2d053cdb7c8726eb0f9bcebbbf048@exys.org> (raw)
In-Reply-To: <37ae4188867ea36022c6305ae687bd23@exys.org>

clang optimized away the check in calloc.c to false.
I can work around it with a cast to something volatile:

diff --git a/src/malloc/calloc.c b/src/malloc/calloc.c
index 9d57456..22f2c01 100644
--- a/src/malloc/calloc.c
+++ b/src/malloc/calloc.c
@@ -13,8 +13,10 @@ void *calloc(size_t m, size_t n)
         n *= m;
         p = malloc(n);
         if (!p) return 0;
+
+    volatile long long dont_optimize_me = p;
         /* Only do this for non-mmapped chunks */
-       if (((size_t *)p)[-1] & 7) {
+       if (((size_t *)dont_optimize_me)[-1] & 7) {
                 /* Only write words that are not already zero */
                 m = (n + sizeof *z - 1)/sizeof *z;
                 for (z=p; m; m--, z++) if (*z) *z=0;



  reply	other threads:[~2011-10-12 14:46 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-12 13:42 Arvid Ephraim Picciani
2011-10-12 14:01 ` Rich Felker
2011-10-12 14:25   ` aep
2011-10-12 14:46     ` aep [this message]
2011-10-14  1:03       ` Rich Felker
2011-10-14 21:11         ` Isaac Dunham
2011-10-14 22:53           ` Rich Felker

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=05e2d053cdb7c8726eb0f9bcebbbf048@exys.org \
    --to=aep@exys.org \
    --cc=musl@lists.openwall.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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

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 NNTP newsgroup(s).