]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
du: prefer xpalloc to xnrealloc
authorPaul Eggert <eggert@cs.ucla.edu>
Fri, 8 Nov 2024 06:56:44 +0000 (22:56 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Sat, 9 Nov 2024 07:41:18 +0000 (23:41 -0800)
* src/du.c (prev_level, process_file):
Prefer idx_t to size_t for sizes related to xpalloc,
and to nesting levels (since that’s what fts_level does anyway).
(process_file): Prefer xpalloc to xnrealloc.

src/du.c

index 81ec1bec8979c80d931a500a04674e7f259c8924..bcbe86b90676fbcd6c200fed996c7bfe346e1370 100644 (file)
--- a/src/du.c
+++ b/src/du.c
@@ -69,7 +69,7 @@ static struct di_set *di_mnt;
 
 /* Keep track of the preceding "level" (depth in hierarchy)
    from one call of process_file to the next.  */
-static size_t prev_level;
+static idx_t prev_level;
 
 /* Define a class for collecting directory information. */
 struct duinfo
@@ -476,8 +476,7 @@ process_file (FTS *fts, FTSENT *ent)
   bool ok = true;
   struct duinfo dui;
   struct duinfo dui_to_print;
-  size_t level;
-  static size_t n_alloc;
+  static idx_t n_alloc;
   /* First element of the structure contains:
      The sum of the sizes of all entries in the single directory
      at the corresponding level.  Although this does include the sizes
@@ -579,7 +578,7 @@ process_file (FTS *fts, FTSENT *ent)
                : time_type == time_atime ? get_stat_atime (sb)
                : get_stat_ctime (sb)));
 
-  level = ent->fts_level;
+  idx_t level = ent->fts_level;
   dui_to_print = dui;
 
   if (n_alloc == 0)
@@ -601,12 +600,10 @@ process_file (FTS *fts, FTSENT *ent)
              e.g., from 1 to 10.  */
 
           if (n_alloc <= level)
-            {
-              dulvl = xnrealloc (dulvl, level, 2 * sizeof *dulvl);
-              n_alloc = level * 2;
-            }
+            dulvl = xpalloc (dulvl, &n_alloc, level - n_alloc + 1, -1,
+                             sizeof *dulvl);
 
-          for (size_t i = prev_level + 1; i <= level; i++)
+          for (idx_t i = prev_level + 1; i <= level; i++)
             {
               duinfo_init (&dulvl[i].ent);
               duinfo_init (&dulvl[i].subdir);