]> granicus.if.org Git - shadow/commitdiff
* lib/sgetspent.c: Add brackets and parenthesis.
authornekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Mon, 26 May 2008 09:39:29 +0000 (09:39 +0000)
committernekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Mon, 26 May 2008 09:39:29 +0000 (09:39 +0000)
* lib/sgetspent.c: Avoid assignments in comparisons.
* lib/sgetspent.c: Avoid implicit conversion of pointers / chars to booleans.
* lib/sgetspent.c: Avoid multi-statements lines.

ChangeLog
lib/sgetspent.c

index a46972eb637924ee4bd3c85df8156686111152ab..a9136cd0005f303189cc5c356a71c8561250ad72 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2008-05-26  Nicolas François  <nicolas.francois@centraliens.net>
+
+       * lib/sgetspent.c: Add brackets and parenthesis.
+       * lib/sgetspent.c: Avoid assignments in comparisons.
+       * lib/sgetspent.c: Avoid implicit conversion of pointers / chars
+       to booleans.
+       * lib/sgetspent.c: Avoid multi-statements lines.
+
 2008-05-26  Nicolas François  <nicolas.francois@centraliens.net>
 
        * lib/sgetpwent.c: Avoid implicit conversion of pointers / chars to
index 6b396b692805ee5f1b3f599b911353a9fb127e33..be55e77db58749d564a14d9633e3d91fd366c2bf 100644 (file)
@@ -56,32 +56,41 @@ struct spwd *sgetspent (const char *string)
         * have to do that to our private copy.
         */
 
-       if (strlen (string) >= sizeof spwbuf)
+       if (strlen (string) >= sizeof spwbuf) {
                return 0;       /* fail if too long */
+       }
        strcpy (spwbuf, string);
 
-       if ((cp = strrchr (spwbuf, '\n')))
+       cp = strrchr (spwbuf, '\n');
+       if (NULL != cp) {
                *cp = '\0';
+       }
 
        /*
         * Tokenize the string into colon separated fields.  Allow up to
         * FIELDS different fields.
         */
 
-       for (cp = spwbuf, i = 0; *cp && i < FIELDS; i++) {
+       for (cp = spwbuf, i = 0; ('\0' != *cp) && (i < FIELDS); i++) {
                fields[i] = cp;
-               while (*cp && *cp != ':')
+               while (('\0' != *cp) && (':' != *cp)) {
                        cp++;
+               }
 
-               if (*cp)
-                       *cp++ = '\0';
+               if ('\0' != *cp) {
+                       *cp = '\0';
+                       cp++;
+               }
        }
 
-       if (i == (FIELDS - 1))
+       if (i == (FIELDS - 1)) {
                fields[i++] = cp;
+       }
 
-       if ((cp && *cp) || (i != FIELDS && i != OFIELDS))
+       if ( ((NULL != cp) && ('\0' != *cp)) ||
+            ((i != FIELDS) && (i != OFIELDS)) ) {
                return 0;
+       }
 
        /*
         * Start populating the structure.  The fields are all in
@@ -97,28 +106,37 @@ struct spwd *sgetspent (const char *string)
         * incorrectly formatted number.
         */
 
-       if ((spwd.sp_lstchg = strtol (fields[2], &cpp, 10)) == 0 && *cpp) {
+       spwd.sp_lstchg = strtol (fields[2], &cpp, 10);
+       /* FIXME: (0 == spwd.sp_lstchg) does not look correct */
+       if ((0 == spwd.sp_lstchg) && ('\0' != *cpp)) {
                return 0;
-       } else if (fields[2][0] == '\0')
+       } else if (fields[2][0] == '\0') {
                spwd.sp_lstchg = -1;
+       }
 
        /*
         * Get the minimum period between password changes.
         */
 
-       if ((spwd.sp_min = strtol (fields[3], &cpp, 10)) == 0 && *cpp) {
+       spwd.sp_min = strtol (fields[3], &cpp, 10);
+       /* FIXME: (0 == spwd.sp_min) does not look correct */
+       if ((0 == spwd.sp_min) && ('\0' != *cpp)) {
                return 0;
-       } else if (fields[3][0] == '\0')
+       } else if (fields[3][0] == '\0') {
                spwd.sp_min = -1;
+       }
 
        /*
         * Get the maximum number of days a password is valid.
         */
 
-       if ((spwd.sp_max = strtol (fields[4], &cpp, 10)) == 0 && *cpp) {
+       spwd.sp_max = strtol (fields[4], &cpp, 10);
+       /* FIXME: (0 == spwd.sp_max) does not look correct */
+       if ((0 == spwd.sp_max) && ('\0' != *cpp)) {
                return 0;
-       } else if (fields[4][0] == '\0')
+       } else if (fields[4][0] == '\0') {
                spwd.sp_max = -1;
+       }
 
        /*
         * If there are only OFIELDS fields (this is a SVR3.2 /etc/shadow
@@ -126,8 +144,10 @@ struct spwd *sgetspent (const char *string)
         */
 
        if (i == OFIELDS) {
-               spwd.sp_warn = spwd.sp_inact = spwd.sp_expire =
-                   spwd.sp_flag = -1;
+               spwd.sp_warn   = -1;
+               spwd.sp_inact  = -1;
+               spwd.sp_expire = -1;
+               spwd.sp_flag   = -1;
 
                return &spwd;
        }
@@ -136,40 +156,53 @@ struct spwd *sgetspent (const char *string)
         * Get the number of days of password expiry warning.
         */
 
-       if ((spwd.sp_warn = strtol (fields[5], &cpp, 10)) == 0 && *cpp) {
+       spwd.sp_warn = strtol (fields[5], &cpp, 10);
+       /* FIXME: (0 == spwd.sp_warn) does not look correct */
+       if ((0 == spwd.sp_warn) && ('\0' != *cpp)) {
                return 0;
-       } else if (fields[5][0] == '\0')
+       } else if (fields[5][0] == '\0') {
                spwd.sp_warn = -1;
+       }
 
        /*
         * Get the number of days of inactivity before an account is
         * disabled.
         */
 
-       if ((spwd.sp_inact = strtol (fields[6], &cpp, 10)) == 0 && *cpp) {
+       spwd.sp_inact = strtol (fields[6], &cpp, 10);
+       /* FIXME: (0 == spwd.sp_inact) does not look correct */
+       if ((0 == spwd.sp_inact) && ('\0' != *cpp)) {
                return 0;
-       } else if (fields[6][0] == '\0')
+       } else if (fields[6][0] == '\0') {
                spwd.sp_inact = -1;
+       }
 
        /*
         * Get the number of days after the epoch before the account is
         * set to expire.
         */
 
-       if ((spwd.sp_expire = strtol (fields[7], &cpp, 10)) == 0 && *cpp) {
+       spwd.sp_expire = strtol (fields[7], &cpp, 10);
+       /* FIXME: (0 == spwd.sp_expire) does not look correct */
+       if ((0 == spwd.sp_expire) && ('\0' != *cpp)) {
                return 0;
-       } else if (fields[7][0] == '\0')
+       } else if (fields[7][0] == '\0') {
                spwd.sp_expire = -1;
+       }
 
        /*
         * This field is reserved for future use.  But it isn't supposed
         * to have anything other than a valid integer in it.
         */
 
-       if ((spwd.sp_flag = strtol (fields[8], &cpp, 10)) == 0 && *cpp) {
+       spwd.sp_flag = strtol (fields[8], &cpp, 10);
+       /* FIXME: (0 == spwd.sp_flag) does not look correct */
+       if ((0 == spwd.sp_flag) && ('\0' != *cpp)) {
                return 0;
-       } else if (fields[8][0] == '\0')
+       } else if (fields[8][0] == '\0') {
                spwd.sp_flag = -1;
+       }
 
        return (&spwd);
 }
+