public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: Jan Palus <jpalus@fastmail.com>
To: David Gibson <david@gibson.dropbear.id.au>,
	passt-dev@passt.top, Stefano Brivio <sbrivio@redhat.com>
Subject: Re: [PATCH 2/3] Fix build with -DNDEBUG
Date: Fri, 15 May 2026 13:05:50 +0200	[thread overview]
Message-ID: <agb4QtGfg0CroXZV@pine.grzadka> (raw)
In-Reply-To: <20260515041312.317644-3-david@gibson.dropbear.id.au>

On 15.05.2026 14:13, David Gibson wrote:
> Since bc872d91765d, our assert() statements are omitted if we compile with
> -DNDEBUG, like the standard library assert(3).  Unfortunately a trivial but
> embarrassing mistake in that patch means that instead of never aborting in
> this case, assert_with_msg() *always* aborts, breaking pretty much
> everything.
> 
> There's also a missing #include that breaks the build with -DNDEBUG on at
> least some library versions.
> 
> Reported-by: Jan Palus <jpalus@fastmail.com>
> Fixes: bc872d91765d ("treewide: Spell ASSERT() as assert()")
> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
> ---
>  util.h | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/util.h b/util.h
> index 70aadeba..11f71d45 100644
> --- a/util.h
> +++ b/util.h
> @@ -6,6 +6,7 @@
>  #ifndef UTIL_H
>  #define UTIL_H
>  
> +#include <assert.h>
>  #include <stdlib.h>
>  #include <stdarg.h>
>  #include <stdbool.h>
> @@ -60,7 +61,7 @@ void abort_with_msg(const char *fmt, ...)
>  			__func__, __FILE__, __LINE__, STRINGIFY(expr))
>  #else
>  #define assert_with_msg(expr, ...)					\
> -	((void)(expr), 0 ? (void)0 : abort_with_msg(__VA_ARGS__))
> +	((void)(expr), 1 ? (void)0 : abort_with_msg(__VA_ARGS__))

There is a slight semantic difference between assert() and
assert_with_msg() when building with -DNDEBUG -- `expr` is still being
evaluated in abort_with_msg() although likely optimized out in most
builds. I'm assuming you'd prefer to avoid cppcheck suppressions. How
about moving `expr` into branch which is never evaluated then? Would it
keep cppcheck happy?

+	(1 ? (void)0 : ((void)(expr), abort_with_msg(__VA_ARGS__)))

>  #endif
>  
>  #ifdef P_tmpdir
> -- 
> 2.54.0
> 

  reply	other threads:[~2026-05-15 11:05 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-15  4:13 [PATCH 0/3] Fix broken " David Gibson
2026-05-15  4:13 ` [PATCH 1/3] test: Extend exeter build tests to cover more recent binaries David Gibson
2026-05-15  4:13 ` [PATCH 2/3] Fix build with -DNDEBUG David Gibson
2026-05-15 11:05   ` Jan Palus [this message]
2026-05-16  6:28     ` David Gibson
2026-05-16  9:27       ` Stefano Brivio
2026-05-16 11:12         ` David Gibson
2026-05-15  4:13 ` [PATCH 3/3] test: Add test for builds " David Gibson

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

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

  git send-email \
    --in-reply-to=agb4QtGfg0CroXZV@pine.grzadka \
    --to=jpalus@fastmail.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=passt-dev@passt.top \
    --cc=sbrivio@redhat.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://passt.top/passt

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 IMAP folder(s).