diff --git a/cocci/outarg.spatch b/cocci/outarg.spatch new file mode 100644 index 0000000000..e4d5ac16b7 --- /dev/null +++ b/cocci/outarg.spatch @@ -0,0 +1,14 @@ +@@ +type T; +identifier fun; +identifier arg; +expression val; +@@ + fun(..., T *arg, ...) { + ... +- if (arg != NULL) { +- *arg = val; +- } ++ OUTARG(arg, val); + ... + } diff --git a/lib/dns/openssl_shim.c b/lib/dns/openssl_shim.c index 9d0e397e2d..15e93b61ba 100644 --- a/lib/dns/openssl_shim.c +++ b/lib/dns/openssl_shim.c @@ -13,6 +13,8 @@ #include "openssl_shim.h" +#include + #if !HAVE_RSA_SET0_KEY && OPENSSL_VERSION_NUMBER < 0x30000000L /* From OpenSSL 1.1.0 */ int diff --git a/lib/isc/histo.c b/lib/isc/histo.c index 395b27b6b6..048e1215ca 100644 --- a/lib/isc/histo.c +++ b/lib/isc/histo.c @@ -34,16 +34,6 @@ #define STRUCT_FLEX_SIZE(pointer, member, count) \ (sizeof(*(pointer)) + sizeof(*(pointer)->member) * (count)) -/* - * XXXFANF this should probably be in too - */ -#define OUTARG(ptr, val) \ - ({ \ - if ((ptr) != NULL) { \ - *(ptr) = (val); \ - } \ - }) - #define HISTO_MAGIC ISC_MAGIC('H', 's', 't', 'o') #define HISTO_VALID(p) ISC_MAGIC_VALID(p, HISTO_MAGIC) #define HISTOMULTI_MAGIC ISC_MAGIC('H', 'g', 'M', 't') diff --git a/lib/isc/include/isc/util.h b/lib/isc/include/isc/util.h index eb99583e20..712c8c727a 100644 --- a/lib/isc/include/isc/util.h +++ b/lib/isc/include/isc/util.h @@ -96,6 +96,16 @@ #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) +/* + * Optional return values, or out-arguments + */ +#define OUTARG(ptr, val) \ + ({ \ + if ((ptr) != NULL) { \ + *(ptr) = (val); \ + } \ + }) + /*% * Use this in translation units that would otherwise be empty, to * suppress compiler warnings.