* [PATCH] libc/stdlib: Fix build failure in nano_calloc
@ 2020-08-12 14:33 Craig Blackmore
2020-08-13 8:01 ` Corinna Vinschen
0 siblings, 1 reply; 4+ messages in thread
From: Craig Blackmore @ 2020-08-12 14:33 UTC (permalink / raw)
To: newlib; +Cc: keithp, vinschen
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 | 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;
}
--
2.17.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] libc/stdlib: Fix build failure in nano_calloc
2020-08-12 14:33 [PATCH] libc/stdlib: Fix build failure in nano_calloc Craig Blackmore
@ 2020-08-13 8:01 ` Corinna Vinschen
2020-08-13 8:05 ` Claudio
0 siblings, 1 reply; 4+ messages in thread
From: Corinna Vinschen @ 2020-08-13 8:01 UTC (permalink / raw)
To: newlib
On Aug 12 15:33, Craig Blackmore wrote:
> 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 | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
Pushed.
Thanks,
Corinna
--
Corinna Vinschen
Cygwin Maintainer
Red Hat
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] libc/stdlib: Fix build failure in nano_calloc
2020-08-13 8:01 ` Corinna Vinschen
@ 2020-08-13 8:05 ` Claudio
2020-08-13 8:18 ` Corinna Vinschen
0 siblings, 1 reply; 4+ messages in thread
From: Claudio @ 2020-08-13 8:05 UTC (permalink / raw)
To: newlib
Please, stop to send mail ... Thanks
Il 13 agosto 2020 10:01:12 CEST, Corinna Vinschen via Newlib <newlib@sourceware.org> ha scritto:
>On Aug 12 15:33, Craig Blackmore wrote:
>> 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 | 4 ++--
>> 1 file changed, 2 insertions(+), 2 deletions(-)
>
>Pushed.
>
>
>Thanks,
>Corinna
>
>--
>Corinna Vinschen
>Cygwin Maintainer
>Red Hat
Inviato dall'app Tiscali Mail.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] libc/stdlib: Fix build failure in nano_calloc
2020-08-13 8:05 ` Claudio
@ 2020-08-13 8:18 ` Corinna Vinschen
0 siblings, 0 replies; 4+ messages in thread
From: Corinna Vinschen @ 2020-08-13 8:18 UTC (permalink / raw)
To: newlib
On Aug 13 10:05, Claudio via Newlib wrote:
> Please, stop to send mail ... Thanks
You'll have to unsubscribe from the newlib mailing list then. Thanks.
> Il 13 agosto 2020 10:01:12 CEST, Corinna Vinschen via Newlib <newlib@sourceware.org> ha scritto:
> >On Aug 12 15:33, Craig Blackmore wrote:
> >> commit 588a5e1ddebdf6d74391c7409680ea20e050c0e1 added a non-reentrant
> >> call to nano_malloc which causes a build failure if INTERNAL_NEWLIB
> >is
> >> defined.
> >> [...]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-08-13 8:18 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-12 14:33 [PATCH] libc/stdlib: Fix build failure in nano_calloc Craig Blackmore
2020-08-13 8:01 ` Corinna Vinschen
2020-08-13 8:05 ` Claudio
2020-08-13 8:18 ` Corinna Vinschen
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 read-only IMAP folder(s) and NNTP newsgroup(s).