Skip to content

Commit

Permalink
Nits that came out of clang analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
wtoorop committed Dec 4, 2024
1 parent 57f9589 commit 9aab672
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
2 changes: 2 additions & 0 deletions nsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,9 @@ readpid(const char *file)
}

if (((l = read(fd, pidbuf, sizeof(pidbuf)))) == -1) {
int errno_bak = errno;
close(fd);
errno = errno_bak;
return -1;
}

Expand Down
16 changes: 15 additions & 1 deletion tpkg/cutest/cutest_options.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#ifdef HAVE_STRING_H
#include <string.h>
#endif

#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
Expand Down Expand Up @@ -369,6 +369,13 @@ check_zonelist_file(CuTest *tc, struct nsd_options* opt, const char* s)
size_t delcount = 0;
fflush(opt->zonelist);
in = fopen(opt->zonelistfile, "r");
if(in == NULL) {
printf("Error opening zonelistfile \"%s\": %s\n",
(opt->zonelistfile ? opt->zonelistfile : "<nil>"),
strerror(errno));
CuAssertTrue(tc, 0);
return;
}
while(fgets(buf, sizeof(buf), in)) {
line++;
if(strncmp(buf, s, strlen(buf)) != 0) {
Expand All @@ -389,6 +396,13 @@ check_zonelist_file(CuTest *tc, struct nsd_options* opt, const char* s)
}
s += strlen(buf);
}
if(ferror(in)) {
printf("Error reading zonelistfile \"%s\": %s\n",
(opt->zonelistfile ? opt->zonelistfile : "<nil>"),
strerror(errno));
CuAssertTrue(tc, 0);
return;
}
if(*s != 0) {
printf("zonelist fail: expected more at EOF\n");
printf("wanted: %s\n", s);
Expand Down
3 changes: 3 additions & 0 deletions tpkg/cutest/popen3_echo.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ int main(int argc, char *argv[])
fds |= 4;

if (fds & 1)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-result"
fgets(buf, sizeof(buf), stdin);
#pragma GCC diagnostic pop
if ((fds & 3) == 3)
fprintf(stdout, "%sstdin,stdout,stderr\n%s", (fds & 1) ? "" : "!", buf);
if ((fds & 5) == 5)
Expand Down
12 changes: 10 additions & 2 deletions xfrd-notify.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,17 @@ xfrd_notify_send_udp(struct notify_zone* zone, int index)
int fd;
socklen_t to_len = xfrd_acl_sockaddr_to(
zone->pkts[index].dest, &to);
if(zone->pkts[index].dest->is_ipv6)
if(zone->pkts[index].dest->is_ipv6
&& zone->notify_send6_handler.ev_fd != -1)
fd = zone->notify_send6_handler.ev_fd;
else fd = zone->notify_send_handler.ev_fd;
else if (zone->notify_send_handler.ev_fd != -1)
fd = zone->notify_send_handler.ev_fd;
else {
log_msg(LOG_ERR, "xfrd notify: sendto %s failed %s",
zone->pkts[index].dest->ip_address_spec,
"invalid file descriptor");
return 0;
}
if(sendto(fd,
buffer_current(packet), buffer_remaining(packet), 0,
(struct sockaddr*)&to, to_len) == -1) {
Expand Down

0 comments on commit 9aab672

Please sign in to comment.