curl_setup: use SIZE_MAX instead of SIZE_T_MAX

As SIZE_MAX exists in C99

Assisted-by: Stefan Eissing
Assisted-by: Jay Satiro

Ref: #18406
Closes #18426
This commit is contained in:
Daniel Stenberg 2025-08-29 09:24:39 +02:00
parent 7ceb9c54aa
commit 93f333c18f
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
13 changed files with 24 additions and 24 deletions

View file

@ -541,7 +541,7 @@ static ssize_t on_session_send(nghttp2_session *h2,
if(!nwritten)
return NGHTTP2_ERR_WOULDBLOCK;
return (nwritten > SSIZE_T_MAX) ?
return (nwritten > SSIZE_MAX) ?
NGHTTP2_ERR_CALLBACK_FAILURE : (ssize_t)nwritten;
}
@ -817,7 +817,7 @@ static ssize_t tunnel_send_callback(nghttp2_session *session,
CURL_TRC_CF(data, cf, "[%d] tunnel_send_callback -> %zd",
ts->stream_id, nread);
return (nread > SSIZE_T_MAX) ?
return (nread > SSIZE_MAX) ?
NGHTTP2_ERR_CALLBACK_FAILURE : (ssize_t)nread;
}

View file

@ -399,7 +399,7 @@ CURLcode Curl_ntlm_core_mk_nt_hash(const char *password,
size_t len = strlen(password);
unsigned char *pw;
CURLcode result;
if(len > SIZE_T_MAX/2) /* avoid integer overflow */
if(len > SIZE_MAX/2) /* avoid integer overflow */
return CURLE_OUT_OF_MEMORY;
pw = len ? malloc(len * 2) : (unsigned char *)strdup("");
if(!pw)

View file

@ -618,21 +618,21 @@
# endif
#endif
#ifndef SIZE_T_MAX
#ifndef SIZE_MAX
/* some limits.h headers have this defined, some do not */
#if defined(SIZEOF_SIZE_T) && (SIZEOF_SIZE_T > 4)
#define SIZE_T_MAX 18446744073709551615U
#define SIZE_MAX 18446744073709551615U
#else
#define SIZE_T_MAX 4294967295U
#define SIZE_MAX 4294967295U
#endif
#endif
#ifndef SSIZE_T_MAX
#ifndef SSIZE_MAX
/* some limits.h headers have this defined, some do not */
#if defined(SIZEOF_SIZE_T) && (SIZEOF_SIZE_T > 4)
#define SSIZE_T_MAX 9223372036854775807
#define SSIZE_MAX 9223372036854775807
#else
#define SSIZE_T_MAX 2147483647
#define SSIZE_MAX 2147483647
#endif
#endif

View file

@ -62,7 +62,7 @@ int curlx_dyn_vprintf(struct dynbuf *dyn, const char *format, va_list ap_save);
char *curlx_dyn_take(struct dynbuf *s, size_t *plen);
/* Dynamic buffer max sizes */
#define MAX_DYNBUF_SIZE (SIZE_T_MAX/2)
#define MAX_DYNBUF_SIZE (SIZE_MAX/2)
#define DYN_DOH_RESPONSE 3000
#define DYN_DOH_CNAME 256

View file

@ -165,7 +165,7 @@ static int str_num_base(const char **linep, curl_off_t *nump, curl_off_t max,
(base == 16) ? 'f' : '7';
DEBUGASSERT(linep && *linep && nump);
DEBUGASSERT((base == 8) || (base == 10) || (base == 16));
DEBUGASSERT(max >= 0); /* mostly to catch SIZE_T_MAX, which is too large */
DEBUGASSERT(max >= 0); /* mostly to catch SIZE_MAX, which is too large */
*nump = 0;
p = *linep;
if(!valid_digit(*p, m))

View file

@ -98,7 +98,7 @@ unsigned long curlx_uztoul(size_t uznum)
# pragma warning(disable:810) /* conversion may lose significant bits */
#endif
#if ULONG_MAX < SIZE_T_MAX
#if ULONG_MAX < SIZE_MAX
DEBUGASSERT(uznum <= (size_t) CURL_MASK_ULONG);
#endif
return (unsigned long)(uznum & (size_t) CURL_MASK_ULONG);
@ -119,7 +119,7 @@ unsigned int curlx_uztoui(size_t uznum)
# pragma warning(disable:810) /* conversion may lose significant bits */
#endif
#if UINT_MAX < SIZE_T_MAX
#if UINT_MAX < SIZE_MAX
DEBUGASSERT(uznum <= (size_t) CURL_MASK_UINT);
#endif
return (unsigned int)(uznum & (size_t) CURL_MASK_UINT);
@ -243,7 +243,7 @@ int curlx_sztosi(ssize_t sznum)
#endif
DEBUGASSERT(sznum >= 0);
#if INT_MAX < SSIZE_T_MAX
#if INT_MAX < SSIZE_MAX
DEBUGASSERT((size_t) sznum <= (size_t) CURL_MASK_SINT);
#endif
return (int)(sznum & (ssize_t) CURL_MASK_SINT);

View file

@ -799,7 +799,7 @@ static ssize_t send_callback(nghttp2_session *h2,
ctx->nw_out_blocked = 1;
return NGHTTP2_ERR_WOULDBLOCK;
}
return (nwritten > SSIZE_T_MAX) ?
return (nwritten > SSIZE_MAX) ?
NGHTTP2_ERR_CALLBACK_FAILURE : (ssize_t)nwritten;
}

View file

@ -218,15 +218,15 @@ static size_t get_max_body_write_len(struct Curl_easy *data, curl_off_t limit)
return 0;
}
#if SIZEOF_CURL_OFF_T > SIZEOF_SIZE_T
else if(remain_diff > SSIZE_T_MAX) {
return SIZE_T_MAX;
else if(remain_diff > SSIZE_MAX) {
return SIZE_MAX;
}
#endif
else {
return (size_t)remain_diff;
}
}
return SIZE_T_MAX;
return SIZE_MAX;
}
struct cw_download_ctx {

View file

@ -1683,7 +1683,7 @@ static CURLcode setopt_cptr(struct Curl_easy *data, CURLoption option,
/*
* Check that requested length does not overflow the size_t type.
*/
else if(s->postfieldsize > SIZE_T_MAX)
else if(s->postfieldsize > SIZE_MAX)
return CURLE_OUT_OF_MEMORY;
#endif
else {

View file

@ -71,7 +71,7 @@ wchar_t *Curl_wcsdup(const wchar_t *src)
{
size_t length = wcslen(src);
if(length > (SIZE_T_MAX / sizeof(wchar_t)) - 1)
if(length > (SIZE_MAX / sizeof(wchar_t)) - 1)
return (wchar_t *)NULL; /* integer overflow */
return (wchar_t *)Curl_memdup(src, (length + 1) * sizeof(wchar_t));

View file

@ -74,8 +74,8 @@ CURLcode Curl_auth_create_plain_message(const char *authzid,
plen = strlen(passwd);
/* Compute binary message length. Check for overflows. */
if((zlen > SIZE_T_MAX/4) || (clen > SIZE_T_MAX/4) ||
(plen > (SIZE_T_MAX/2 - 2)))
if((zlen > SIZE_MAX/4) || (clen > SIZE_MAX/4) ||
(plen > (SIZE_MAX/2 - 2)))
return CURLE_OUT_OF_MEMORY;
plainlen = zlen + clen + plen + 2;

View file

@ -426,7 +426,7 @@ CURLcode Curl_gtls_shared_creds_create(struct Curl_easy *data,
CURLcode Curl_gtls_shared_creds_up_ref(struct gtls_shared_creds *creds)
{
DEBUGASSERT(creds);
if(creds->refcount < SIZE_T_MAX) {
if(creds->refcount < SIZE_MAX) {
++creds->refcount;
return CURLE_OK;
}

View file

@ -130,7 +130,7 @@ static CURLcode glob_set(struct URLGlob *glob, const char **patternp,
if(pat->c.set.elem) {
char **arr;
if(pat->c.set.size >= (curl_off_t)(SIZE_T_MAX/(sizeof(char *))))
if(pat->c.set.size >= (curl_off_t)(SIZE_MAX/(sizeof(char *))))
return globerror(glob, "range overflow", 0, CURLE_URL_MALFORMAT);
arr = realloc(pat->c.set.elem, (size_t)(pat->c.set.size + 1) *