* lib/sgetpwent.c: Avoid implicit conversion of pointers / chars to booleans.

* lib/sgetpwent.c: Add brackets and parenthesis.
	* lib/sgetpwent.c: Return NULL instead of 0.
This commit is contained in:
nekral-guest 2008-05-26 09:15:02 +00:00
parent 64d0313c5b
commit adc4729ffa
2 changed files with 24 additions and 12 deletions

View File

@ -1,3 +1,11 @@
2008-05-26 Nicolas François <nicolas.francois@centraliens.net>
* lib/sgetpwent.c: Avoid implicit conversion of pointers / chars to
booleans.
* lib/sgetpwent.c: Add brackets and parenthesis.
* lib/sgetpwent.c: Return NULL instead of 0.
2008-05-26 Nicolas François <nicolas.francois@centraliens.net>
* libmisc/getdate.y: abbrev is a bool.

View File

@ -77,15 +77,18 @@ struct passwd *sgetpwent (const char *buf)
* field. The fields are converted into NUL terminated strings.
*/
for (cp = pwdbuf, i = 0; i < NFIELDS && cp; i++) {
for (cp = pwdbuf, i = 0; (i < NFIELDS) && (NULL != cp); i++) {
fields[i] = cp;
while (*cp && *cp != ':')
++cp;
while (('\0' != *cp) && (':' != *cp)) {
cp++;
}
if (*cp)
*cp++ = '\0';
else
cp = 0;
if ('\0' != *cp) {
*cp = '\0';
cp++;
} else {
cp = NULL;
}
}
/*
@ -94,7 +97,7 @@ struct passwd *sgetpwent (const char *buf)
*/
if (i != NFIELDS || *fields[2] == '\0' || *fields[3] == '\0')
return 0;
return NULL;
/*
* Each of the fields is converted the appropriate data type
@ -106,12 +109,12 @@ struct passwd *sgetpwent (const char *buf)
pwent.pw_name = fields[0];
pwent.pw_passwd = fields[1];
if (fields[2][0] == '\0' ||
((pwent.pw_uid = strtol (fields[2], &ep, 10)) == 0 && *ep)) {
return 0;
((pwent.pw_uid = strtol (fields[2], &ep, 10)) == 0 && ('\0' != *ep))) {
return NULL;
}
if (fields[3][0] == '\0' ||
((pwent.pw_gid = strtol (fields[3], &ep, 10)) == 0 && *ep)) {
return 0;
((pwent.pw_gid = strtol (fields[3], &ep, 10)) == 0 && ('\0' != *ep))) {
return NULL;
}
pwent.pw_gecos = fields[4];
pwent.pw_dir = fields[5];
@ -119,3 +122,4 @@ struct passwd *sgetpwent (const char *buf)
return &pwent;
}