mwrap user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: <mwrap-public@80x24.org>
Cc: Sam Saffron <sam.saffron@gmail.com>
Subject: [PATCH] quiet uninitialized and unused variable warnings
Date: Sat, 20 Aug 2022 22:55:05 +0000	[thread overview]
Message-ID: <20220820225505.11143-1-e@80x24.org> (raw)

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

                 reply	other threads:[~2022-08-20 22:55 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://80x24.org/mwrap/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220820225505.11143-1-e@80x24.org \
    --to=e@80x24.org \
    --cc=mwrap-public@80x24.org \
    --cc=sam.saffron@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).