From 75829cad18c73a9b74fa1bc5d6c7be29a410ca13 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Tue, 6 Jul 2021 13:10:16 +1200 Subject: [PATCH] Avoid -Werror=strict-overflow on in rk_dns_srv_order() MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit In a strict Samba build with -Werror=strict-overflow on Ubuntu 18.04 with gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04) we see ../../source4/heimdal/lib/roken/resolve.c: In function ‘rk_dns_srv_order’: ../../source4/heimdal/lib/roken/resolve.c:639:7: error: assuming signed overflow does not occur when simplifying conditional to constant [-Werror=strict-overflow] if(num_srv == 0) ^ cc1: all warnings being treated as errors This avoids the issue by additionally setting a distinct flag. Signed-off-by: Andrew Bartlett --- lib/roken/resolve.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/roken/resolve.c b/lib/roken/resolve.c index 98be0cb87..31da4136d 100644 --- a/lib/roken/resolve.c +++ b/lib/roken/resolve.c @@ -629,14 +629,17 @@ rk_dns_srv_order(struct rk_dns_reply *r) struct rk_resource_record **srvs, **ss, **headp; struct rk_resource_record *rr; int num_srv = 0; + unsigned int srv_found = FALSE; rk_random_init(); for(rr = r->head; rr; rr = rr->next) - if(rr->type == rk_ns_t_srv) + if(rr->type == rk_ns_t_srv) { num_srv++; + srv_found = TRUE; + } - if(num_srv == 0) + if(srv_found == FALSE) return; srvs = malloc(num_srv * sizeof(*srvs)); -- 2.11.4.GIT