From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2728 invoked by alias); 25 Feb 2018 07:06:44 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: X-Seq: 42401 Received: (qmail 20199 invoked by uid 1010); 25 Feb 2018 07:06:44 -0000 X-Qmail-Scanner-Diagnostics: from mail-pf0-f193.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(209.85.192.193):SA:0(1.2/5.0):. Processed in 1.44733 secs); 25 Feb 2018 07:06:44 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: * X-Spam-Status: No, score=1.2 required=5.0 tests=BAYES_00,FREEMAIL_FROM, FSL_HELO_FAKE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_PASS,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.1 X-Envelope-From: joeypabalinas@gmail.com X-Qmail-Scanner-Mime-Attachments: |signature.asc| X-Qmail-Scanner-Zip-Files: | DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=Hd2QI08ynQOfDw9yabj/4vg9+d7rXf/2M7xKeOiwvyQ=; b=mjbYOP8fSOTRuWkp6d8oAfWzz1D0KndPEi+SNfAGPlryf10W7mRda8p97bHwRO2+Za Nj/Xm94CoaAE5EY+ascor9AkX43KRunUuBsuYvVvoPA9VcbMOpytAnB64TdGQAOsmo5a rvUSCh8BXhhsUT7UNpkb7tXOfCaUChARtPGJmmy8XbRWb+yz3NpXDXyQSq6RzSGDloKT lR5QtfOftX0NiYHIZWYFOW7Uw1+0FoWSFjAVNd8zvSnVGdPPrEI+g/wcf/zclvPXi9lz HU2m1G+iCf7jcNfVIxskq8V4jQF4kvbvAawKEhRhoIP4IhhTZnKt0jrKTrMF9f/k7Xgg mDXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=Hd2QI08ynQOfDw9yabj/4vg9+d7rXf/2M7xKeOiwvyQ=; b=Mx3T2em9mXArZ3/UQJPMRSu6pOD1TExotWYBTbsr0TNMYCVtgHQlPxDgx88EgEk9a1 aMuqAELKe7uvwzetDU/lXZWUQhLDw7sSjKufhTof//aLMcL+H4wgbNFX1j+ARiFvTzsr U6ChBdmBWz5B8pgDR0amrY+/INAKpRTtDfNOsw4y2HiV00XxQvtug8p1BXZ8tZtsk1Sr lJ6GoCZXf8So03Z5idjJOLAQSzdIc9FYTRHgZwEy2mt7m0TVBTCNIy9dIkAx5RFDOnrN xpFahyQJfUgQfpTr2V11/c0lFEAudubce0O8uUIFC6YvnvWxCfpZEPtprutxWRoKCdrL 4GUg== X-Gm-Message-State: APf1xPC5idYKISgn9YTRnJNEA/wYq3smrYF0S2R7CgrYFom9lMX5iexP apvRWhuymTg0pycCNVJH89Q= X-Google-Smtp-Source: AH8x226iBTEweWyiz4N0pTFxar+y32G4xLFz+lowvnGAEvtgpV3oqWEOp3p1oPBdbSZVU73BSLL9Fw== X-Received: by 10.101.66.193 with SMTP id l1mr5424493pgp.57.1519542400604; Sat, 24 Feb 2018 23:06:40 -0800 (PST) Date: Sat, 24 Feb 2018 21:06:37 -1000 From: Joey Pabalinas To: Mikael Magnusson Cc: zsh workers , Joey Pabalinas Subject: Re: crash/hang with gcc 5+ -O2 and --enable-zsh-mem Message-ID: <20180225070637.2weeeu63fhm4ebqk@gmail.com> References: <20180225001334.fzsdcy67cnosvj5z@gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="6nfenrgtl2ij6ste" Content-Disposition: inline In-Reply-To: <20180225001334.fzsdcy67cnosvj5z@gmail.com> User-Agent: NeoMutt/20171215 --6nfenrgtl2ij6ste Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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 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 =3D n * size)) return (MALLOC_RET_T) m_high; =20 - r =3D 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 =3D realloc(NULL, l); =20 memset(r, 0, l); =20 --=20 2.16.2 --6nfenrgtl2ij6ste Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEKlZXrihdNOcUPZTNruvLfWhyVBkFAlqSYH0ACgkQruvLfWhy VBkVuxAAnLotf3Tvs3W4iZBPFZh6QLz7mQX319cDk4GEmbmG0RwUXlbnw/qHy0YE KT6LWxAbUpQcVWPQ1WU9uXCjgS0UE57Q9LXS3UQvK1lodl3s8/Ce3GqJLtfnoRiN 4tt+eHybG/wvfPN4VTQ3KcAU+oSGoaG38wxvspF7Q2qw3nmBGAd5JIVkedjjLyAK qNF8/DNnq+pNPQUEXPzIOStcBRjz7uMQtgMu21iFMzDT5/eHi6/FF2kveP8eLQb7 d7P1sDA4mpcleP9ud6eOXmGnJuLepsl8aKSWoi9ydQSjnJwpcdFAxebzsrnSEq7/ oUw0abKfSYnjWtNvwzLUG50Ge2hljE6jYDscfAPE0fWxwPVllURX9Cp0FZRcnz3L zMYMLFXc22PSFSud26nOIjM8j6oHYGNvgGS6r2mbrYj2LM7CNZQgpMao8pBqvJ0H CWP7LNRNcyJNwWNBC+ZVvPXMSd8ZPi8M6+ZVM8UGydbfZJJroWJJN5cQ2PNS7Yez xWIZTdsX+SBjK8ZbNa4ZUHXlruxnLq0go9fH6GuaQszKmonYFyH9dG0qNGKlGjis JajVyOnKp7asCGLKJAbm+DPRo+rOeCsVucMWgNRDwooW2QwC9s47MAEDb5VSijnm ZopuXVetG+QF45XYrkWcA2nEH1MLCuVwFBWMvR/VshVHzCkKFJc= =4Vfd -----END PGP SIGNATURE----- --6nfenrgtl2ij6ste--