]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
dircolors,du,expr: prefer signed types
authorPaul Eggert <eggert@cs.ucla.edu>
Mon, 31 Jul 2023 23:35:32 +0000 (16:35 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Tue, 1 Aug 2023 00:51:28 +0000 (17:51 -0700)
* src/dircolors.c (dc_parse_stream):
* src/du.c (max_depth, main):
* src/expr.c (main):
Prefer signed types.

src/dircolors.c
src/du.c
src/expr.c

index 17b3c8b3fd51fac9cb161cf8410cc7d953031827..8a86efb76fc3ce5ea5daeec3da440e0fe55dc727 100644 (file)
@@ -264,7 +264,7 @@ append_entry (char prefix, char const *item, char const *arg)
 static bool
 dc_parse_stream (FILE *fp, char const *filename)
 {
-  size_t line_number = 0;
+  idx_t line_number = 0;
   char const *next_G_line = G_line;
   char *input_line = nullptr;
   size_t input_line_size = 0;
@@ -322,8 +322,8 @@ dc_parse_stream (FILE *fp, char const *filename)
 
       if (arg == nullptr)
         {
-          error (0, 0, _("%s:%lu: invalid line;  missing second token"),
-                 quotef (filename), (unsigned long int) line_number);
+          error (0, 0, _("%s:%td: invalid line;  missing second token"),
+                 quotef (filename), line_number);
           ok = false;
           free (keywd);
           continue;
@@ -377,9 +377,9 @@ dc_parse_stream (FILE *fp, char const *filename)
 
       if (unrecognized && (state == ST_TERMSURE || state == ST_TERMYES))
         {
-          error (0, 0, _("%s:%lu: unrecognized keyword %s"),
+          error (0, 0, _("%s:%td: unrecognized keyword %s"),
                  (filename ? quotef (filename) : _("<internal>")),
-                 (unsigned long int) line_number, keywd);
+                 line_number, keywd);
           ok = false;
         }
 
index 3d098bb326244d145f52b4e34246093feb4064fd..1e88b29ba971239fbbef87e7d924eafd1bc4f5b0 100644 (file)
--- a/src/du.c
+++ b/src/du.c
@@ -150,7 +150,7 @@ static bool opt_separate_dirs = false;
 /* Show the total for each directory (and file if --all) that is at
    most MAX_DEPTH levels down from the root of the hierarchy.  The root
    is at level 0, so 'du --max-depth=0' is equivalent to 'du -s'.  */
-static size_t max_depth = SIZE_MAX;
+static idx_t max_depth = IDX_MAX;
 
 /* Only output entries with at least this SIZE if positive,
    or at most if negative.  See --threshold option.  */
@@ -806,9 +806,9 @@ main (int argc, char **argv)
 
         case 'd':              /* --max-depth=N */
           {
-            uintmax_t tmp;
-            if (xstrtoumax (optarg, nullptr, 0, &tmp, "") == LONGINT_OK
-                && tmp <= SIZE_MAX)
+            intmax_t tmp;
+            if (xstrtoimax (optarg, nullptr, 0, &tmp, "") == LONGINT_OK
+                && tmp <= IDX_MAX)
               {
                 max_depth_specified = true;
                 max_depth = tmp;
@@ -940,8 +940,8 @@ main (int argc, char **argv)
 
   if (opt_summarize_only && max_depth_specified && max_depth != 0)
     {
-      unsigned long int d = max_depth;
-      error (0, 0, _("warning: summarizing conflicts with --max-depth=%lu"), d);
+      error (0, 0, _("warning: summarizing conflicts with --max-depth=%td"),
+             max_depth);
       usage (EXIT_FAILURE);
     }
 
@@ -1107,8 +1107,8 @@ main (int argc, char **argv)
               /* Using the standard 'filename:line-number:' prefix here is
                  not totally appropriate, since NUL is the separator, not NL,
                  but it might be better than nothing.  */
-              unsigned long int file_number = argv_iter_n_args (ai);
-              error (0, 0, "%s:%lu: %s", quotef (files_from),
+              idx_t file_number = argv_iter_n_args (ai);
+              error (0, 0, "%s:%td: %s", quotef (files_from),
                      file_number, _("invalid zero-length file name"));
             }
           skip_file = true;
index 8a76cbf7ce30502e2146ea6299880ca1b3c5a811..eeb4e13cca3f64a15d542d69bf1fbfc01333a300 100644 (file)
@@ -333,14 +333,13 @@ main (int argc, char **argv)
 
   /* The above handles --help and --version.
      Since there is no other invocation of getopt, handle '--' here.  */
-  unsigned int u_argc = argc;
-  if (1 < u_argc && STREQ (argv[1], "--"))
+  if (1 < argc && STREQ (argv[1], "--"))
     {
-      --u_argc;
+      --argc;
       ++argv;
     }
 
-  if (u_argc <= 1)
+  if (argc <= 1)
     {
       error (0, 0, _("missing operand"));
       usage (EXPR_INVALID);