Skip to content

Commit

Permalink
depmod: Use memdup
Browse files Browse the repository at this point in the history
No need to clear newly allocated memory if source is copied into
destination directly.

Simplify code by using memdup from shared.

Signed-off-by: Tobias Stoeckmann <[email protected]>
Reviewed-by: Emil Velikov <[email protected]>
Link: #158
Signed-off-by: Lucas De Marchi <[email protected]>
  • Loading branch information
stoeckmann authored and lucasdemarchi committed Oct 1, 2024
1 parent 806c304 commit 568e951
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions tools/depmod.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,9 @@ static int index_insert(struct index_node *node, const char *key, const char *va
struct index_node *n;

/* New child is copy of node with prefix[j+1..N] */
n = calloc(1, sizeof(struct index_node));
n = memdup(node, sizeof(struct index_node));
if (n == NULL)
fatal_oom();
memcpy(n, node, sizeof(struct index_node));
n->prefix = strdup(&prefix[j + 1]);
if (n->prefix == NULL)
fatal_oom();
Expand Down

0 comments on commit 568e951

Please sign in to comment.