Mercurial > hg > octave-lyh > gnulib-hg
changeset 9703:e29f811d31c0
Don't rely on signed integer overflowing to negative value.
* lib/getugroups.c (getugroups): Include <limits.h>.
Instead, compare against INT_MAX, and increment only if the test passes.
author | Lasse Collin <lasse.collin@tukaani.org> |
---|---|
date | Wed, 23 Jan 2008 17:48:40 +0100 |
parents | 11e548fe7d73 |
children | c0a42911e984 |
files | ChangeLog lib/getugroups.c |
diffstat | 2 files changed, 9 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2008-02-13 Lasse Collin <lasse.collin@tukaani.org> + + Don't rely on signed integer overflowing to negative value. + * lib/getugroups.c (getugroups): Include <limits.h>. + Instead, compare against INT_MAX, and increment only if the test passes. + 2008-02-13 Jim Meyering <meyering@redhat.com> and Eric Blake <ebb9@byu.net>
--- a/lib/getugroups.c +++ b/lib/getugroups.c @@ -21,6 +21,7 @@ #include "getugroups.h" +#include <limits.h> #include <stdio.h> /* grp.h on alpha OSF1 V2.0 uses "FILE *". */ #include <grp.h> @@ -92,12 +93,12 @@ goto done; grouplist[count] = grp->gr_gid; } - count++; - if (count < 0) + if (count == INT_MAX) { errno = EOVERFLOW; goto done; } + count++; } } }