[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] test-userspec.c: avoid compiler warnings
From: |
Jim Meyering |
Subject: |
[PATCH] test-userspec.c: avoid compiler warnings |
Date: |
Tue, 26 Jan 2010 09:52:32 +0100 |
FYI, my new test added a lot of warnings.
This change addresses all of them.
>From 1c9217c42e20cb34140f66b58bca543fd14c4aea Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Tue, 26 Jan 2010 09:51:26 +0100
Subject: [PATCH] test-userspec.c: avoid compiler warnings
* tests/test-userspec.c (main): Avoid shadowing ("uid"),
and "initialization discards qualifiers..." warnings.
Put the first "uid" in its own scope, and make char* members "const".
---
ChangeLog | 7 +++++
tests/test-userspec.c | 67 ++++++++++++++++++++++++++----------------------
2 files changed, 43 insertions(+), 31 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 2ae8381..62dcf87 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2010-01-26 Jim Meyering <address@hidden>
+
+ test-userspec.c: avoid compiler warnings
+ * tests/test-userspec.c (main): Avoid shadowing ("uid"),
+ and "initialization discards qualifiers..." warnings.
+ Put the first "uid" in its own scope, and make char* members "const".
+
2010-01-25 Bruno Haible <address@hidden>
gnulib-tool: Make warning diagnostics consistent.
diff --git a/tests/test-userspec.c b/tests/test-userspec.c
index 3e101f3..17428f2 100644
--- a/tests/test-userspec.c
+++ b/tests/test-userspec.c
@@ -35,12 +35,12 @@
struct test
{
- char *in;
+ const char *in;
uid_t uid;
gid_t gid;
- char *user_name;
- char *group_name;
- char *result;
+ const char *user_name;
+ const char *group_name;
+ const char *result;
};
static struct test T[] =
@@ -101,36 +101,41 @@ main (void)
{
unsigned int i;
int fail = 0;
- uid_t uid;
/* Find a UID that has both a user name and login group name,
but skip UID 0. */
- for (uid = 1200; 0 < uid; uid--)
- {
- struct group *gr;
- struct passwd *pw = getpwuid (uid);
- unsigned int j;
- size_t len;
- if (!pw || !pw->pw_name || !(gr = getgrgid (pw->pw_gid)) || !gr->gr_name)
- continue;
- j = ARRAY_CARDINALITY (T) - 2;
- assert (T[j].in == NULL);
- assert (T[j+1].in == NULL);
- len = strlen (pw->pw_name);
-
- /* Store "username:" in T[j].in. */
- T[j].in = xmalloc (len + 1 + 1);
- memcpy (T[j].in, pw->pw_name, len);
- T[j].in[len] = ':';
- T[j].in[len+1] = '\0';
-
- T[j].uid = uid;
- T[j].gid = gr->gr_gid;
- T[j].user_name = xstrdup (pw->pw_name);
- T[j].group_name = xstrdup (gr->gr_name);
- T[j].result = NULL;
- break;
- }
+ {
+ uid_t uid;
+ for (uid = 1200; 0 < uid; uid--)
+ {
+ struct group *gr;
+ struct passwd *pw = getpwuid (uid);
+ unsigned int j;
+ size_t len;
+ if (!pw || !pw->pw_name || !(gr = getgrgid (pw->pw_gid)) ||
!gr->gr_name)
+ continue;
+ j = ARRAY_CARDINALITY (T) - 2;
+ assert (T[j].in == NULL);
+ assert (T[j+1].in == NULL);
+ len = strlen (pw->pw_name);
+
+ /* Store "username:" in T[j].in. */
+ {
+ char *t = xmalloc (len + 1 + 1);
+ memcpy (t, pw->pw_name, len);
+ t[len] = ':';
+ t[len+1] = '\0';
+ T[j].in = t;
+ }
+
+ T[j].uid = uid;
+ T[j].gid = gr->gr_gid;
+ T[j].user_name = xstrdup (pw->pw_name);
+ T[j].group_name = xstrdup (gr->gr_name);
+ T[j].result = NULL;
+ break;
+ }
+ }
for (i = 0; T[i].in; i++)
{
--
1.7.0.rc0.127.gab8271
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [PATCH] test-userspec.c: avoid compiler warnings,
Jim Meyering <=