summaryrefslogtreecommitdiffstats
path: root/src/resolve
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2021-03-21 05:39:44 +0100
committerYu Watanabe <watanabe.yu+github@gmail.com>2021-03-23 13:30:23 +0100
commit06939d3b0c19b121491e6afe539309778461b0e6 (patch)
tree92335c24397eb0780bccac6c3454cb45def3257b /src/resolve
parentresolve: rename function argument in prototype to match its declaration (diff)
downloadsystemd-06939d3b0c19b121491e6afe539309778461b0e6.tar.xz
systemd-06939d3b0c19b121491e6afe539309778461b0e6.zip
resolve: use dns_answer_size() and dns_answer_isempty()
Diffstat (limited to 'src/resolve')
-rw-r--r--src/resolve/resolved-dns-answer.h33
1 files changed, 17 insertions, 16 deletions
diff --git a/src/resolve/resolved-dns-answer.h b/src/resolve/resolved-dns-answer.h
index e20c60b25e..7ecd8606bd 100644
--- a/src/resolve/resolved-dns-answer.h
+++ b/src/resolve/resolved-dns-answer.h
@@ -93,37 +93,38 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(DnsAnswer*, dns_answer_unref);
#define _DNS_ANSWER_FOREACH(q, kk, a) \
for (size_t UNIQ_T(i, q) = ({ \
- (kk) = ((a) && (a)->n_rrs > 0) ? (a)->items[0].rr : NULL; \
- 0; \
- }); \
- (a) && (UNIQ_T(i, q) < (a)->n_rrs); \
- UNIQ_T(i, q)++, (kk) = (UNIQ_T(i, q) < (a)->n_rrs ? (a)->items[UNIQ_T(i, q)].rr : NULL))
+ (kk) = dns_answer_isempty(a) ? NULL : (a)->items[0].rr; \
+ 0; \
+ }); \
+ UNIQ_T(i, q) < dns_answer_size(a); \
+ UNIQ_T(i, q)++, \
+ (kk) = UNIQ_T(i, q) < dns_answer_size(a) ? (a)->items[UNIQ_T(i, q)].rr : NULL)
#define DNS_ANSWER_FOREACH(kk, a) _DNS_ANSWER_FOREACH(UNIQ, kk, a)
#define _DNS_ANSWER_FOREACH_IFINDEX(q, kk, ifi, a) \
for (size_t UNIQ_T(i, q) = ({ \
- (kk) = ((a) && (a)->n_rrs > 0) ? (a)->items[0].rr : NULL; \
- (ifi) = ((a) && (a)->n_rrs > 0) ? (a)->items[0].ifindex : 0; \
+ (kk) = dns_answer_isempty(a) ? NULL : (a)->items[0].rr; \
+ (ifi) = dns_answer_isempty(a) ? 0 : (a)->items[0].ifindex; \
0; \
}); \
- (a) && (UNIQ_T(i, q) < (a)->n_rrs); \
+ UNIQ_T(i, q) < dns_answer_size(a); \
UNIQ_T(i, q)++, \
- (kk) = ((UNIQ_T(i, q) < (a)->n_rrs) ? (a)->items[UNIQ_T(i, q)].rr : NULL), \
- (ifi) = ((UNIQ_T(i, q) < (a)->n_rrs) ? (a)->items[UNIQ_T(i, q)].ifindex : 0))
+ (kk) = UNIQ_T(i, q) < dns_answer_size(a) ? (a)->items[UNIQ_T(i, q)].rr : NULL, \
+ (ifi) = UNIQ_T(i, q) < dns_answer_size(a) ? (a)->items[UNIQ_T(i, q)].ifindex : 0)
#define DNS_ANSWER_FOREACH_IFINDEX(kk, ifindex, a) _DNS_ANSWER_FOREACH_IFINDEX(UNIQ, kk, ifindex, a)
#define _DNS_ANSWER_FOREACH_FLAGS(q, kk, fl, a) \
for (size_t UNIQ_T(i, q) = ({ \
- (kk) = ((a) && (a)->n_rrs > 0) ? (a)->items[0].rr : NULL; \
- (fl) = ((a) && (a)->n_rrs > 0) ? (a)->items[0].flags : 0; \
+ (kk) = dns_answer_isempty(a) ? NULL : (a)->items[0].rr; \
+ (fl) = dns_answer_isempty(a) ? 0 : (a)->items[0].flags; \
0; \
}); \
- (a) && (UNIQ_T(i, q) < (a)->n_rrs); \
+ UNIQ_T(i, q) < dns_answer_size(a); \
UNIQ_T(i, q)++, \
- (kk) = ((UNIQ_T(i, q) < (a)->n_rrs) ? (a)->items[UNIQ_T(i, q)].rr : NULL), \
- (fl) = ((UNIQ_T(i, q) < (a)->n_rrs) ? (a)->items[UNIQ_T(i, q)].flags : 0))
+ (kk) = UNIQ_T(i, q) < dns_answer_size(a) ? (a)->items[UNIQ_T(i, q)].rr : NULL, \
+ (fl) = UNIQ_T(i, q) < dns_answer_size(a) ? (a)->items[UNIQ_T(i, q)].flags : 0)
#define DNS_ANSWER_FOREACH_FLAGS(kk, flags, a) _DNS_ANSWER_FOREACH_FLAGS(UNIQ, kk, flags, a)
@@ -134,6 +135,6 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(DnsAnswer*, dns_answer_unref);
}); \
UNIQ_T(i, q) < dns_answer_size(a); \
UNIQ_T(i, q)++, \
- (item) = ((UNIQ_T(i, q) < dns_answer_size(a)) ? (a)->items + UNIQ_T(i, q) : NULL))
+ (item) = (UNIQ_T(i, q) < dns_answer_size(a)) ? (a)->items + UNIQ_T(i, q) : NULL)
#define DNS_ANSWER_FOREACH_ITEM(item, a) _DNS_ANSWER_FOREACH_ITEM(UNIQ, item, a)