OSDN Git Service

* cygcheck.cc (pretty_id): Don't exit on id error. Fix size calculations.
authorcgf <cgf>
Fri, 15 Oct 2004 13:57:56 +0000 (13:57 +0000)
committercgf <cgf>
Fri, 15 Oct 2004 13:57:56 +0000 (13:57 +0000)
winsup/utils/ChangeLog
winsup/utils/cygcheck.cc

index 9b236f0..1462b31 100644 (file)
@@ -1,3 +1,9 @@
+2004-10-15  Bas van Gompel  <cygwin-patch.buzz@bavag.tmfweb.nl>
+           Christopher Faylor  <cgf@timesys.com>
+
+       * cygcheck.cc (pretty_id): Don't exit on id error.  Fix size
+       calculations.
+
 2004-10-14  Christopher Faylor  <cgf@timesys.com>
            Bas van Gompel  <cygwin-patch.buzz@bavag.tmfweb.nl>
 
index 327e3cc..64130ee 100644 (file)
@@ -802,7 +802,7 @@ pretty_id (const char *s, char *cygwin, size_t cyglen)
   else
     {
       fprintf (stderr, "garbled output from `id' command - no uid= found\n");
-      exit (1);
+      return;
     }
   char *gid = strtok (NULL, ")");
   if (gid)
@@ -810,14 +810,14 @@ pretty_id (const char *s, char *cygwin, size_t cyglen)
   else
     {
       fprintf (stderr, "garbled output from `id' command - no gid= found\n");
-      exit (1);
+      return;
     }
 
   char **ng = groups - 1;
   size_t len_uid = strlen (uid);
   size_t len_gid = strlen (gid);
-  *++ng = groups[0] = (char *) alloca (len_uid += sizeof ("UID: )"));
-  *++ng = groups[1] = (char *) alloca (len_uid += sizeof ("GID: )"));
+  *++ng = groups[0] = (char *) alloca (len_uid += sizeof ("UID: )") - 1);
+  *++ng = groups[1] = (char *) alloca (len_gid += sizeof ("GID: )") - 1);
   sprintf (groups[0], "UID: %s)", uid);
   sprintf (groups[1], "GID: %s)", gid);
   size_t sz = max (len_uid, len_gid);
@@ -832,13 +832,14 @@ pretty_id (const char *s, char *cygwin, size_t cyglen)
       if (sz < len)
        sz = len;
     }
+  ng--;
 
   printf ("\nOutput from %s (%s)\n", id, s);
-  int n = 80 / (int) sz;
-  sz = -(sz + 1);
-  int i = n - 2;
-  for (char **g = groups; g < ng; g++)
-    if ((g != ng - 1) && (++i < n))
+  int n = 80 / (int) ++sz;
+  int i = n ? n - 2 : 0;
+  sz = -sz;
+  for (char **g = groups; g <= ng; g++)
+    if ((g != ng) && (++i < n))
       printf ("%*s ", sz, *g);
     else
       {