Replacing `strtoul()` calls and glue code.
Closes #16671
#define curlx_str_octal(x,y,z) Curl_str_octal(x,y,z)
#define curlx_str_single(x,y) Curl_str_single(x,y)
#define curlx_str_passblanks(x) Curl_str_passblanks(x)
+#define curlx_str_numblanks(x,y) Curl_str_numblanks(x,y)
#endif /* HEADER_CURL_STRPARSE_H */
request including the body before we return. If we've been told to
ignore the content-length, we will return as soon as all headers
have been received */
- char *endptr;
- char *ptr = line + 15;
- unsigned long clen = 0;
- while(*ptr && ISSPACE(*ptr))
- ptr++;
- endptr = ptr;
- CURL_SETERRNO(0);
- clen = strtoul(ptr, &endptr, 10);
- if((ptr == endptr) || !ISSPACE(*endptr) || (ERANGE == errno)) {
+ curl_off_t clen;
+ const char *p = line + strlen("Content-Length:");
+ if(curlx_str_numblanks(&p, &clen)) {
/* this assumes that a zero Content-Length is valid */
- logmsg("Found invalid Content-Length: (%s) in the request", ptr);
+ logmsg("Found invalid '%s' in the request", line);
req->open = FALSE; /* closes connection */
return 1; /* done */
}
- req->cl = clen - req->skip;
+ req->cl = (size_t)clen - req->skip;
- logmsg("Found Content-Length: %lu in the request", clen);
+ logmsg("Found Content-Length: %zu in the request", (size_t)clen);
if(req->skip)
logmsg("... but will abort after %zu bytes", req->cl);
break;
request including the body before we return. If we've been told to
ignore the content-length, we will return as soon as all headers
have been received */
- char *endptr;
- char *ptr = line + 15;
- unsigned long clen = 0;
- while(*ptr && ISSPACE(*ptr))
- ptr++;
- endptr = ptr;
- CURL_SETERRNO(0);
- clen = strtoul(ptr, &endptr, 10);
- if((ptr == endptr) || !ISSPACE(*endptr) || (ERANGE == errno)) {
+ curl_off_t clen;
+ const char *p = line + strlen("Content-Length:");
+ if(curlx_str_numblanks(&p, &clen)) {
/* this assumes that a zero Content-Length is valid */
- logmsg("Found invalid Content-Length: (%s) in the request", ptr);
+ logmsg("Found invalid '%s' in the request", line);
req->open = FALSE; /* closes connection */
return 1; /* done */
}
if(req->skipall)
req->cl = 0;
else
- req->cl = clen - req->skip;
+ req->cl = (size_t)clen - req->skip;
- logmsg("Found Content-Length: %lu in the request", clen);
+ logmsg("Found Content-Length: %zu in the request", (size_t)clen);
if(req->skip)
logmsg("... but will abort after %zu bytes", req->cl);
}