Simplify add_hierarchy_to_namelist allocation

* src/names.c (add_hierarchy_to_namelist):
Use xpalloc rather than a complicated homebrew heuristic.
This commit is contained in:
Paul Eggert
2024-11-01 09:40:36 -07:00
parent d127dac10e
commit 2ce5791124

View File

@@ -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;