* [PATCH] quiet uninitialized and unused variable warnings
@ 2022-08-20 22:55 Eric Wong
0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2022-08-20 22:55 UTC (permalink / raw)
To: mwrap-public; +Cc: Sam Saffron
These warnings are already suppressed in similar ways in the
Perl/XS port.
The only warning which remains is related to cfree, which I'm
leaving alone, for now, due to lack of use/test-cases:
../../../../ext/mwrap/mwrap.c:689:6: warning: ‘cfree’ specifies less restrictive attributes than its target ‘free’: ‘leaf’, ‘nothrow’ [-Wmissing-attributes]
689 | void cfree(void *) __attribute__((alias("free")));
| ^~~~~
/usr/include/stdlib.h:565:13: note: ‘cfree’ target declared here
565 | extern void free (void *__ptr) __THROW;
| ^~~~
---
ext/mwrap/mwrap.c | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/ext/mwrap/mwrap.c b/ext/mwrap/mwrap.c
index cd68eed..a097b2e 100644
--- a/ext/mwrap/mwrap.c
+++ b/ext/mwrap/mwrap.c
@@ -169,11 +169,18 @@ __attribute__((constructor)) static void resolve_malloc(void)
--locating;
}
+#ifdef NDEBUG
+#define QUIET_CC_WARNING(var) (void)var;
+#else
+#define QUIET_CC_WARNING(var)
+#endif
+
static void
mutex_lock(pthread_mutex_t *m)
{
int err = pthread_mutex_lock(m);
assert(err == 0);
+ QUIET_CC_WARNING(err)
}
static void
@@ -181,6 +188,7 @@ mutex_unlock(pthread_mutex_t *m)
{
int err = pthread_mutex_unlock(m);
assert(err == 0);
+ QUIET_CC_WARNING(err)
}
#ifndef HAVE_MEMPCPY
@@ -660,16 +668,14 @@ internal_memalign(void **pp, size_t alignment, size_t size, uintptr_t caller)
static void *
memalign_result(int err, void *p)
{
- if (caa_unlikely(err)) {
+ if (caa_unlikely(err))
errno = err;
- return 0;
- }
return p;
}
void *memalign(size_t alignment, size_t size)
{
- void *p;
+ void *p = NULL;
int err = internal_memalign(&p, alignment, size, RETURN_ADDRESS(0));
return memalign_result(err, p);
}
@@ -684,7 +690,7 @@ void cfree(void *) __attribute__((alias("free")));
void *valloc(size_t size)
{
- void *p;
+ void *p = NULL;
int err = internal_memalign(&p, page_size, size, RETURN_ADDRESS(0));
return memalign_result(err, p);
}
@@ -702,7 +708,7 @@ void *valloc(size_t size)
void *pvalloc(size_t size)
{
size_t alignment = page_size;
- void *p;
+ void *p = NULL;
int err;
if (add_overflow_p(size, alignment)) {
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2022-08-20 22:55 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-20 22:55 [PATCH] quiet uninitialized and unused variable warnings Eric Wong
Code repositories for project(s) associated with this public inbox
https://80x24.org/mwrap.git/
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).