Skip to content

Commit

Permalink
Merge pull request #35 from wolframroesler/more-clang-tidy-findings
Browse files Browse the repository at this point in the history
Fix more clang tidy findings
  • Loading branch information
troglobit authored May 18, 2020
2 parents 148786d + d6180fd commit d7c3191
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 27 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*~
*.swp
.config
.unpacked
autom4te.cache/
Expand All @@ -20,4 +21,4 @@ libtool
ltmain.sh
missing
stamp-h1
mdnsd.service
mdnsd.service
Binary file removed libmdnsd/.1035.c.swp
Binary file not shown.
12 changes: 6 additions & 6 deletions libmdnsd/1035.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

unsigned short int net2short(unsigned char **bufp)
{
short int i;
unsigned short int i;

i = **bufp;
i <<= 8;
Expand Down Expand Up @@ -146,7 +146,7 @@ static int _label(struct message *m, unsigned char **bufp, char **namep)
/* No cache, so cache it if room */
if (x < MAX_NUM_LABELS && m->_labels[x] == 0)
m->_labels[x] = *namep;
m->_len += (name - *namep) + 1;
m->_len += (int)(name - *namep) + 1;

return 0;
}
Expand Down Expand Up @@ -200,7 +200,7 @@ static int _host(struct message *m, unsigned char **bufp, const char *name)
if (name[y] == '.') {
if (!name[y + 1])
break;
label[last] = x - (last + 1);
label[last] = (char)(x - (last + 1));
last = x;
} else {
label[x] = name[y];
Expand All @@ -212,7 +212,7 @@ static int _host(struct message *m, unsigned char **bufp, const char *name)
y++;
}

label[last] = x - (last + 1);
label[last] = (char)(x - (last + 1));
if (x == 1)
x--; /* Special case, bad names, but handle correctly */
len = x + 1;
Expand All @@ -225,7 +225,7 @@ static int _host(struct message *m, unsigned char **bufp, const char *name)
/* Matching label, set up pointer */
l = label + x;
short2net((unsigned char *)m->_labels[y] - m->_packet, (unsigned char **)&l);
label[x] |= 0xc0;
label[x] |= '\xc0';
len = x + 2;
break;
}
Expand Down Expand Up @@ -516,5 +516,5 @@ int message_packet_len(struct message *m)
if (m->_buf == 0)
return 12;

return m->_buf - m->_packet;
return (int)(m->_buf - m->_packet);
}
19 changes: 10 additions & 9 deletions libmdnsd/mdnsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@ static mdns_record_t *_r_next(mdns_daemon_t *d, mdns_record_t *r, const char *ho
return 0;
}

static int _rr_len(mdns_answer_t *rr)
static size_t _rr_len(mdns_answer_t *rr)
{
int len = 12; /* name is always compressed (dup of earlier), plus normal stuff */
size_t len = 12; /* name is always compressed (dup of earlier), plus normal stuff */

if (rr->rdata)
len += rr->rdlen;
Expand Down Expand Up @@ -205,9 +205,9 @@ static int _a_match(struct resource *r, mdns_answer_t *a)
}

/* Compare time values easily */
static int _tvdiff(struct timeval old, struct timeval new)
static long _tvdiff(struct timeval old, struct timeval new)
{
int udiff = 0;
long udiff = 0;

if (old.tv_sec != new.tv_sec)
udiff = (new.tv_sec - old.tv_sec) * 1000000;
Expand Down Expand Up @@ -597,7 +597,7 @@ static int _r_out(mdns_daemon_t *d, struct message *m, mdns_record_t **list)
mdns_record_t *r;
int ret = 0;

while ((r = *list) != NULL && message_packet_len(m) + _rr_len(&r->rr) < d->frame) {
while ((r = *list) != NULL && message_packet_len(m) + (int)_rr_len(&r->rr) < d->frame) {
if (r != r->list)
*list = r->list;
else
Expand Down Expand Up @@ -927,7 +927,7 @@ int mdnsd_out(mdns_daemon_t *d, struct message *m, struct in_addr *ip, unsigned
mdns_record_t *last = NULL;
mdns_record_t *next;

while (cur && message_packet_len(m) + _rr_len(&cur->rr) < d->frame) {
while (cur && message_packet_len(m) + (int)_rr_len(&cur->rr) < d->frame) {
if (cur->rr.type == QTYPE_PTR) {
INFO("Send Publish PTR: Name: %s, rdlen: %d, rdata: %s, rdname: %s", cur->rr.name,cur->rr.rdlen, cur->rr.rdata, cur->rr.rdname);
} else if (cur->rr.type == QTYPE_SRV) {
Expand Down Expand Up @@ -1066,7 +1066,7 @@ int mdnsd_out(mdns_daemon_t *d, struct message *m, struct in_addr *ip, unsigned
/* If room, add all known good entries */
c = 0;
while ((c = _c_next(d, c, q->name, q->type)) != 0 && c->rr.ttl > (unsigned long)d->now.tv_sec + 8 &&
message_packet_len(m) + _rr_len(&c->rr) < d->frame) {
message_packet_len(m) + (int)_rr_len(&c->rr) < d->frame) {

INFO("Add known answer: Name: %s, Type: %d", c->rr.name, c->rr.type);
message_an(m, q->name, (unsigned short)q->type, (unsigned short)d->class, c->rr.ttl - (unsigned long)d->now.tv_sec);
Expand Down Expand Up @@ -1094,7 +1094,7 @@ int mdnsd_out(mdns_daemon_t *d, struct message *m, struct in_addr *ip, unsigned
struct timeval *mdnsd_sleep(mdns_daemon_t *d)
{
time_t expire;
int sec, usec;
long usec;

d->sleep.tv_sec = d->sleep.tv_usec = 0;

Expand Down Expand Up @@ -1127,7 +1127,8 @@ struct timeval *mdnsd_sleep(mdns_daemon_t *d)

/* Also check for queries with known answer expiration/retry */
if (d->checkqlist) {
if ((sec = d->checkqlist - d->now.tv_sec) > 0)
long sec;
if ((sec = (long)d->checkqlist - d->now.tv_sec) > 0)
d->sleep.tv_sec = sec;
RET;
}
Expand Down
18 changes: 9 additions & 9 deletions libmdnsd/sdtxt.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
#include <stdlib.h>
#include <string.h>

static int _sd2txt_len(const char *key, char *val)
static size_t _sd2txt_len(const char *key, char *val)
{
int ret = strlen(key);
size_t ret = strlen(key);

if (!*val)
return ret;
Expand All @@ -47,18 +47,18 @@ static int _sd2txt_len(const char *key, char *val)

static void _sd2txt_count(xht_t *__attribute__((unused)) h, const char *key, void *val, void *arg)
{
int *count = (int *)arg;
int *const count = arg;

*count += _sd2txt_len(key, (char *)val) + 1;
*count += (int)_sd2txt_len(key, val) + 1;
}

static void _sd2txt_write(xht_t *__attribute__((unused)) h, const char *key, void *val, void *arg)
{
unsigned char **txtp = (unsigned char **)arg;
char *cval = (char *)val;
unsigned char **txtp = arg;
char *const cval = val;

/* Copy in lengths, then strings */
**txtp = _sd2txt_len(key, (char *)val);
**txtp = _sd2txt_len(key, val);
(*txtp)++;
memcpy(*txtp, key, strlen(key));
*txtp += strlen(key);
Expand All @@ -77,7 +77,7 @@ unsigned char *sd2txt(xht_t *h, int *len)

*len = 0;

xht_walk(h, _sd2txt_count, (void *)len);
xht_walk(h, _sd2txt_count, len);
if (!*len) {
*len = 1;
return (unsigned char *)strdup("");
Expand Down Expand Up @@ -111,7 +111,7 @@ xht_t *txt2sd(unsigned char *txt, int len)
val = strchr(key, '=');
if (val) {
*val++ = 0;
xht_store(h, key, strlen(key), val, strlen(val));
xht_store(h, key, (int)strlen(key), val, (int)strlen(val));
}
}

Expand Down
10 changes: 8 additions & 2 deletions src/conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,14 @@ static void read_line(char *line, struct conf_srec *srec)
srec->type = strdup(arg);
if (match(token, "name"))
srec->name = strdup(arg);
if (match(token, "port"))
srec->port = atoi(arg);
if (match(token, "port")) {
char *end;
srec->port = (int)strtol(arg, &end, 10);
if (*end) {
DBG("Bad port number: %s", arg);
return;
}
}
if (match(token, "target"))
srec->target = strdup(arg);
if (match(token, "cname"))
Expand Down

0 comments on commit d7c3191

Please sign in to comment.