]> granicus.if.org Git - shadow/commitdiff
* libmisc/list.c: Avoid assignments in comparisons, assignments
authornekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Sat, 24 May 2008 14:09:35 +0000 (14:09 +0000)
committernekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Sat, 24 May 2008 14:09:35 +0000 (14:09 +0000)
with post increments (x++), use of integers as booleans, and
explicitly mark blocks with brackets.

ChangeLog
libmisc/list.c

index 3474390e41e99d34f80fdbc75c422a80f89bc61f..db2919817b95457df782c8b403f33b32bec4e812 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -7,6 +7,9 @@
        * src/passwd.c: Declare the check_selinux_access prototype and
        avoid name clashes (change_user -> changed_user; change_uid ->
        changed_uid; access -> requested_access)
+       * libmisc/list.c: Avoid assignments in comparisons, assignments
+       with post increments (x++), use of integers as booleans, and
+       explicitly mark blocks with brackets.
 
 2008-05-23  Nicolas François  <nicolas.francois@centraliens.net>
 
index 38beee6c1715ae1bca0739eeac679e7217b1ea02..c39f79318d6cda393c86c86e15883fd3a2d61aea 100644 (file)
@@ -55,9 +55,11 @@ char **add_list (char **list, const char *member)
         * pointer if it is present.
         */
 
-       for (i = 0; list[i] != (char *) 0; i++)
-               if (strcmp (list[i], member) == 0)
+       for (i = 0; list[i] != (char *) 0; i++) {
+               if (strcmp (list[i], member) == 0) {
                        return list;
+               }
+       }
 
        /*
         * Allocate a new list pointer large enough to hold all the
@@ -72,11 +74,12 @@ char **add_list (char **list, const char *member)
         * is returned to the invoker.
         */
 
-       for (i = 0; list[i] != (char *) 0; i++)
+       for (i = 0; list[i] != (char *) 0; i++) {
                tmp[i] = list[i];
+       }
 
-       tmp[i++] = xstrdup (member);
-       tmp[i] = (char *) 0;
+       tmp[i] = xstrdup (member);
+       tmp[i+1] = (char *) 0;
 
        return tmp;
 }
@@ -99,12 +102,15 @@ char **del_list (char **list, const char *member)
         * pointer if it is not present.
         */
 
-       for (i = j = 0; list[i] != (char *) 0; i++)
-               if (strcmp (list[i], member))
+       for (i = j = 0; list[i] != (char *) 0; i++) {
+               if (strcmp (list[i], member) != 0) {
                        j++;
+               }
+       }
 
-       if (j == i)
+       if (j == i) {
                return list;
+       }
 
        /*
         * Allocate a new list pointer large enough to hold all the
@@ -119,9 +125,12 @@ char **del_list (char **list, const char *member)
         * is returned to the invoker.
         */
 
-       for (i = j = 0; list[i] != (char *) 0; i++)
-               if (strcmp (list[i], member))
-                       tmp[j++] = list[i];
+       for (i = j = 0; list[i] != (char *) 0; i++) {
+               if (strcmp (list[i], member) != 0) {
+                       tmp[j] = list[i];
+                       j++;
+               }
+       }
 
        tmp[j] = (char *) 0;
 
@@ -138,8 +147,11 @@ char **dup_list (char *const *list)
        tmp = (char **) xmalloc ((i + 1) * sizeof (char *));
 
        i = 0;
-       while (*list)
-               tmp[i++] = xstrdup (*list++);
+       while (*list) {
+               tmp[i] = xstrdup (*list);
+               i++;
+               list++;
+       }
 
        tmp[i] = (char *) 0;
        return tmp;
@@ -148,8 +160,9 @@ char **dup_list (char *const *list)
 int is_on_list (char *const *list, const char *member)
 {
        while (*list) {
-               if (strcmp (*list, member) == 0)
+               if (strcmp (*list, member) == 0) {
                        return 1;
+               }
                list++;
        }
        return 0;
@@ -176,11 +189,14 @@ char **comma_to_list (const char *comma)
         * Count the number of commas in the list
         */
 
-       for (cp = members, i = 0;; i++)
-               if ((cp2 = strchr (cp, ',')))
+       for (cp = members, i = 0;; i++) {
+               cp2 = strchr (cp, ',');
+               if (NULL != cp2) {
                        cp = cp2 + 1;
-               else
+               } else {
                        break;
+               }
+       }
 
        /*
         * Add 2 - one for the ending NULL, the other for the last item
@@ -198,7 +214,7 @@ char **comma_to_list (const char *comma)
         * Empty list is special - 0 members, not 1 empty member.  --marekm
         */
 
-       if (!*members) {
+       if ('\0' == *members) {
                *array = (char *) 0;
                return array;
        }
@@ -210,8 +226,10 @@ char **comma_to_list (const char *comma)
 
        for (cp = members, i = 0;; i++) {
                array[i] = cp;
-               if ((cp2 = strchr (cp, ','))) {
-                       *cp2++ = '\0';
+               cp2 = strchr (cp, ',');
+               if (NULL != cp2) {
+                       *cp2 = '\0';
+                       cp2++;
                        cp = cp2;
                } else {
                        array[i + 1] = (char *) 0;
@@ -225,3 +243,4 @@ char **comma_to_list (const char *comma)
 
        return array;
 }
+