There's no strict contract for situations when caller passes NULL as grouplist. In all invocations inside gnulib, it's assumed that if you pass max_count != 0 it means that grouplist isn't NULL.
So if this is the case, then there's no need for explicit NULL check for grouplist. This inconsistency creates questions which are detected by static analyzers. If it's not the case, then additional checks should be added, so this patch does exactly that: In case when user passes non-zero maxcount and NULL group list it counts amount of groups until maxcount is reached. Signed-off-by: Sergey Zhidkih <[email protected]> --- lib/getugroups.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/getugroups.c b/lib/getugroups.c index 6acb583fd9..8f5ac8be07 100644 --- a/lib/getugroups.c +++ b/lib/getugroups.c @@ -63,7 +63,7 @@ getugroups (int maxcount, gid_t *grouplist, char const *username, if (gid != (gid_t) -1) { - if (maxcount != 0) + if (maxcount != 0 && grouplist) grouplist[count] = gid; ++count; } @@ -93,7 +93,8 @@ getugroups (int maxcount, gid_t *grouplist, char const *username, { if (count >= maxcount) goto done; - grouplist[count] = grp->gr_gid; + if (grouplist) + grouplist[count] = grp->gr_gid; } if (count == INT_MAX) { -- 2.50.1
