From 37c6cee5d5e545216c50c9115515554237bc2503 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wolfram=20R=C3=B6sler?= Date: Fri, 8 May 2020 12:40:16 +0200 Subject: [PATCH] Remove dead store, redundant cast, and possible NULL dereference Found during static analysis with clang-tidy-9. --- libmdnsd/1035.c | 4 ++-- libmdnsd/mdnsd.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libmdnsd/1035.c b/libmdnsd/1035.c index cede54c..3639a5b 100644 --- a/libmdnsd/1035.c +++ b/libmdnsd/1035.c @@ -470,7 +470,7 @@ void message_rdata_srv(struct message *m, unsigned short int priority, unsigned void message_rdata_raw(struct message *m, unsigned char *rdata, unsigned short int rdlength) { - if (((unsigned char *)m->_buf - m->_packet) + rdlength > 4096) + if ((m->_buf - m->_packet) + rdlength > 4096) rdlength = 0; short2net(rdlength, &(m->_buf)); memcpy(m->_buf, rdata, rdlength); @@ -516,5 +516,5 @@ int message_packet_len(struct message *m) if (m->_buf == 0) return 12; - return (unsigned char *)m->_buf - m->_packet; + return m->_buf - m->_packet; } diff --git a/libmdnsd/mdnsd.c b/libmdnsd/mdnsd.c index 2b35ca1..353b386 100644 --- a/libmdnsd/mdnsd.c +++ b/libmdnsd/mdnsd.c @@ -995,7 +995,7 @@ int mdnsd_out(mdns_daemon_t *d, struct message *m, struct in_addr *ip, unsigned if (d->probing == r) d->probing = r->list; - else + else if (last) last->list = r->list; r->list = 0; @@ -1014,7 +1014,7 @@ int mdnsd_out(mdns_daemon_t *d, struct message *m, struct in_addr *ip, unsigned } /* Scan probe list again to append our to-be answers */ - for (r = d->probing; r != 0; last = r, r = r->list) { + for (r = d->probing; r != 0; r = r->list) { r->unique++; INFO("Send Answer in Probe: Name: %s, Type: %d", r->rr.name, r->rr.type);