From: Daniel Stenberg Date: Mon, 17 Feb 2025 10:24:49 +0000 (+0100) Subject: lib: simplify more white space loops X-Git-Tag: curl-8_13_0~447 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=076444ec467576a1839148c48db1d92d9a1c59c7;p=thirdparty%2Fcurl.git lib: simplify more white space loops Since the ISBLANK() and ISSPACE() macros check for specific matches, there is no point in using while(*ptr && ISSPACE(*ptr)) etc, as the '*ptr' check is then superfluous. Closes #16363 --- diff --git a/lib/altsvc.c b/lib/altsvc.c index c7449ab106..c3aaf1dad6 100644 --- a/lib/altsvc.c +++ b/lib/altsvc.c @@ -232,7 +232,7 @@ static CURLcode altsvc_load(struct altsvcinfo *asi, const char *file) Curl_dyn_init(&buf, MAX_ALTSVC_LINE); while(Curl_get_line(&buf, fp)) { char *lineptr = Curl_dyn_ptr(&buf); - while(*lineptr && ISBLANK(*lineptr)) + while(ISBLANK(*lineptr)) lineptr++; if(*lineptr == '#') /* skip commented lines */ @@ -410,7 +410,7 @@ static CURLcode getalnum(const char **ptr, char *alpnbuf, size_t buflen) size_t len; const char *protop; const char *p = *ptr; - while(*p && ISBLANK(*p)) + while(ISBLANK(*p)) p++; protop = p; while(*p && !ISBLANK(*p) && (*p != ';') && (*p != '=')) @@ -593,12 +593,12 @@ CURLcode Curl_altsvc_parse(struct Curl_easy *data, /* skip option if name is too long */ option[0] = '\0'; } - while(*p && ISBLANK(*p)) + while(ISBLANK(*p)) p++; if(*p != '=') return CURLE_OK; p++; - while(*p && ISBLANK(*p)) + while(ISBLANK(*p)) p++; if(!*p) return CURLE_OK; diff --git a/lib/headers.c b/lib/headers.c index 2985e1e185..411515dfe1 100644 --- a/lib/headers.c +++ b/lib/headers.c @@ -209,7 +209,7 @@ static CURLcode namevalue(char *header, size_t hlen, unsigned int type, return CURLE_BAD_FUNCTION_ARGUMENT; /* skip all leading space letters */ - while(*header && ISBLANK(*header)) + while(ISBLANK(*header)) header++; *value = header; diff --git a/lib/hsts.c b/lib/hsts.c index 1c729d94cb..7fb3652598 100644 --- a/lib/hsts.c +++ b/lib/hsts.c @@ -154,7 +154,7 @@ CURLcode Curl_hsts_parse(struct hsts *h, const char *hostname, return CURLE_OK; do { - while(*p && ISBLANK(*p)) + while(ISBLANK(*p)) p++; if(strncasecompare("max-age", p, 7)) { bool quoted = FALSE; @@ -164,11 +164,11 @@ CURLcode Curl_hsts_parse(struct hsts *h, const char *hostname, return CURLE_BAD_FUNCTION_ARGUMENT; p += 7; - while(*p && ISBLANK(*p)) + while(ISBLANK(*p)) p++; if(*p++ != '=') return CURLE_BAD_FUNCTION_ARGUMENT; - while(*p && ISBLANK(*p)) + while(ISBLANK(*p)) p++; if(*p == '\"') { @@ -202,7 +202,7 @@ CURLcode Curl_hsts_parse(struct hsts *h, const char *hostname, p++; } - while(*p && ISBLANK(*p)) + while(ISBLANK(*p)) p++; if(*p == ';') p++; @@ -534,7 +534,7 @@ static CURLcode hsts_load(struct hsts *h, const char *file) Curl_dyn_init(&buf, MAX_HSTS_LINE); while(Curl_get_line(&buf, fp)) { char *lineptr = Curl_dyn_ptr(&buf); - while(*lineptr && ISBLANK(*lineptr)) + while(ISBLANK(*lineptr)) lineptr++; /* * Skip empty or commented lines, since we know the line will have a diff --git a/lib/http.c b/lib/http.c index 8010b4d92d..f82e030a1b 100644 --- a/lib/http.c +++ b/lib/http.c @@ -257,7 +257,7 @@ char *Curl_copy_header_value(const char *header) /* Find the first non-space letter */ start = header; - while(*start && ISSPACE(*start)) + while(ISSPACE(*start)) start++; end = strchr(start, '\r'); @@ -1016,7 +1016,7 @@ CURLcode Curl_http_input_auth(struct Curl_easy *data, bool proxy, auth++; if(*auth == ',') /* if we are on a comma, skip it */ auth++; - while(*auth && ISSPACE(*auth)) + while(ISSPACE(*auth)) auth++; } @@ -1404,7 +1404,7 @@ Curl_compareheader(const char *headerline, /* line to check */ start = &headerline[hlen]; /* pass all whitespace */ - while(*start && ISSPACE(*start)) + while(ISSPACE(*start)) start++; /* find the end of the header line */ @@ -1597,7 +1597,7 @@ CURLcode Curl_add_custom_headers(struct Curl_easy *data, if(ptr) { optr = ptr; ptr++; /* pass the semicolon */ - while(*ptr && ISSPACE(*ptr)) + while(ISSPACE(*ptr)) ptr++; if(*ptr) { @@ -1625,7 +1625,7 @@ CURLcode Curl_add_custom_headers(struct Curl_easy *data, /* we require a colon for this to be a true header */ ptr++; /* pass the colon */ - while(*ptr && ISSPACE(*ptr)) + while(ISSPACE(*ptr)) ptr++; if(*ptr || semicolonp) { @@ -3847,7 +3847,7 @@ static CURLcode http_rw_hd(struct Curl_easy *data, */ const char *p = hd; - while(*p && ISBLANK(*p)) + while(ISBLANK(*p)) p++; if(!strncmp(p, "HTTP/", 5)) { p += 5; @@ -3907,7 +3907,7 @@ static CURLcode http_rw_hd(struct Curl_easy *data, } else if(data->conn->handler->protocol & CURLPROTO_RTSP) { const char *p = hd; - while(*p && ISBLANK(*p)) + while(ISBLANK(*p)) p++; if(!strncmp(p, "RTSP/", 5)) { p += 5; @@ -4448,7 +4448,7 @@ CURLcode Curl_http_req_to_h2(struct dynhds *h2_headers, scheme = Curl_checkheaders(data, STRCONST(HTTP_PSEUDO_SCHEME)); if(scheme) { scheme += sizeof(HTTP_PSEUDO_SCHEME); - while(*scheme && ISBLANK(*scheme)) + while(ISBLANK(*scheme)) scheme++; infof(data, "set pseudo header %s to %s", HTTP_PSEUDO_SCHEME, scheme); } diff --git a/lib/http_aws_sigv4.c b/lib/http_aws_sigv4.c index 2fbb8de13a..e572cc4f5b 100644 --- a/lib/http_aws_sigv4.c +++ b/lib/http_aws_sigv4.c @@ -95,12 +95,12 @@ static void trim_headers(struct curl_slist *head) store = value; /* skip leading whitespace */ - while(*value && ISBLANK(*value)) + while(ISBLANK(*value)) value++; while(*value) { int space = 0; - while(*value && ISBLANK(*value)) { + while(ISBLANK(*value)) { value++; space++; } @@ -356,7 +356,7 @@ static char *parse_content_sha_hdr(struct Curl_easy *data, return NULL; ++value; - while(*value && ISBLANK(*value)) + while(ISBLANK(*value)) ++value; len = strlen(value); diff --git a/lib/http_digest.c b/lib/http_digest.c index a3ba17a51f..3c81640f20 100644 --- a/lib/http_digest.c +++ b/lib/http_digest.c @@ -62,7 +62,7 @@ CURLcode Curl_input_digest(struct Curl_easy *data, return CURLE_BAD_CONTENT_ENCODING; header += strlen("Digest"); - while(*header && ISBLANK(*header)) + while(ISBLANK(*header)) header++; return Curl_auth_decode_digest_http_message(header, digest); diff --git a/lib/http_negotiate.c b/lib/http_negotiate.c index f031d0abc8..b686b8ebc6 100644 --- a/lib/http_negotiate.c +++ b/lib/http_negotiate.c @@ -86,7 +86,7 @@ CURLcode Curl_input_negotiate(struct Curl_easy *data, struct connectdata *conn, /* Obtain the input token, if any */ header += strlen("Negotiate"); - while(*header && ISBLANK(*header)) + while(ISBLANK(*header)) header++; len = strlen(header); diff --git a/lib/http_ntlm.c b/lib/http_ntlm.c index 771f81da4c..2eee92742a 100644 --- a/lib/http_ntlm.c +++ b/lib/http_ntlm.c @@ -70,7 +70,7 @@ CURLcode Curl_input_ntlm(struct Curl_easy *data, if(checkprefix("NTLM", header)) { header += strlen("NTLM"); - while(*header && ISSPACE(*header)) + while(ISSPACE(*header)) header++; if(*header) { diff --git a/lib/http_proxy.c b/lib/http_proxy.c index 3a2e9f2b05..8a9effd49f 100644 --- a/lib/http_proxy.c +++ b/lib/http_proxy.c @@ -108,7 +108,7 @@ static CURLcode dynhds_add_custom(struct Curl_easy *data, name = headers->data; namelen = ptr - headers->data; ptr++; /* pass the colon */ - while(*ptr && ISSPACE(*ptr)) + while(ISSPACE(*ptr)) ptr++; if(*ptr) { value = ptr; @@ -131,7 +131,7 @@ static CURLcode dynhds_add_custom(struct Curl_easy *data, name = headers->data; namelen = ptr - headers->data; ptr++; /* pass the semicolon */ - while(*ptr && ISSPACE(*ptr)) + while(ISSPACE(*ptr)) ptr++; if(!*ptr) { /* quirk #2, send an empty header */ diff --git a/lib/noproxy.c b/lib/noproxy.c index 78cc06fa01..23dd46ba74 100644 --- a/lib/noproxy.c +++ b/lib/noproxy.c @@ -177,7 +177,7 @@ bool Curl_check_noproxy(const char *name, const char *no_proxy) bool match = FALSE; /* pass blanks */ - while(*p && ISBLANK(*p)) + while(ISBLANK(*p)) p++; token = p; diff --git a/lib/rtsp.c b/lib/rtsp.c index 652734ee2d..7ff7274cb9 100644 --- a/lib/rtsp.c +++ b/lib/rtsp.c @@ -944,7 +944,7 @@ CURLcode Curl_rtsp_parseheader(struct Curl_easy *data, const char *header) /* Find the first non-space letter */ start = header + 8; - while(*start && ISBLANK(*start)) + while(ISBLANK(*start)) start++; if(!*start) { @@ -1003,7 +1003,7 @@ CURLcode rtsp_parse_transport(struct Curl_easy *data, const char *transport) const char *start, *end; start = transport; while(start && *start) { - while(*start && ISBLANK(*start) ) + while(ISBLANK(*start) ) start++; end = strchr(start, ';'); if(checkprefix("interleaved=", start)) { diff --git a/lib/strtoofft.c b/lib/strtoofft.c index 5a7f058f96..f347e2b6fe 100644 --- a/lib/strtoofft.c +++ b/lib/strtoofft.c @@ -39,7 +39,7 @@ CURLofft curlx_strtoofft(const char *str, char **endp, int base, *num = 0; /* clear by default */ DEBUGASSERT((base == 10) || (base == 16)); - while(*str && ISBLANK(*str)) + while(ISBLANK(*str)) str++; rc = base == 10 ?