Merge pull request #2054 from qlyoung/sa-fixes

Static analyzer fixes
This commit is contained in:
Renato Westphal 2018-04-15 19:10:50 -03:00 committed by GitHub
commit aecba4e88a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 54 additions and 65 deletions

View File

@ -176,6 +176,7 @@ insert_route(struct babel_route *route)
resize_route_table(max_route_slots < 1 ? 8 : 2 * max_route_slots); resize_route_table(max_route_slots < 1 ? 8 : 2 * max_route_slots);
if(route_slots >= max_route_slots) if(route_slots >= max_route_slots)
return NULL; return NULL;
assert(routes);
route->next = NULL; route->next = NULL;
if(n < route_slots) if(n < route_slots)
memmove(routes + n + 1, routes + n, memmove(routes + n + 1, routes + n,

View File

@ -592,6 +592,8 @@ void bgp_info_mpath_update(struct bgp_node *rn, struct bgp_info *new_best,
*/ */
new_mpath = listgetdata(mp_node); new_mpath = listgetdata(mp_node);
list_delete_node(mp_list, mp_node); list_delete_node(mp_list, mp_node);
assert(new_mpath);
assert(prev_mpath);
if ((mpath_count < maxpaths) && (new_mpath != new_best) if ((mpath_count < maxpaths) && (new_mpath != new_best)
&& bgp_info_nexthop_cmp(prev_mpath, new_mpath)) { && bgp_info_nexthop_cmp(prev_mpath, new_mpath)) {
if (new_mpath == next_mpath) if (new_mpath == next_mpath)

View File

@ -649,7 +649,6 @@ void bgp_notify_send_with_data(struct peer *peer, uint8_t code,
uint8_t sub_code, uint8_t *data, size_t datalen) uint8_t sub_code, uint8_t *data, size_t datalen)
{ {
struct stream *s; struct stream *s;
int length;
/* Lock I/O mutex to prevent other threads from pushing packets */ /* Lock I/O mutex to prevent other threads from pushing packets */
pthread_mutex_lock(&peer->io_mtx); pthread_mutex_lock(&peer->io_mtx);
@ -670,7 +669,7 @@ void bgp_notify_send_with_data(struct peer *peer, uint8_t code,
stream_write(s, data, datalen); stream_write(s, data, datalen);
/* Set BGP packet length. */ /* Set BGP packet length. */
length = bgp_packet_set_size(s); bgp_packet_set_size(s);
/* wipe output buffer */ /* wipe output buffer */
stream_fifo_clean(peer->obuf); stream_fifo_clean(peer->obuf);
@ -697,13 +696,13 @@ void bgp_notify_send_with_data(struct peer *peer, uint8_t code,
bgp_notify.code = code; bgp_notify.code = code;
bgp_notify.subcode = sub_code; bgp_notify.subcode = sub_code;
bgp_notify.data = NULL; bgp_notify.data = NULL;
bgp_notify.length = length - BGP_MSG_NOTIFY_MIN_SIZE; bgp_notify.length = datalen;
bgp_notify.raw_data = data; bgp_notify.raw_data = data;
peer->notify.code = bgp_notify.code; peer->notify.code = bgp_notify.code;
peer->notify.subcode = bgp_notify.subcode; peer->notify.subcode = bgp_notify.subcode;
if (bgp_notify.length) { if (bgp_notify.length && data) {
bgp_notify.data = bgp_notify.data =
XMALLOC(MTYPE_TMP, bgp_notify.length * 3); XMALLOC(MTYPE_TMP, bgp_notify.length * 3);
for (i = 0; i < bgp_notify.length; i++) for (i = 0; i < bgp_notify.length; i++)

View File

@ -7047,32 +7047,36 @@ void route_vty_out_overlay(struct vty *vty, struct prefix *p,
default: default:
vty_out(vty, "?"); vty_out(vty, "?");
} }
char *str = esi2str(&(attr->evpn_overlay.eth_s_id));
vty_out(vty, "%s", str);
XFREE(MTYPE_TMP, str);
if (IS_EVPN_PREFIX_IPADDR_V4((struct prefix_evpn *)p)) {
vty_out(vty, "/%s",
inet_ntoa(attr->evpn_overlay.gw_ip.ipv4));
} else if (IS_EVPN_PREFIX_IPADDR_V6((struct prefix_evpn *)p)) {
vty_out(vty, "/%s",
inet_ntop(AF_INET6,
&(attr->evpn_overlay.gw_ip.ipv6), buf,
BUFSIZ));
}
if (attr->ecommunity) {
char *mac = NULL;
struct ecommunity_val *routermac = ecommunity_lookup(
attr->ecommunity, ECOMMUNITY_ENCODE_EVPN,
ECOMMUNITY_EVPN_SUBTYPE_ROUTERMAC);
if (routermac)
mac = ecom_mac2str((char *)routermac->val);
if (mac) {
vty_out(vty, "/%s", (char *)mac);
XFREE(MTYPE_TMP, mac);
}
}
vty_out(vty, "\n");
} }
struct eth_segment_id *id = &(attr->evpn_overlay.eth_s_id);
char *str = esi2str(id);
vty_out(vty, "%s", str);
XFREE(MTYPE_TMP, str);
if (IS_EVPN_PREFIX_IPADDR_V4((struct prefix_evpn *)p)) {
vty_out(vty, "/%s", inet_ntoa(attr->evpn_overlay.gw_ip.ipv4));
} else if (IS_EVPN_PREFIX_IPADDR_V6((struct prefix_evpn *)p)) {
vty_out(vty, "/%s",
inet_ntop(AF_INET6, &(attr->evpn_overlay.gw_ip.ipv6),
buf, BUFSIZ));
}
if (attr->ecommunity) {
char *mac = NULL;
struct ecommunity_val *routermac = ecommunity_lookup(
attr->ecommunity, ECOMMUNITY_ENCODE_EVPN,
ECOMMUNITY_EVPN_SUBTYPE_ROUTERMAC);
if (routermac)
mac = ecom_mac2str((char *)routermac->val);
if (mac) {
vty_out(vty, "/%s", (char *)mac);
XFREE(MTYPE_TMP, mac);
}
}
vty_out(vty, "\n");
} }
/* dampening route */ /* dampening route */

View File

@ -548,13 +548,12 @@ rfapi_group_new(struct bgp *bgp, rfapi_group_cfg_type_t type, const char *name)
rfg = XCALLOC(MTYPE_RFAPI_GROUP_CFG, rfg = XCALLOC(MTYPE_RFAPI_GROUP_CFG,
sizeof(struct rfapi_nve_group_cfg)); sizeof(struct rfapi_nve_group_cfg));
if (rfg) { rfg->type = type;
rfg->type = type; rfg->name = strdup(name);
rfg->name = strdup(name); /* add to tail of list */
/* add to tail of list */ listnode_add(bgp->rfapi_cfg->nve_groups_sequential, rfg);
listnode_add(bgp->rfapi_cfg->nve_groups_sequential, rfg);
}
rfg->label = MPLS_LABEL_NONE; rfg->label = MPLS_LABEL_NONE;
QOBJ_REG(rfg, rfapi_nve_group_cfg); QOBJ_REG(rfg, rfapi_nve_group_cfg);
return rfg; return rfg;

View File

@ -23,6 +23,9 @@
*/ */
%{ %{
/* ignore flex generated code in static analyzer */
#ifndef __clang_analyzer__
/* ignore harmless bugs in old versions of flex */ /* ignore harmless bugs in old versions of flex */
#pragma GCC diagnostic ignored "-Wsign-compare" #pragma GCC diagnostic ignored "-Wsign-compare"
#pragma GCC diagnostic ignored "-Wmissing-prototypes" #pragma GCC diagnostic ignored "-Wmissing-prototypes"
@ -91,3 +94,5 @@ void cleanup_lexer (yyscan_t *scn)
// yy_delete_buffer (buffer, *scn); // yy_delete_buffer (buffer, *scn);
yylex_destroy(*scn); yylex_destroy(*scn);
} }
#endif /* __clang_analyzer__ */

View File

@ -99,6 +99,9 @@ enum matcher_rv command_match(struct graph *cmdgraph, vector vline,
struct listnode *head = listhead(*argv); struct listnode *head = listhead(*argv);
struct listnode *tail = listtail(*argv); struct listnode *tail = listtail(*argv);
assert(head);
assert(tail);
// delete dummy start node // delete dummy start node
cmd_token_del((struct cmd_token *)head->data); cmd_token_del((struct cmd_token *)head->data);
list_delete_node(*argv, head); list_delete_node(*argv, head);

View File

@ -786,6 +786,9 @@ void ospf6_abr_examin_summary(struct ospf6_lsa *lsa, struct ospf6_area *oa)
/* (3) if the prefix is equal to an active configured address range */ /* (3) if the prefix is equal to an active configured address range */
/* or if the NU bit is set in the prefix */ /* or if the NU bit is set in the prefix */
if (lsa->header->type == htons(OSPF6_LSTYPE_INTER_PREFIX)) { if (lsa->header->type == htons(OSPF6_LSTYPE_INTER_PREFIX)) {
/* must have been set in previous block */
assert(prefix_lsa);
range = ospf6_route_lookup(&prefix, oa->range_table); range = ospf6_route_lookup(&prefix, oa->range_table);
if (range) { if (range) {
if (is_debug) if (is_debug)

View File

@ -349,28 +349,6 @@ void ospf6_interface_if_add(struct interface *ifp)
ospf6_interface_state_update(oi->interface); ospf6_interface_state_update(oi->interface);
} }
void ospf6_interface_if_del(struct interface *ifp)
{
struct ospf6_interface *oi;
oi = (struct ospf6_interface *)ifp->info;
if (oi == NULL)
return;
/* interface stop */
if (oi->area)
thread_execute(master, interface_down, oi, 0);
listnode_delete(oi->area->if_list, oi);
oi->area = (struct ospf6_area *)NULL;
/* cut link */
oi->interface = NULL;
ifp->info = NULL;
ospf6_interface_delete(oi);
}
void ospf6_interface_state_update(struct interface *ifp) void ospf6_interface_state_update(struct interface *ifp)
{ {
struct ospf6_interface *oi; struct ospf6_interface *oi;

View File

@ -176,7 +176,6 @@ extern void ospf6_interface_enable(struct ospf6_interface *);
extern void ospf6_interface_disable(struct ospf6_interface *); extern void ospf6_interface_disable(struct ospf6_interface *);
extern void ospf6_interface_if_add(struct interface *); extern void ospf6_interface_if_add(struct interface *);
extern void ospf6_interface_if_del(struct interface *);
extern void ospf6_interface_state_update(struct interface *); extern void ospf6_interface_state_update(struct interface *);
extern void ospf6_interface_connected_route_update(struct interface *); extern void ospf6_interface_connected_route_update(struct interface *);

View File

@ -1844,6 +1844,7 @@ void ospf6_intra_prefix_lsa_remove(struct ospf6_lsa *lsa)
INTRA_PREFIX)) { INTRA_PREFIX)) {
prefix2str(&route->prefix, buf, prefix2str(&route->prefix, buf,
sizeof(buf)); sizeof(buf));
assert(route->nh_list);
zlog_debug("%s: route %s update paths %u nh %u" zlog_debug("%s: route %s update paths %u nh %u"
, __PRETTY_FUNCTION__, , __PRETTY_FUNCTION__,
buf, buf,

View File

@ -127,13 +127,6 @@ static int ospf6_zebra_if_del(int command, struct zclient *zclient,
zlog_debug("Zebra Interface delete: %s index %d mtu %d", zlog_debug("Zebra Interface delete: %s index %d mtu %d",
ifp->name, ifp->ifindex, ifp->mtu6); ifp->name, ifp->ifindex, ifp->mtu6);
#if 0
/* XXX: ospf6_interface_if_del is not the right way to handle this,
* because among other thinkable issues, it will also clear all
* settings as they are contained in the struct ospf6_interface. */
ospf6_interface_if_del (ifp);
#endif /*0*/
if_set_index(ifp, IFINDEX_INTERNAL); if_set_index(ifp, IFINDEX_INTERNAL);
return 0; return 0;
} }

View File

@ -1756,6 +1756,7 @@ static struct ospf_lsa *ospf_lsa_translated_nssa_new(struct ospf *ospf,
ei.route_map_set.metric = -1; ei.route_map_set.metric = -1;
ei.route_map_set.metric_type = -1; ei.route_map_set.metric_type = -1;
ei.tag = 0; ei.tag = 0;
ei.instance = 0;
if ((new = ospf_external_lsa_new(ospf, &ei, &type7->data->id)) if ((new = ospf_external_lsa_new(ospf, &ei, &type7->data->id))
== NULL) { == NULL) {

View File

@ -118,7 +118,8 @@ static int ospf_interface_add(int command, struct zclient *zclient,
assert(ifp->info); assert(ifp->info);
if (!OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp), type)) { if (IF_DEF_PARAMS(ifp)
&& !OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp), type)) {
SET_IF_PARAM(IF_DEF_PARAMS(ifp), type); SET_IF_PARAM(IF_DEF_PARAMS(ifp), type);
IF_DEF_PARAMS(ifp)->type = ospf_default_iftype(ifp); IF_DEF_PARAMS(ifp)->type = ospf_default_iftype(ifp);
} }