public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix unused malloc return value warning
@ 2019-08-29 20:50 François Dumont
  2019-08-30 14:03 ` Jonathan Wakely
  0 siblings, 1 reply; 2+ messages in thread
From: François Dumont @ 2019-08-29 20:50 UTC (permalink / raw)
  To: libstdc++, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 828 bytes --]

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 ?

     It seems trivial but I wonder if I shouldn't keep the malloc 
returned pointer and free it properly ?

     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.

     * testsuite_files/util/testsuite_performance.h
     (resource_counter::start): Ignore unused malloc(0) result.

François


[-- Attachment #2: testsuite_performance.h.patch --]
[-- Type: text/x-patch, Size: 609 bytes --]

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();
     }
 


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Fix unused malloc return value warning
  2019-08-29 20:50 [PATCH] Fix unused malloc return value warning François Dumont
@ 2019-08-30 14:03 ` Jonathan Wakely
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Wakely @ 2019-08-30 14:03 UTC (permalink / raw)
  To: François Dumont; +Cc: libstdc++, gcc-patches

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();
>     }
> 
>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-08-30 13:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-29 20:50 [PATCH] Fix unused malloc return value warning François Dumont
2019-08-30 14:03 ` Jonathan Wakely

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).