Skip to content

Commit

Permalink
Cppcheck v1.90 fixes (#52)
Browse files Browse the repository at this point in the history
cppcheck fixes:
* graph: shadowArgument fix
* stringlib: fix uninitialized error
  • Loading branch information
barrust authored Mar 14, 2021
1 parent 6d0258e commit 270a3cb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,8 @@ unsigned int* g_breadth_first_traverse(graph_t g, vertex_t v, unsigned int* size
edge_t e;
unsigned int i;
while (cur_pos != pos) { /* this signifies that we have hit the end */
vertex_t v = g_vertex_get(g, ret[cur_pos]);
g_iterate_edges(v, e, i) {
vertex_t ver = g_vertex_get(g, ret[cur_pos]);
g_iterate_edges(ver, e, i) {
id = g_edge_dest(e);
if (CHECK_BIT(bitarray, id) != 0)
continue; /* already visited */
Expand Down
2 changes: 1 addition & 1 deletion src/graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ void g_edge_free_alt(edge_t e, bool free_metadata);
i - An unsigned int that will be modified during the loop */
#define g_iterate_edges(v, e, i) for (i = 0; i < g_vertex_num_edges_out(v); i++) if ((e = g_vertex_edge(v, i)) != NULL)

/* Return an array with a listing of the vertices in bredth first fashion;
/* Return an array with a listing of the vertices in breadth first fashion;
this is useful for finding what order one should traverse the list starting
at vertex v in a bredth first fashion.
NOTE: Up to the caller to free the corresponding memory.
Expand Down
8 changes: 7 additions & 1 deletion src/stringlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,14 @@ char* s_append_alt(char* (*s1), const char* s2) {
char* res;
if ((*s1) == NULL)
res = (char*)calloc(strlen(s2) + 1, sizeof(char));
else
else {
res = (char*)realloc(*s1, strlen(*s1) + strlen(s2) + 1);
}

if (res == NULL) {
return NULL; // something went wrong getting memory
}

strcat(res, s2);
/* set s1 pointer to the res pointer */
*s1 = res;
Expand Down

0 comments on commit 270a3cb

Please sign in to comment.