]> git.ipfire.org Git - thirdparty/tar.git/commitdiff
Simplify add_hierarchy_to_namelist allocation
authorPaul Eggert <eggert@cs.ucla.edu>
Fri, 1 Nov 2024 16:40:36 +0000 (09:40 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sat, 2 Nov 2024 06:47:23 +0000 (23:47 -0700)
* src/names.c (add_hierarchy_to_namelist):
Use xpalloc rather than a complicated homebrew heuristic.

src/names.c

index 516b0cef307735265d2994ad7021639348d039ba..f069a72c069a6508422b01ade0f7bdae52145564 100644 (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;