diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2022-05-12 16:37:10 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2022-05-12 17:15:51 +0200 |
commit | 14b71de4e143500cf872ef1ca2e2653cc941302b (patch) | |
tree | 4c3a23d41485579292dc8b50beb1106b87a8e5b5 /src/resolve | |
parent | 8b0c43475a764080299f1d69efc2cef0db7b6c66 (diff) | |
download | systemd-14b71de4e143500cf872ef1ca2e2653cc941302b.tar.gz |
resolved: use saturate_add()
Diffstat (limited to 'src/resolve')
-rw-r--r-- | src/resolve/resolved-dns-answer.c | 10 |
1 files changed, 2 insertions, 8 deletions
diff --git a/src/resolve/resolved-dns-answer.c b/src/resolve/resolved-dns-answer.c index 96ae9bc005..0394c3ec84 100644 --- a/src/resolve/resolved-dns-answer.c +++ b/src/resolve/resolved-dns-answer.c @@ -60,10 +60,7 @@ static int dns_answer_reserve_internal(DnsAnswer *a, size_t n) { m = ordered_set_size(a->items); assert(m <= UINT16_MAX); /* We can only place 64K RRs in an answer at max */ - if (n > UINT16_MAX - m) - n = UINT16_MAX; - else - n += m; + n = saturate_add(m, n, UINT16_MAX); /* Higher multipliers give slightly higher efficiency through hash collisions, but the gains * quickly drop off after 2. */ @@ -707,10 +704,7 @@ int dns_answer_reserve_or_clone(DnsAnswer **a, size_t n_free) { ns = dns_answer_size(*a); assert(ns <= UINT16_MAX); /* Maximum number of RRs we can stick into a DNS packet section */ - if (n_free > UINT16_MAX - ns) /* overflow check */ - ns = UINT16_MAX; - else - ns += n_free; + ns = saturate_add(ns, n_free, UINT16_MAX); n = dns_answer_new(ns); if (!n) |