From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id 7C420384A033; Thu, 13 Aug 2020 08:00:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7C420384A033 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Corinna Vinschen To: newlib-cvs@sourceware.org Subject: [newlib-cygwin] libc/stdlib: Fix build failure in nano_calloc X-Act-Checkin: newlib-cygwin X-Git-Author: Craig Blackmore X-Git-Refname: refs/heads/master X-Git-Oldrev: 588a5e1ddebdf6d74391c7409680ea20e050c0e1 X-Git-Newrev: ab215e3dd18530f6f289fbbb26368e09a540c024 Message-Id: <20200813080059.7C420384A033@sourceware.org> Date: Thu, 13 Aug 2020 08:00:59 +0000 (GMT) X-BeenThere: newlib-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Newlib GIT logs List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 13 Aug 2020 08:00:59 -0000 https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=ab215e3dd18530f6f289fbbb26368e09a540c024 commit ab215e3dd18530f6f289fbbb26368e09a540c024 Author: Craig Blackmore Date: Wed Aug 12 15:33:23 2020 +0100 libc/stdlib: Fix build failure in nano_calloc commit 588a5e1ddebdf6d74391c7409680ea20e050c0e1 added a non-reentrant call to nano_malloc which causes a build failure if INTERNAL_NEWLIB is defined. Here is a snippet of the error: In file included from .../newlib/newlib/libc/stdlib/nano-mallocr.c:38: .../newlib/newlib/libc/include/malloc.h:42:25: note: expected 'struct _reent *' but argument is of type 'ptrdiff_t' {aka 'int'} 42 | extern void *_malloc_r (struct _reent *, size_t); | ^~~~~~~~~~~~~~~ .../newlib/newlib/libc/stdlib/nano-mallocr.c:67:22: error: too few arguments to function '_malloc_r' 67 | #define nano_malloc _malloc_r | ^~~~~~~~~ .../newlib/newlib/libc/stdlib/nano-mallocr.c:456:11: note: in expansion of macro 'nano_malloc' 456 | mem = nano_malloc(bytes); | ^~~~~~~~~~~ In file included from .../newlib/newlib/libc/stdlib/nano-mallocr.c:38: .../newlib/newlib/libc/include/malloc.h:42:14: note: declared here 42 | extern void *_malloc_r (struct _reent *, size_t); | ^~~~~~~~~ .../newlib/newlib/libc/stdlib/nano-mallocr.c:43: warning: "assert" redefined 43 | #define assert(x) ((void)0) | This patch adds a missing RCALL to the args when calling nano_malloc from nano_calloc, so that if the call is reentrant, reent_ptr is passed as the first argument. The variable `bytes` (also added in 588a5e1d) has been changed from a `ptrdiff_t` to `malloc_size_t` as it does not need to be signed. It is used to store the product of two unsigned malloc_size_t variables and then iff there was no overflow is it passed to malloc and memset which both expect size_t which is unsigned. Signed-off-by: Craig Blackmore Diff: --- newlib/libc/stdlib/nano-mallocr.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/newlib/libc/stdlib/nano-mallocr.c b/newlib/libc/stdlib/nano-mallocr.c index 04465eb9e..9c59cff73 100644 --- a/newlib/libc/stdlib/nano-mallocr.c +++ b/newlib/libc/stdlib/nano-mallocr.c @@ -445,7 +445,7 @@ void nano_cfree(RARG void * ptr) * Implement calloc simply by calling malloc and set zero */ void * nano_calloc(RARG malloc_size_t n, malloc_size_t elem) { - ptrdiff_t bytes; + malloc_size_t bytes; void * mem; if (__builtin_mul_overflow (n, elem, &bytes)) @@ -453,7 +453,7 @@ void * nano_calloc(RARG malloc_size_t n, malloc_size_t elem) RERRNO = ENOMEM; return NULL; } - mem = nano_malloc(bytes); + mem = nano_malloc(RCALL bytes); if (mem != NULL) memset(mem, 0, bytes); return mem; }