From 14743c0dfdb81a6a4a051921e56a61c3b1e0e664 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Mon, 26 Feb 2018 20:21:56 +0000 Subject: 42401: workaround for gcc -foptimize-strlen oddit. Use realloc(NULL, ...) instead of malloc in zsh-mem calloc(). --- Src/mem.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'Src/mem.c') diff --git a/Src/mem.c b/Src/mem.c index 840bbb6e4..f1208197b 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); -- cgit 1.4.1