]> granicus.if.org Git - procps-ng/commitdiff
pgrep: Simplify the match_*() functions.
authorQualys Security Advisory <qsa@qualys.com>
Thu, 1 Jan 1970 00:00:00 +0000 (00:00 +0000)
committerCraig Small <csmall@enc.com.au>
Fri, 18 May 2018 21:32:21 +0000 (07:32 +1000)
pgrep.c

diff --git a/pgrep.c b/pgrep.c
index dead923c851fb9889467a036125f81fbe95d4b86..e37678b2ea532d86f37c7bb6a3f39d2809aec0e3 100644 (file)
--- a/pgrep.c
+++ b/pgrep.c
@@ -360,13 +360,13 @@ static int conv_ns (const char *restrict name, struct el *restrict e)
 static int match_numlist (long value, const struct el *restrict list)
 {
        int found = 0;
-       if (list == NULL)
-               found = 0;
-       else {
+       if (list != NULL) {
                int i;
                for (i = list[0].num; i > 0; i--) {
-                       if (list[i].num == value)
+                       if (list[i].num == value) {
                                found = 1;
+                               break;
+                       }
                }
        }
        return found;
@@ -375,13 +375,13 @@ static int match_numlist (long value, const struct el *restrict list)
 static int match_strlist (const char *restrict value, const struct el *restrict list)
 {
        int found = 0;
-       if (list == NULL)
-               found = 0;
-       else {
+       if (list != NULL) {
                int i;
                for (i = list[0].num; i > 0; i--) {
-                       if (! strcmp (list[i].str, value))
+                       if (! strcmp (list[i].str, value)) {
                                found = 1;
+                               break;
+                       }
                }
        }
        return found;
@@ -391,14 +391,14 @@ static int match_ns (const proc_t *task, const proc_t *ns_task)
 {
        int found = 1;
        int i;
-
        for (i = 0; i < NUM_NS; i++) {
                if (ns_flags & (1 << i)) {
-                       if (task->ns[i] != ns_task->ns[i])
+                       if (task->ns[i] != ns_task->ns[i]) {
                                found = 0;
+                               break;
+                       }
                }
        }
-
        return found;
 }