This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix unused malloc return value warning
- From: François Dumont <frs dot dumont at gmail dot com>
- To: "libstdc++ at gcc dot gnu dot org" <libstdc++ at gcc dot gnu dot org>, gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 29 Aug 2019 21:54:25 +0200
- Subject: [PATCH] Fix unused malloc return value warning
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
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();
}