Mercurial > hg > octave-nkf > gnulib-hg
comparison lib/getugroups.c @ 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 | bbbbbf4cd1c5 |
children | 85800f596ad2 |
comparison
equal
deleted
inserted
replaced
9702:11e548fe7d73 | 9703:e29f811d31c0 |
---|---|
19 | 19 |
20 #include <config.h> | 20 #include <config.h> |
21 | 21 |
22 #include "getugroups.h" | 22 #include "getugroups.h" |
23 | 23 |
24 #include <limits.h> | |
24 #include <stdio.h> /* grp.h on alpha OSF1 V2.0 uses "FILE *". */ | 25 #include <stdio.h> /* grp.h on alpha OSF1 V2.0 uses "FILE *". */ |
25 #include <grp.h> | 26 #include <grp.h> |
26 | 27 |
27 #include <unistd.h> | 28 #include <unistd.h> |
28 | 29 |
90 { | 91 { |
91 if (count >= maxcount) | 92 if (count >= maxcount) |
92 goto done; | 93 goto done; |
93 grouplist[count] = grp->gr_gid; | 94 grouplist[count] = grp->gr_gid; |
94 } | 95 } |
95 count++; | 96 if (count == INT_MAX) |
96 if (count < 0) | |
97 { | 97 { |
98 errno = EOVERFLOW; | 98 errno = EOVERFLOW; |
99 goto done; | 99 goto done; |
100 } | 100 } |
101 count++; | |
101 } | 102 } |
102 } | 103 } |
103 } | 104 } |
104 | 105 |
105 if (errno != 0) | 106 if (errno != 0) |