From: Joey Pabalinas <joeypabalinas@gmail.com>
To: Mikael Magnusson <mikachu@gmail.com>
Cc: zsh workers <zsh-workers@zsh.org>,
Joey Pabalinas <joeypabalinas@gmail.com>
Subject: Re: crash/hang with gcc 5+ -O2 and --enable-zsh-mem
Date: Sat, 24 Feb 2018 21:06:37 -1000 [thread overview]
Message-ID: <20180225070637.2weeeu63fhm4ebqk@gmail.com> (raw)
In-Reply-To: <20180225001334.fzsdcy67cnosvj5z@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 1513 bytes --]
On Sat, Feb 24, 2018 at 02:13:34PM -1000, Joey Pabalinas wrote:
> The only fix I could find which didn't requiring substantial
> reimplementation of the memory management functions was to replace
> the malloc() call in calloc() with realloc() instead. With a NULL `p`
> argument realloc() behaves exactly the same as malloc() does, and
> (at least on my system) gcc doesn't seem to consider realloc() a
> candidate for sibling call optimizations; give this patch a try
> and _hopefully_ this is a viable solution.
On second thought, doing it this way is probably a *little* bit better; the
needless initialization of `r` to NULL is avoided, and it also makes the
purpose of using realloc() over malloc() a *tiny* bit more explicit:
Signed-off-by: Joey Pabalinas <joeypabalinas@gmail.com>
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/Src/mem.c b/Src/mem.c
index 840bbb6e4a4eb6fd73..f1208197b3ddac2139 100644
--- a/Src/mem.c
+++ b/Src/mem.c
@@ -1719,7 +1719,13 @@ calloc(MALLOC_ARG_T n, MALLOC_ARG_T size)
if (!(l = n * size))
return (MALLOC_RET_T) m_high;
- r = malloc(l);
+ /*
+ * use realloc() (with a NULL `p` argument it behaves exactly the same
+ * as malloc() does) to prevent an infinite loop caused by sibling-call
+ * optimizations (the malloc() call would otherwise be replaced by an
+ * unconditional branch back to line 1719 ad infinitum).
+ */
+ r = realloc(NULL, l);
memset(r, 0, l);
--
2.16.2
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2018-02-25 7:06 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-24 19:01 Mikael Magnusson
2018-02-25 0:13 ` Joey Pabalinas
2018-02-25 7:06 ` Joey Pabalinas [this message]
2018-02-25 7:07 ` Joey Pabalinas
2018-02-26 20:24 ` Peter Stephenson
2018-02-27 1:13 ` Joey Pabalinas
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=20180225070637.2weeeu63fhm4ebqk@gmail.com \
--to=joeypabalinas@gmail.com \
--cc=mikachu@gmail.com \
--cc=zsh-workers@zsh.org \
/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/zsh/
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).