bug-anubis
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug-anubis] [patch] fail_if_error macro evalutes parameter twice


From: Brian Dessent
Subject: [bug-anubis] [patch] fail_if_error macro evalutes parameter twice
Date: Wed, 06 Apr 2005 01:17:17 -0700

In gpg.c, there is a macro fail_if_error that prints an error message if
a gpgme function has an error.  Unfortunately the way it's coded now,
the function call will be evaluated twice if it fails the first time,
which could lead to unexpected results.  The following patch uses the
gcc ({ ... }) extension to make sure the macro is only evaluated once. 
I suppose that makes it less portable, but there's no portable way to do
this other than not using a macro.  Seems like the safer but less
portable way is better.

-----

2005-04-06  Brian Dessent  address@hidden

        * gpg.c (fail_if_error): Use gcc extension to avoid parameter
        being evaluated more than once.
--- gpg.orig    2005-04-06 00:35:23.265625000 -0700
+++ gpg.c       2005-04-06 00:40:16.046875000 -0700
@@ -49,12 +49,11 @@
 static void gpgme_debug_info (gpgme_ctx_t);
 
 #define EXTRA_GPG_BUF 4096
-#define fail_if_err(a) do { \
-               if (a) { \
-                       anubis_error(EXIT_FAILURE, 0, _("GPGME: %s."), \
-                                    gpgme_strerror(a)); \
-               } \
-       } while(0)
+#define fail_if_err(a) \
+            (__extension__ ({ gpgme_error_t __a = (a); \
+             if(__a) anubis_error(EXIT_FAILURE, 0, _("GPGME: %s."), \
+                                  gpgme_strerror(__a)); }))
+
 
 /* A replacement for the deprecated gpgme_data_rewind function. */
 static gpgme_error_t

reply via email to

[Prev in Thread] Current Thread [Next in Thread]