+2009-12-04 Eric Blake <ebb9@byu.net>
+
+ mgetgroups: avoid argument promotion issues with -1
+ * lib/mgetgroups.c (mgetgroups): A cast is required when checking
+ for invalid gid_t.
+ * tests/test-chown.h (getegid, test_chown): Likewise.
+ * tests/test-lchown.h (getegid, test_lchown): Likewise.
+
2009-12-03 Paolo Bonzini <bonzini@gnu.org>
exclude: Fix header file problems.
max_n_groups = (username
? getugroups (0, NULL, username, gid)
- : getgroups (0, NULL) + (gid != -1));
+ : getgroups (0, NULL) + (gid != (gid_t) -1));
/* If we failed to count groups with NULL for a buffer,
try again with a non-NULL one, just in case. */
ng = (username
? getugroups (max_n_groups, g, username, gid)
- : getgroups (max_n_groups, g + (gid != -1)));
+ : getgroups (max_n_groups, g + (gid != (gid_t) -1)));
if (ng < 0)
{
return -1;
}
- if (!username && gid != -1)
+ if (!username && gid != (gid_t) -1)
{
*g = gid;
ng++;
}
#if !HAVE_GETEGID
-# define getegid() (-1)
+# define getegid() ((gid_t) -1)
#endif
/* This file is designed to test chown(n,o,g) and
ASSERT (close (creat (BASE "dir/file", 0600)) == 0);
ASSERT (stat (BASE "dir/file", &st1) == 0);
- ASSERT (st1.st_uid != -1);
- ASSERT (st1.st_gid != -1);
+ ASSERT (st1.st_uid != (uid_t) -1);
+ ASSERT (st1.st_gid != (uid_t) -1);
ASSERT (st1.st_gid == getegid ());
/* Sanity check of error cases. */
/* Check that -1 does not alter ownership. */
ASSERT (func (BASE "dir/file", -1, st1.st_gid) == 0);
ASSERT (func (BASE "dir/file", st1.st_uid, -1) == 0);
+ ASSERT (func (BASE "dir/file", (uid_t) -1, (gid_t) -1) == 0);
ASSERT (stat (BASE "dir/file", &st2) == 0);
ASSERT (st1.st_uid == st2.st_uid);
ASSERT (st1.st_gid == st2.st_gid);
gids[0] = gids[1];
}
ASSERT (gids[0] != st1.st_gid);
- ASSERT (gids[0] != -1);
+ ASSERT (gids[0] != (gid_t) -1);
ASSERT (lstat (BASE "dir/link", &st2) == 0);
ASSERT (st1.st_uid == st2.st_uid);
ASSERT (st1.st_gid == st2.st_gid);
#endif /* !TEST_CHOWN_NAP */
#if !HAVE_GETEGID
-# define getegid() (-1)
+# define getegid() ((gid_t) -1)
#endif
#ifndef HAVE_LCHMOD
ASSERT (close (creat (BASE "dir/file", 0600)) == 0);
ASSERT (stat (BASE "dir/file", &st1) == 0);
- ASSERT (st1.st_uid != -1);
- ASSERT (st1.st_gid != -1);
+ ASSERT (st1.st_uid != (uid_t) -1);
+ ASSERT (st1.st_gid != (gid_t) -1);
ASSERT (st1.st_gid == getegid ());
/* Sanity check of error cases. */
/* Check that -1 does not alter ownership. */
ASSERT (func (BASE "dir/file", -1, st1.st_gid) == 0);
ASSERT (func (BASE "dir/file", st1.st_uid, -1) == 0);
+ ASSERT (func (BASE "dir/file", (uid_t) -1, (gid_t) -1) == 0);
ASSERT (stat (BASE "dir/file", &st2) == 0);
ASSERT (st1.st_uid == st2.st_uid);
ASSERT (st1.st_gid == st2.st_gid);
gids[0] = gids[1];
}
ASSERT (gids[0] != st1.st_gid);
- ASSERT (gids[0] != -1);
+ ASSERT (gids[0] != (gid_t) -1);
ASSERT (lstat (BASE "dir/link", &st2) == 0);
ASSERT (st1.st_uid == st2.st_uid);
ASSERT (st1.st_gid == st2.st_gid);