From ecb29573e9d2caf59de17fcb4efff129b35ad792 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Tue, 22 Aug 2006 23:40:28 +0000 Subject: [PATCH] =?UTF-8?q?"Jordan=20Crouse"=20=20s?= =?UTF-8?q?ays:=20The=20following=20patch=20makes=20coreutils/test.c=20act?= =?UTF-8?q?=20fail=20gracefully=20if=20getgroups()=20returns=20a=20-1.=20?= =?UTF-8?q?=C2=A0This=20fixes=20a=20problem=20on=20the=20One=20Laptop=20Pe?= =?UTF-8?q?r=20Child=20ROM=20image=20whereby=20we=20were=20getting=20odd?= =?UTF-8?q?=20Memory=20exhausted=20messages=20for=20'['=20and=20'test'.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Found by Mitch Bradley (Tweaked by Rob: no need to initialize a static to NULL, or realloc something that's only allocated when it's NULL.) --- coreutils/test.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/coreutils/test.c b/coreutils/test.c index bbc802283..c1097c28c 100644 --- a/coreutils/test.c +++ b/coreutils/test.c @@ -151,7 +151,7 @@ typedef int arith_t; static char **t_wp; static struct t_op const *t_wp_op; -static gid_t *group_array = NULL; +static gid_t *group_array; static int ngroups; static enum token t_lex(char *s); @@ -547,8 +547,10 @@ static int test_eaccess(char *path, int mode) static void initialize_group_array(void) { ngroups = getgroups(0, NULL); - group_array = xrealloc(group_array, ngroups * sizeof(gid_t)); - getgroups(ngroups, group_array); + if (ngroups > 0) { + group_array = xmalloc(ngroups * sizeof(gid_t)); + getgroups(ngroups, group_array); + } } /* Return non-zero if GID is one that we have in our groups list. */