From: Paul Eggert Date: Fri, 1 Nov 2024 16:40:36 +0000 (-0700) Subject: Simplify add_hierarchy_to_namelist allocation X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2ce5791124c491a9e467cd408375d6289172d08f;p=thirdparty%2Ftar.git Simplify add_hierarchy_to_namelist allocation * src/names.c (add_hierarchy_to_namelist): Use xpalloc rather than a complicated homebrew heuristic. --- 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;