From: Christian Couder Date: Mon, 23 Mar 2026 08:05:08 GMT Subject: [PATCH 05/16] promisor-remote: refactor has_control_char() Message-ID: <20260323080520.887550-6-christian.couder@gmail.com> In-Reply-To: <20260323080520.887550-1-christian.couder@gmail.com> In a following commit we are going to check if some strings contain control character, so let's refactor the logic to do that in a new has_control_char() helper function. Signed-off-by: Christian Couder --- promisor-remote.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/promisor-remote.c b/promisor-remote.c index f5c4d41155..eda38223b9 100644 --- a/promisor-remote.c +++ b/promisor-remote.c @@ -632,6 +632,14 @@ static int all_fields_match(struct promisor_info *advertised, return 1; } +static bool has_control_char(const char *s) +{ + for (const char *c = s; *c; c++) + if (iscntrl(*c)) + return true; + return false; +} + static int should_accept_remote(enum accept_promisor accept, struct promisor_info *advertised, struct string_list *config_info) @@ -762,18 +770,14 @@ static bool valid_filter(const char *filter, const char *remote_name) return !res; } -/* Check that a token doesn't contain any control character */ static bool valid_token(const char *token, const char *remote_name) { - const char *c = token; - - for (; *c; c++) - if (iscntrl(*c)) { - warning(_("invalid token '%s' for remote '%s' " - "will not be stored"), - token, remote_name); - return false; - } + if (has_control_char(token)) { + warning(_("invalid token '%s' for remote '%s' " + "will not be stored"), + token, remote_name); + return false; + } return true; } -- 2.53.0.625.g20f70b52bb