lib: Pass in "strv_len" to strv_valid_entry
authorVolker Lendecke <vl@samba.org>
Wed, 2 Aug 2017 15:22:34 +0000 (17:22 +0200)
committerRalph Boehme <slow@samba.org>
Wed, 29 Nov 2017 15:59:15 +0000 (16:59 +0100)
Preparation for a later commit

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
lib/util/strv.c

index 99ce76f54fd99b50f7b767c32dc52ae5f04afe9b..864a3e5cf8ba88636daedf6ddef55c0d102d902e 100644 (file)
@@ -62,27 +62,23 @@ int strv_append(TALLOC_CTX *mem_ctx, char **strv, const char *src)
        return _strv_append(mem_ctx, strv, src, talloc_array_length(src));
 }
 
-static bool strv_valid_entry(const char *strv, const char *entry,
-                            size_t *strv_len, size_t *entry_len)
+static bool strv_valid_entry(const char *strv, size_t strv_len,
+                            const char *entry, size_t *entry_len)
 {
-       size_t len;
-
-       len = talloc_array_length(strv);
-       if (len == 0) {
+       if (strv_len == 0) {
                return false;
        }
-       if (strv[len-1] != '\0') {
+       if (strv[strv_len-1] != '\0') {
                return false;
        }
 
        if (entry < strv) {
                return false;
        }
-       if (entry >= (strv+len)) {
+       if (entry >= (strv+strv_len)) {
                return false;
        }
 
-       *strv_len = len;
        *entry_len = strlen(entry);
 
        return true;
@@ -90,17 +86,18 @@ static bool strv_valid_entry(const char *strv, const char *entry,
 
 char *strv_next(char *strv, const char *entry)
 {
-       size_t len, entry_len;
+       size_t len = talloc_array_length(strv);
+       size_t entry_len;
        char *result;
 
        if (entry == NULL) {
-               if (strv_valid_entry(strv, strv, &len, &entry_len)) {
+               if (strv_valid_entry(strv, len, strv, &entry_len)) {
                        return strv;
                }
                return NULL;
        }
 
-       if (!strv_valid_entry(strv, entry, &len, &entry_len)) {
+       if (!strv_valid_entry(strv, len, entry, &entry_len)) {
                return NULL;
        }
        result = &strv[entry - strv]; /* avoid const problems with this stmt */
@@ -139,13 +136,14 @@ char *strv_find(char *strv, const char *entry)
 
 void strv_delete(char **strv, char *entry)
 {
-       size_t len, entry_len;
+       size_t len = talloc_array_length(*strv);
+       size_t entry_len;
 
        if (entry == NULL) {
                return;
        }
 
-       if (!strv_valid_entry(*strv, entry, &len, &entry_len)) {
+       if (!strv_valid_entry(*strv, len, entry, &entry_len)) {
                return;
        }
        entry_len += 1;