]> sourceware.org Git - newlib-cygwin.git/commit
libc/stdlib: Fix build failure in nano_calloc
authorCraig Blackmore <craig.blackmore@embecosm.com>
Wed, 12 Aug 2020 14:33:23 +0000 (15:33 +0100)
committerCorinna Vinschen <corinna@vinschen.de>
Thu, 13 Aug 2020 07:59:45 +0000 (09:59 +0200)
commitab215e3dd18530f6f289fbbb26368e09a540c024
tree5cbbb59be7910c1ec67010e865aee4f5fda8e70d
parent588a5e1ddebdf6d74391c7409680ea20e050c0e1
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 <craig.blackmore@embecosm.com>
newlib/libc/stdlib/nano-mallocr.c
This page took 0.030094 seconds and 5 git commands to generate.