From: Evan Hunt Date: Thu, 4 Jun 2026 16:49:41 +0000 (-0700) Subject: Add "warn_unused_result" to attributes.h X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=849aaacaae5613f959ddca2e6d3d36428945bc77;p=thirdparty%2Fbind9.git Add "warn_unused_result" to attributes.h A new ISC_ATTR_WARN_UNUSED_RESULT macro now defines __attribute__((warn_unused_result)) and is used for dns_rdata_fromstruct(). (cherry picked from commit 07c8c1d2421fdb4beb1b7821fe9033ff7d66b46a) --- diff --git a/configure.ac b/configure.ac index 53c3f269763..2278a5d7633 100644 --- a/configure.ac +++ b/configure.ac @@ -491,6 +491,11 @@ AC_COMPILE_IFELSE( # AX_GCC_FUNC_ATTRIBUTE([returns_nonnull]) +# +# check for GCC returns_nonnull attribute +# +AX_GCC_FUNC_ATTRIBUTE([warn_unused_result]) + # # how to link math functions? # diff --git a/lib/dns/include/dns/rdata.h b/lib/dns/include/dns/rdata.h index 02ac4eef221..b014c5751f2 100644 --- a/lib/dns/include/dns/rdata.h +++ b/lib/dns/include/dns/rdata.h @@ -468,6 +468,7 @@ dns_rdata_tofmttext(dns_rdata_t *rdata, const dns_name_t *origin, * it is undefined and falls back to the default value of 'width' */ +ISC_ATTR_WARN_UNUSED_RESULT isc_result_t dns_rdata_fromstruct(dns_rdata_t *rdata, dns_rdataclass_t rdclass, dns_rdatatype_t type, void *source, isc_buffer_t *target); diff --git a/lib/isc/include/isc/attributes.h b/lib/isc/include/isc/attributes.h index aab0629c459..15958b93a99 100644 --- a/lib/isc/include/isc/attributes.h +++ b/lib/isc/include/isc/attributes.h @@ -35,6 +35,12 @@ #define ISC_ATTR_RETURNS_NONNULL #endif +#if HAVE_FUNC_ATTRIBUTE_WARN_UNUSED_RESULT +#define ISC_ATTR_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) +#else +#define ISC_ATTR_WARN_UNUSED_RESULT +#endif + #ifdef HAVE_FUNC_ATTRIBUTE_MALLOC /* * Indicates that a function is malloc-like, i.e., that the diff --git a/tests/dns/private_test.c b/tests/dns/private_test.c index f65408bdd06..0ab974f34c0 100644 --- a/tests/dns/private_test.c +++ b/tests/dns/private_test.c @@ -97,6 +97,7 @@ make_signing(signing_testcase_t *testcase, dns_rdata_t *private, static void make_nsec3(nsec3_testcase_t *testcase, dns_rdata_t *private, unsigned char *pbuf) { + isc_result_t result; dns_rdata_nsec3param_t params; dns_rdata_t nsec3param = DNS_RDATA_INIT; unsigned char bufdata[BUFSIZ]; @@ -134,8 +135,9 @@ make_nsec3(nsec3_testcase_t *testcase, dns_rdata_t *private, } isc_buffer_init(&buf, bufdata, sizeof(bufdata)); - dns_rdata_fromstruct(&nsec3param, dns_rdataclass_in, - dns_rdatatype_nsec3param, ¶ms, &buf); + result = dns_rdata_fromstruct(&nsec3param, dns_rdataclass_in, + dns_rdatatype_nsec3param, ¶ms, &buf); + assert_int_equal(result, ISC_R_SUCCESS); dns_rdata_init(private);