Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

EVUTIL_ASSERT: Use sizeof() to avoid "unused variable" warnings.

  • Loading branch information...
commit b63ab1776b3bbf3fe47406d0ca9639b299c4348d 1 parent 18adc3f
authored Nick Mathewson committed

Showing 2 changed files with 11 additions and 1 deletion. Show diff stats Hide diff stats

  1. 6  buffer.c
  2. 6  util-internal.h
6  buffer.c
@@ -246,6 +246,12 @@ evbuffer_chains_all_empty(struct evbuffer_chain *chain)
246 246
 	}
247 247
 	return 1;
248 248
 }
  249
+#else
  250
+/* The definition is needed for EVUTIL_ASSERT, which uses sizeof to avoid
  251
+"unused variable" warnings. */
  252
+static inline int evbuffer_chains_all_empty(struct evbuffer_chain *chain) {
  253
+	return 1;
  254
+}
249 255
 #endif
250 256
 
251 257
 static void
6  util-internal.h
@@ -52,6 +52,10 @@ extern "C" {
52 52
 
53 53
 /* A good no-op to use in macro definitions. */
54 54
 #define _EVUTIL_NIL_STMT ((void)0)
  55
+/* Suppresses the compiler's "unused variable" warnings for unused assert. */
  56
+#define _EVUTIL_NIL_CONDITION(condition) do { \
  57
+	(void)sizeof(condition); \
  58
+} while(0)
55 59
 
56 60
 /* Internal use only: macros to match patterns of error codes in a
57 61
    cross-platform way.  We need these macros because of two historical
@@ -177,7 +181,7 @@ long _evutil_weakrand(void);
177 181
 
178 182
 /* Replacement for assert() that calls event_errx on failure. */
179 183
 #ifdef NDEBUG
180  
-#define EVUTIL_ASSERT(cond) _EVUTIL_NIL_STMT
  184
+#define EVUTIL_ASSERT(cond) _EVUTIL_NIL_CONDITION(cond)
181 185
 #define EVUTIL_FAILURE_CHECK(cond) 0
182 186
 #else
183 187
 #define EVUTIL_ASSERT(cond)						\

0 notes on commit b63ab17

Please sign in to comment.
Something went wrong with that request. Please try again.