From 2ce5791124c491a9e467cd408375d6289172d08f Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Fri, 1 Nov 2024 09:40:36 -0700 Subject: [PATCH] Simplify add_hierarchy_to_namelist allocation * src/names.c (add_hierarchy_to_namelist): Use xpalloc rather than a complicated homebrew heuristic. --- src/names.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/names.c b/src/names.c index 516b0cef..f069a72c 100644 --- a/src/names.c +++ b/src/names.c @@ -1603,10 +1603,8 @@ add_hierarchy_to_namelist (struct tar_stat_info *st, struct name *name) { struct name *child_head = NULL, *child_tail = NULL; idx_t name_length = name->length; - idx_t allocated_length = (name_length >= NAME_FIELD_SIZE - ? name_length + NAME_FIELD_SIZE - : NAME_FIELD_SIZE) + 2; - char *namebuf = xmalloc (allocated_length); + idx_t allocated_length = 0; + char *namebuf = xpalloc (NULL, &allocated_length, name_length + 2, -1, 1); const char *string; idx_t string_length; idx_t change_dir = name->change_dir; -- 2.47.3