Merge pull request #185 from opensourcerouting/coverity-lib-1

Coverity foo
This commit is contained in:
Donald Sharp 2017-02-08 13:44:53 -05:00 committed by GitHub
commit 10c7cd3920
7 changed files with 38 additions and 58 deletions

View File

@ -294,27 +294,6 @@ cmd_free_strvec (vector v)
vector_free (v);
}
char *
cmd_concat_strvec (vector v)
{
size_t strsize = 0;
for (unsigned int i = 0; i < vector_active (v); i++)
if (vector_slot (v, i))
strsize += strlen ((char *) vector_slot (v, i)) + 1;
if (strsize == 0)
return XSTRDUP (MTYPE_TMP, "");
char *concatenated = calloc (sizeof (char), strsize);
for (unsigned int i = 0; i < vector_active (v); i++)
{
strlcat (concatenated, (char *) vector_slot (v, i), strsize);
strlcat (concatenated, " ", strsize);
}
return concatenated;
}
/* Return prompt character of specified node. */
const char *
cmd_prompt (enum node_type node)
@ -720,6 +699,8 @@ cmd_complete_command (vector vline, struct vty *vty, int *status)
vector_free (comps);
comps = NULL;
}
else if (initial_comps)
vector_free (initial_comps);
// comps should always be null here
assert (!comps);
@ -805,6 +786,8 @@ cmd_execute_command_real (vector vline,
// if matcher error, return corresponding CMD_ERR
if (MATCHER_ERROR(status))
{
if (argv_list)
list_delete (argv_list);
switch (status)
{
case MATCHER_INCOMPLETE:

View File

@ -410,7 +410,6 @@ extern int argv_find (struct cmd_token **argv, int argc, const char *text, int *
extern vector cmd_make_strvec (const char *);
extern void cmd_free_strvec (vector);
extern char *cmd_concat_strvec (vector);
extern vector cmd_describe_command (vector, struct vty *, int *status);
extern char **cmd_complete_command (vector, struct vty *, int *status);
extern const char *cmd_prompt (enum node_type);

View File

@ -239,6 +239,9 @@ csv_encode (csv_t *csv,
rec = malloc(sizeof(csv_record_t));
if (!rec) {
log_error("record malloc failed\n");
if (!buf)
free(str);
va_end(list);
return (NULL);
}
csv_init_record(rec);
@ -255,6 +258,7 @@ csv_encode (csv_t *csv,
if (!fld) {
log_error("fld malloc failed\n");
csv_remove_record(csv, rec);
va_end(list);
return (NULL);
}
if (tempc < (count - 1)) {
@ -518,7 +522,7 @@ csv_concat_record (csv_t *csv,
curr = (char *)calloc(1, csv->buflen);
if (!curr) {
log_error("field str malloc failed\n");
return (NULL);
goto out_rec;
}
rec->record = curr;
@ -526,7 +530,7 @@ csv_concat_record (csv_t *csv,
ret = strstr(rec1->record, "\n");
if (!ret) {
log_error("rec1 str not properly formatted\n");
return (NULL);
goto out_curr;
}
snprintf(curr, (int)(ret - rec1->record + 1), "%s", rec1->record);
@ -535,7 +539,7 @@ csv_concat_record (csv_t *csv,
ret = strstr(rec2->record, "\n");
if (!ret) {
log_error("rec2 str not properly formatted\n");
return (NULL);
goto out_curr;
}
snprintf((curr+strlen(curr)), (int)(ret - rec2->record + 1), "%s",
@ -556,6 +560,12 @@ csv_concat_record (csv_t *csv,
csv_insert_record(csv, rec);
return rec;
out_curr:
free(curr);
out_rec:
free(rec);
return NULL;
}
void
@ -569,6 +579,8 @@ csv_decode (csv_t *csv, char *inbuf)
pos = strpbrk(buf, "\n");
while (pos != NULL) {
rec = calloc(1, sizeof(csv_record_t));
if (!rec)
return;
csv_init_record(rec);
TAILQ_INSERT_TAIL(&(csv->records), rec, next_record);
csv->num_recs++;

View File

@ -557,10 +557,11 @@ prefix_list_entry_delete (struct prefix_list *plist,
struct prefix_list_entry *pentry,
int update_list)
{
prefix_list_trie_del (plist, pentry);
if (plist == NULL || pentry == NULL)
return;
prefix_list_trie_del (plist, pentry);
if (pentry->prev)
pentry->prev->next = pentry->next;
else

View File

@ -722,20 +722,6 @@ apply_mask_ipv6 (struct prefix_ipv6 *p)
}
}
void
str2in6_addr (const char *str, struct in6_addr *addr)
{
int i;
unsigned int x;
/* %x must point to unsinged int */
for (i = 0; i < 16; i++)
{
sscanf (str + (i * 2), "%02x", &x);
addr->s6_addr[i] = x & 0xff;
}
}
void
apply_mask (struct prefix *p)
{

View File

@ -281,7 +281,6 @@ extern void apply_mask_ipv6 (struct prefix_ipv6 *);
extern int ip6_masklen (struct in6_addr);
extern void masklen2ip6 (const int, struct in6_addr *);
extern void str2in6_addr (const char *, struct in6_addr *);
extern const char *inet6_ntoa (struct in6_addr);
static inline int ipv6_martian (struct in6_addr *addr)

View File

@ -800,29 +800,29 @@ route_map_free_map (struct route_map *map)
struct route_map_list *list;
struct route_map_index *index;
if (map == NULL)
return;
while ((index = map->head) != NULL)
route_map_index_delete (index, 0);
list = &route_map_master;
if (map != NULL)
{
QOBJ_UNREG (map);
QOBJ_UNREG (map);
if (map->next)
map->next->prev = map->prev;
else
list->tail = map->prev;
if (map->next)
map->next->prev = map->prev;
else
list->tail = map->prev;
if (map->prev)
map->prev->next = map->next;
else
list->head = map->next;
if (map->prev)
map->prev->next = map->next;
else
list->head = map->next;
hash_release(route_map_master_hash, map);
XFREE (MTYPE_ROUTE_MAP_NAME, map->name);
XFREE (MTYPE_ROUTE_MAP, map);
}
hash_release(route_map_master_hash, map);
XFREE (MTYPE_ROUTE_MAP_NAME, map->name);
XFREE (MTYPE_ROUTE_MAP, map);
}
/* Route map delete from list. */
@ -1053,7 +1053,7 @@ vty_show_route_map (struct vty *vty, const char *name)
{
if (zlog_default)
vty_out (vty, "%s", zlog_proto_names[zlog_default->protocol]);
if (zlog_default->instance)
if (zlog_default && zlog_default->instance)
vty_out (vty, " %d", zlog_default->instance);
vty_out (vty, ": 'route-map %s' not found%s", name, VTY_NEWLINE);
return CMD_SUCCESS;