]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
groups,id: don’t assume gid_t fits in unsigned long
authorPaul Eggert <eggert@cs.ucla.edu>
Mon, 31 Jul 2023 23:36:38 +0000 (16:36 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Tue, 1 Aug 2023 00:51:28 +0000 (17:51 -0700)
* src/group-list.c (print_group): Convert to intmax_t or
uintmax_t, not to unsigned long.

src/group-list.c

index d94d79e757c20355ce8e18cf9671d6e0e1b5c36f..52301239177417308545a6fe4cf17b59e25ea88f 100644 (file)
@@ -109,8 +109,16 @@ print_group (gid_t gid, bool use_name)
       grp = getgrgid (gid);
       if (grp == nullptr)
         {
-          error (0, 0, _("cannot find name for group ID %lu"),
-                 (unsigned long int) gid);
+          if (TYPE_SIGNED (gid_t))
+            {
+              intmax_t g = gid;
+              error (0, 0, _("cannot find name for group ID %"PRIdMAX), g);
+            }
+          else
+            {
+              uintmax_t g = gid;
+              error (0, 0, _("cannot find name for group ID %"PRIuMAX), g);
+            }
           ok = false;
         }
     }