From 568e9516fc3853a7abe860f29ef056663e1bbe24 Mon Sep 17 00:00:00 2001 From: Tobias Stoeckmann Date: Fri, 27 Sep 2024 22:15:59 +0200 Subject: [PATCH] depmod: Use memdup 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 Reviewed-by: Emil Velikov Link: https://github.com/kmod-project/kmod/pull/158 Signed-off-by: Lucas De Marchi --- tools/depmod.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tools/depmod.c b/tools/depmod.c index e736cac4..61999730 100644 --- a/tools/depmod.c +++ b/tools/depmod.c @@ -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(); -- 2.47.3