From: Lasse Collin Date: Wed, 23 Jan 2008 16:48:40 +0000 (+0100) Subject: Don't rely on signed integer overflowing to negative value. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a76230b70f5f81c63fbb43debf8d690885537de4;p=pspp Don't rely on signed integer overflowing to negative value. * lib/getugroups.c (getugroups): Include . Instead, compare against INT_MAX, and increment only if the test passes. --- diff --git a/ChangeLog b/ChangeLog index 155d5f7be8..a7ef8fb4be 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2008-02-13 Lasse Collin + + Don't rely on signed integer overflowing to negative value. + * lib/getugroups.c (getugroups): Include . + Instead, compare against INT_MAX, and increment only if the test passes. + 2008-02-13 Jim Meyering and Eric Blake diff --git a/lib/getugroups.c b/lib/getugroups.c index 6c557cdf34..4b8752f6b6 100644 --- a/lib/getugroups.c +++ b/lib/getugroups.c @@ -21,6 +21,7 @@ #include "getugroups.h" +#include #include /* grp.h on alpha OSF1 V2.0 uses "FILE *". */ #include @@ -92,12 +93,12 @@ getugroups (int maxcount, GETGROUPS_T *grouplist, char const *username, goto done; grouplist[count] = grp->gr_gid; } - count++; - if (count < 0) + if (count == INT_MAX) { errno = EOVERFLOW; goto done; } + count++; } } }