[PATCH] Fix unused malloc return value warning
Jonathan Wakely
jwakely@redhat.com
Fri Aug 30 14:03:00 GMT 2019
On 29/08/19 21:54 +0200, François Dumont wrote:
>Hi
>
>Â Â Â I am having this warning:
>
>/home/fdt/dev/gcc/git/libstdc++-v3/testsuite/util/testsuite_performance.h:170:
>attention: ignoring return value of « void* malloc(size_t) » declared
>with attribute « warn_unused_result » [-Wunused-result]
>Â 170 |Â Â Â Â Â Â malloc(0); // Needed for some implementations.
>
>Â Â Â Ok to fix it with attached patch ?
OK for trunk.
>Â Â Â It seems trivial but I wonder if I shouldn't keep the malloc
>returned pointer and free it properly ?
It's not causing any problems (it's only the testsuite) so let's not
worry about it.
>Â Â Â Or maybe just remove the malloc cause there is not clear comment
>explaining why it's needed and I haven't found much in SVN audit
>trail.
The comment says it's needed, so let's assume that's true.
>Â Â Â * testsuite_files/util/testsuite_performance.h
>Â Â Â (resource_counter::start): Ignore unused malloc(0) result.
>
>François
>
>diff --git a/libstdc++-v3/testsuite/util/testsuite_performance.h b/libstdc++-v3/testsuite/util/testsuite_performance.h
>index 556c78159be..8abc77cf31a 100644
>--- a/libstdc++-v3/testsuite/util/testsuite_performance.h
>+++ b/libstdc++-v3/testsuite/util/testsuite_performance.h
>@@ -167,7 +167,7 @@ namespace __gnu_test
> {
> if (getrusage(who, &rusage_begin) != 0 )
> memset(&rusage_begin, 0, sizeof(rusage_begin));
>- malloc(0); // Needed for some implementations.
>+ void* p __attribute__((unused)) = malloc(0); // Needed for some implementations.
> allocation_begin = mallinfo();
> }
>
>
More information about the Gcc-patches
mailing list