From: Volker Lendecke Date: Wed, 2 Aug 2017 15:22:34 +0000 (+0200) Subject: lib: Pass in "strv_len" to strv_valid_entry X-Git-Tag: talloc-2.1.11~328 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=805ae8a4f1fe61cb44000c2967f61e3bffa08eca;p=thirdparty%2Fsamba.git lib: Pass in "strv_len" to strv_valid_entry Preparation for a later commit Signed-off-by: Volker Lendecke Reviewed-by: Ralph Boehme --- diff --git a/lib/util/strv.c b/lib/util/strv.c index 99ce76f54fd..864a3e5cf8b 100644 --- a/lib/util/strv.c +++ b/lib/util/strv.c @@ -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;