Skip to content

Commit

Permalink
Merge pull request #146 from clumens/static-analysis
Browse files Browse the repository at this point in the history
Refactor: Fix problems found by clang.
  • Loading branch information
clumens authored Jun 28, 2024
2 parents dbf1b73 + f31d896 commit 7f83c1b
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/alt/nametag_libsystemd.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ void sd_notify_wrapper(const char *fmt, ...)
rv = vsnprintf(buffer, sizeof(buffer), suffix, ap);
va_end(ap);

if (rv < 0) {
log_warn("%s:%d: vsnprintf fail", __FILE__, __LINE__);
}

rv = sd_notifyf(0, "READY=1\n"
"STATUS=Running: %s",
buffer);
Expand Down
2 changes: 1 addition & 1 deletion src/attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void print_geostore_usage(void)
int test_attr_reply(cmd_result_t reply_code, cmd_request_t cmd)
{
int rv = 0;
const char *op_str = "";
const char *op_str = NULL;

switch (cmd) {
case ATTR_SET: op_str = "set"; break;
Expand Down
3 changes: 1 addition & 2 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ static int loop(int fd)
static int test_reply(cmd_result_t reply_code, cmd_request_t cmd)
{
int rv = 0;
const char *op_str = "";
const char *op_str = NULL;

if (cmd == CMD_GRANT)
op_str = "grant";
Expand Down Expand Up @@ -743,7 +743,6 @@ static int query_get_string_answer(cmd_request_t cmd)
*(data + data_len) = '\0';
(void)fputs(data, stdout);
fflush(stdout);
rv = 0;

out_test_reply:
rv = test_reply_f(ntohl(reply.header.result), cmd);
Expand Down
2 changes: 1 addition & 1 deletion src/ticket.c
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ void reset_ticket_and_set_no_leader(struct ticket_config *tk)
static void log_reacquire_reason(struct ticket_config *tk)
{
int valid;
const char *where_granted = "\0";
const char *where_granted = NULL;
char buff[75];

valid = is_time_set(&tk->term_expires) && !is_past(&tk->term_expires);
Expand Down
11 changes: 8 additions & 3 deletions src/transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,13 @@ int _find_myself(int family, struct booth_site **mep, int fuzzy_allowed)
if (tb[IFA_LOCAL]) {
memcpy(ipaddr, RTA_DATA(tb[IFA_LOCAL]),
BOOTH_IPADDR_LEN);
} else {
} else if (tb[IFA_ADDRESS]) {
memcpy(ipaddr, RTA_DATA(tb[IFA_ADDRESS]),
BOOTH_IPADDR_LEN);
} else {
log_error("failed to copy netlink addr");
close(fd);
return 0;
}

/* Try to find the exact address or the address with subnet matching.
Expand Down Expand Up @@ -386,6 +390,8 @@ int read_client(struct client *req_cl)
log_error("out of memory for client messages");
return -1;
}

memset(msg, 0, MAX_MSG_LEN);
req_cl->msg = (void *)msg;
} else {
msg = (char *)req_cl->msg;
Expand Down Expand Up @@ -615,8 +621,7 @@ static int connect_nonb(int sockfd, const struct sockaddr *saptr,
tval.tv_sec = sec;
tval.tv_usec = 0;

if ((n = select(sockfd + 1, &rset, &wset, NULL,
sec ? &tval : NULL)) == 0) {
if (select(sockfd + 1, &rset, &wset, NULL, sec ? &tval : NULL) == 0) {
/* leave outside function to close */
/* timeout */
/* close(sockfd); */
Expand Down

0 comments on commit 7f83c1b

Please sign in to comment.