Skip to content

Commit

Permalink
Merge pull request #17136 from opensourcerouting/clang-sa-19
Browse files Browse the repository at this point in the history
*: fix clang-19 SA
  • Loading branch information
donaldsharp authored Oct 17, 2024
2 parents 5fecb1f + b5f196c commit 466efab
Show file tree
Hide file tree
Showing 17 changed files with 168 additions and 252 deletions.
73 changes: 23 additions & 50 deletions bgpd/bgp_fsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -2776,99 +2776,72 @@ int bgp_gr_update_all(struct bgp *bgp, enum global_gr_command global_gr_cmd)

const char *print_peer_gr_mode(enum peer_mode pr_mode)
{
const char *peer_gr_mode = NULL;

switch (pr_mode) {
case PEER_HELPER:
peer_gr_mode = "PEER_HELPER";
break;
return "PEER_HELPER";
case PEER_GR:
peer_gr_mode = "PEER_GR";
break;
return "PEER_GR";
case PEER_DISABLE:
peer_gr_mode = "PEER_DISABLE";
break;
return "PEER_DISABLE";
case PEER_INVALID:
peer_gr_mode = "PEER_INVALID";
break;
return "PEER_INVALID";
case PEER_GLOBAL_INHERIT:
peer_gr_mode = "PEER_GLOBAL_INHERIT";
break;
return "PEER_GLOBAL_INHERIT";
}

return peer_gr_mode;
return NULL;
}

const char *print_peer_gr_cmd(enum peer_gr_command pr_gr_cmd)
{
const char *peer_gr_cmd = NULL;

switch (pr_gr_cmd) {
case PEER_GR_CMD:
peer_gr_cmd = "PEER_GR_CMD";
break;
return "PEER_GR_CMD";
case NO_PEER_GR_CMD:
peer_gr_cmd = "NO_PEER_GR_CMD";
break;
return "NO_PEER_GR_CMD";
case PEER_DISABLE_CMD:
peer_gr_cmd = "PEER_DISABLE_GR_CMD";
break;
return "PEER_DISABLE_GR_CMD";
case NO_PEER_DISABLE_CMD:
peer_gr_cmd = "NO_PEER_DISABLE_GR_CMD";
break;
return "NO_PEER_DISABLE_GR_CMD";
case PEER_HELPER_CMD:
peer_gr_cmd = "PEER_HELPER_CMD";
break;
return "PEER_HELPER_CMD";
case NO_PEER_HELPER_CMD:
peer_gr_cmd = "NO_PEER_HELPER_CMD";
break;
return "NO_PEER_HELPER_CMD";
}

return peer_gr_cmd;
return NULL;
}

const char *print_global_gr_mode(enum global_mode gl_mode)
{
const char *global_gr_mode = "???";

switch (gl_mode) {
case GLOBAL_HELPER:
global_gr_mode = "GLOBAL_HELPER";
break;
return "GLOBAL_HELPER";
case GLOBAL_GR:
global_gr_mode = "GLOBAL_GR";
break;
return "GLOBAL_GR";
case GLOBAL_DISABLE:
global_gr_mode = "GLOBAL_DISABLE";
break;
return "GLOBAL_DISABLE";
case GLOBAL_INVALID:
global_gr_mode = "GLOBAL_INVALID";
break;
return "GLOBAL_INVALID";
}

return global_gr_mode;
return "???";
}

const char *print_global_gr_cmd(enum global_gr_command gl_gr_cmd)
{
const char *global_gr_cmd = NULL;

switch (gl_gr_cmd) {
case GLOBAL_GR_CMD:
global_gr_cmd = "GLOBAL_GR_CMD";
break;
return "GLOBAL_GR_CMD";
case NO_GLOBAL_GR_CMD:
global_gr_cmd = "NO_GLOBAL_GR_CMD";
break;
return "NO_GLOBAL_GR_CMD";
case GLOBAL_DISABLE_CMD:
global_gr_cmd = "GLOBAL_DISABLE_CMD";
break;
return "GLOBAL_DISABLE_CMD";
case NO_GLOBAL_DISABLE_CMD:
global_gr_cmd = "NO_GLOBAL_DISABLE_CMD";
break;
return "NO_GLOBAL_DISABLE_CMD";
}

return global_gr_cmd;
return NULL;
}

enum global_mode bgp_global_gr_mode_get(struct bgp *bgp)
Expand Down
6 changes: 6 additions & 0 deletions bgpd/bgp_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,13 @@ static uint16_t bgp_read(struct peer_connection *connection, int *code_p)

readsize = MIN(ibuf_work_space, sizeof(ibuf_scratch));

#ifdef __clang_analyzer__
/* clang-SA doesn't want you to call read() while holding a mutex */
(void)readsize;
nbytes = 0;
#else
nbytes = read(connection->fd, ibuf_scratch, readsize);
#endif

/* EAGAIN or EWOULDBLOCK; come back later */
if (nbytes < 0 && ERRNO_IO_RETRY(errno)) {
Expand Down
2 changes: 2 additions & 0 deletions ldpd/ldpe.c
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,8 @@ static void ldpe_dispatch_main(struct event *thread)
tnbr_update_all(AF_UNSPEC);
break;
case IMSG_RECONF_CONF:
if (nconf)
ldp_clear_config(nconf);
if ((nconf = malloc(sizeof(struct ldpd_conf))) == NULL)
fatal(NULL);
memcpy(nconf, imsg.data, sizeof(struct ldpd_conf));
Expand Down
3 changes: 3 additions & 0 deletions lib/defun_lex.l
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ SPECIAL [(),]
%%
#else
extern int def_yylex(void);
extern int def_yylex_destroy(void);
#endif /* __clang_analyzer__ */
static int yylex_clr(char **retbuf)
Expand Down
2 changes: 1 addition & 1 deletion lib/netns_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ static void ns_disable_internal(struct ns *ns)
if (ns_master.ns_disable_hook)
(*ns_master.ns_disable_hook)(ns);

if (have_netns())
if (have_netns() && ns->fd >= 0)
close(ns->fd);

ns->fd = -1;
Expand Down
26 changes: 11 additions & 15 deletions lib/ptm_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,22 +308,18 @@ static int _ptm_lib_read_ptm_socket(int fd, char *buf, int len)
while (bytes_read != len) {
rc = recv(fd, (void *)(buf + bytes_read), (len - bytes_read),
MSG_DONTWAIT);
if (rc <= 0) {
if (errno && (errno != EAGAIN)
&& (errno != EWOULDBLOCK)) {
ERRLOG("fatal recv error(%s), closing connection, rc %d\n",
strerror(errno), rc);
return (rc);
} else {
if (retries++ < 2) {
usleep(10000);
continue;
}
DLOG("max retries - recv error(%d - %s) bytes read %d (%d)\n",
errno, strerror(errno), bytes_read, len);
return (bytes_read);
if (rc < 0 && (errno != EAGAIN) && (errno != EWOULDBLOCK)) {
ERRLOG("fatal recv error(%s), closing connection, rc %d\n", strerror(errno),
rc);
return (rc);
} else if (rc <= 0) {
if (retries++ < 2) {
usleep(10000);
continue;
}
break;
DLOG("max retries - recv error(%d - %s) bytes read %d (%d)\n", errno,
strerror(errno), bytes_read, len);
return (bytes_read);
} else {
bytes_read += rc;
}
Expand Down
61 changes: 19 additions & 42 deletions lib/zclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,21 +251,16 @@ enum zebra_error_types {

static inline const char *zebra_error_type2str(enum zebra_error_types type)
{
const char *ret = "UNKNOWN";

switch (type) {
case ZEBRA_UNKNOWN_ERROR:
ret = "ZEBRA_UNKNOWN_ERROR";
break;
return "ZEBRA_UNKNOWN_ERROR";
case ZEBRA_NO_VRF:
ret = "ZEBRA_NO_VRF";
break;
return "ZEBRA_NO_VRF";
case ZEBRA_INVALID_MSG_TYPE:
ret = "ZEBRA_INVALID_MSG_TYPE";
break;
return "ZEBRA_INVALID_MSG_TYPE";
}

return ret;
return "UNKNOWN";
}

struct redist_proto {
Expand Down Expand Up @@ -780,69 +775,51 @@ enum zclient_send_status {
static inline const char *
zapi_nhg_notify_owner2str(enum zapi_nhg_notify_owner note)
{
const char *ret = "UNKNOWN";

switch (note) {
case ZAPI_NHG_FAIL_INSTALL:
ret = "ZAPI_NHG_FAIL_INSTALL";
break;
return "ZAPI_NHG_FAIL_INSTALL";
case ZAPI_NHG_INSTALLED:
ret = "ZAPI_NHG_INSTALLED";
break;
return "ZAPI_NHG_INSTALLED";
case ZAPI_NHG_REMOVE_FAIL:
ret = "ZAPI_NHG_REMOVE_FAIL";
break;
return "ZAPI_NHG_REMOVE_FAIL";
case ZAPI_NHG_REMOVED:
ret = "ZAPI_NHG_REMOVED";
break;
return "ZAPI_NHG_REMOVED";
}

return ret;
return "UNKNOWN";
}

static inline const char *
zapi_rule_notify_owner2str(enum zapi_rule_notify_owner note)
{
const char *ret = "UNKNOWN";

switch (note) {
case ZAPI_RULE_FAIL_INSTALL:
ret = "ZAPI_RULE_FAIL_INSTALL";
break;
return "ZAPI_RULE_FAIL_INSTALL";
case ZAPI_RULE_INSTALLED:
ret = "ZAPI_RULE_INSTALLED";
break;
return "ZAPI_RULE_INSTALLED";
case ZAPI_RULE_FAIL_REMOVE:
ret = "ZAPI_RULE_FAIL_REMOVE";
break;
return "ZAPI_RULE_FAIL_REMOVE";
case ZAPI_RULE_REMOVED:
ret = "ZAPI_RULE_REMOVED";
break;
return "ZAPI_RULE_REMOVED";
}

return ret;
return "UNKNOWN";
}

static inline const char *zapi_srv6_sid_notify2str(enum zapi_srv6_sid_notify note)
{
const char *ret = "UNKNOWN";

switch (note) {
case ZAPI_SRV6_SID_FAIL_ALLOC:
ret = "ZAPI_SRV6_SID_FAIL_ALLOC";
break;
return "ZAPI_SRV6_SID_FAIL_ALLOC";
case ZAPI_SRV6_SID_ALLOCATED:
ret = "ZAPI_SRV6_SID_ALLOCATED";
break;
return "ZAPI_SRV6_SID_ALLOCATED";
case ZAPI_SRV6_SID_FAIL_RELEASE:
ret = "ZAPI_SRV6_SID_FAIL_RELEASE";
break;
return "ZAPI_SRV6_SID_FAIL_RELEASE";
case ZAPI_SRV6_SID_RELEASED:
ret = "ZAPI_SRV6_SID_RELEASED";
break;
return "ZAPI_SRV6_SID_RELEASED";
}

return ret;
return "UNKNOWN";
}

/* Zebra MAC types */
Expand Down
1 change: 1 addition & 0 deletions lib/zlog_5424_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,7 @@ static int log_5424_config_write(struct vty *vty)

vty_out(vty, "log extended %s\n", cfg->name);

(void)fmt_str; /* clang-SA */
switch (cfg->cfg.fmt) {
case ZLOG_FMT_5424:
fmt_str = " format rfc5424";
Expand Down
2 changes: 2 additions & 0 deletions pimd/pim6_mld.c
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,8 @@ static void gm_sg_update(struct gm_sg *sg, bool has_expired)

static void gm_packet_free(struct gm_packet_state *pkt)
{
assert(pkt->iface);

gm_packet_expires_del(pkt->iface->expires, pkt);
gm_packets_del(pkt->subscriber->packets, pkt);
gm_subscriber_drop(&pkt->subscriber);
Expand Down
2 changes: 1 addition & 1 deletion pimd/pim_autorp.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ static bool pim_autorp_discovery(struct pim_autorp *autorp, uint8_t rpcnt,
struct autorp_pkt_grp *grp;
size_t offset = 0;
pim_addr rp_addr;
struct prefix grppfix;
struct prefix grppfix = {};
char plname[32];
struct prefix_list *pl;
struct prefix_list_entry *ple;
Expand Down
3 changes: 3 additions & 0 deletions pimd/pim_bsr_rpdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,9 @@ int pim_crp_process(struct interface *ifp, pim_sgaddr *src_dst, uint8_t *buf,
buf += sizeof(*crp_hdr);
remain -= sizeof(*crp_hdr);

/* ignore trailing data */
(void)buf;

size_t ngroups = crp_hdr->prefix_cnt;

if (remain < ngroups * sizeof(struct pim_encoded_group_ipv4)) {
Expand Down
12 changes: 4 additions & 8 deletions vtysh/vtysh.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,6 @@ static int vtysh_client_run(struct vtysh_client *vclient, const char *line,
nread = vtysh_client_receive(
vclient, bufvalid, buf + bufsz - bufvalid - 1, pass_fd);

if (nread < 0 && (errno == EINTR || errno == EAGAIN))
continue;

if (nread <= 0) {
if (vty->of)
vty_out(vty,
Expand Down Expand Up @@ -698,7 +695,7 @@ static char *trim(char *s)
int vtysh_mark_file(const char *filename)
{
struct vty *vty;
FILE *confp = NULL;
FILE *confp = NULL, *closefp = NULL;
int ret;
vector vline;
int tried = 0;
Expand All @@ -711,7 +708,7 @@ int vtysh_mark_file(const char *filename)
if (strncmp("-", filename, 1) == 0)
confp = stdin;
else
confp = fopen(filename, "r");
confp = closefp = fopen(filename, "r");

if (confp == NULL) {
fprintf(stderr, "%% Can't open config file %s due to '%s'.\n",
Expand Down Expand Up @@ -851,9 +848,8 @@ int vtysh_mark_file(const char *filename)
vty_close(vty);
XFREE(MTYPE_VTYSH_CMD, vty_buf_copy);

if (confp != stdin)
fclose(confp);

if (closefp)
fclose(closefp);
return 0;
}

Expand Down
Loading

0 comments on commit 466efab

Please sign in to comment.