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 07c8c1d242)
This commit is contained in:
Evan Hunt 2026-06-04 09:49:41 -07:00
parent 65a3694f2a
commit 849aaacaae
4 changed files with 16 additions and 2 deletions

View file

@ -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?
#

View file

@ -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);

View file

@ -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

View file

@ -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, &params, &buf);
result = dns_rdata_fromstruct(&nsec3param, dns_rdataclass_in,
dns_rdatatype_nsec3param, &params, &buf);
assert_int_equal(result, ISC_R_SUCCESS);
dns_rdata_init(private);