From: Jim Meyering Date: Wed, 7 Apr 2010 14:13:17 +0000 (+0200) Subject: sa_assert: assert-like macro, enabled only for use with static analyzers X-Git-Tag: v0.8.1~140 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e078fa3cecd4bb3303a1735a45723c9a2d9adec2;p=thirdparty%2Flibvirt.git sa_assert: assert-like macro, enabled only for use with static analyzers Among some here, there is a strong aversion to the use of "assert", yet some others think it is essential (when applied judiciously) even -- perhaps "especially" -- at the heart of libraries and core hypervisor- related code. Here is a compromise that lets us make assertions about the code (e.g., to tell static analyzers about invariants) without even a hint of risk of an abort. * src/internal.h [STATIC_ANALYSIS]: Include . (sa_assert): Define. A no-op most of the time, but equivalent to classical assert when STATIC_ANALYSIS is nonzero. --- diff --git a/src/internal.h b/src/internal.h index 2e73210d0e..896df22d74 100644 --- a/src/internal.h +++ b/src/internal.h @@ -9,6 +9,14 @@ # include # include +# if STATIC_ANALYSIS +# undef NDEBUG /* Don't let a prior NDEBUG definition cause trouble. */ +# include +# define sa_assert(expr) assert (expr) +# else +# define sa_assert(expr) /* empty */ +# endif + # ifdef HAVE_SYS_SYSLIMITS_H # include # endif