← Commit list

e2be568974

Stefan Eissing
Stefan Eissing
2025-11-21
SUCCESS Duration: 146s

Subject

multi: make max_total_* members size_t

Binary

No binary (build failed)

Architecture & Compiler Flags

Architecture: x86_64-linux-gnu Compiler: gcc (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0

—

Build Log

(log yok)

Commit Diff GitHub →

lib/cshutdn.c+1 -2
@@ -414,8 +414,7 @@ void Curl_cshutdn_add(struct cshutdn *cshutdn,
size_t conns_in_pool)
{
struct Curl_easy *data = cshutdn->multi->admin;
- size_t max_total = (cshutdn->multi->max_total_connections > 0) ?
- (size_t)cshutdn->multi->max_total_connections : 0;
+ size_t max_total = cshutdn->multi->max_total_connections;
/* Add the connection to our shutdown list for non-blocking shutdown
* during multi processing. */
lib/curl_setup.h+3 -0
@@ -627,6 +627,9 @@
#endif
#endif
+#if SIZEOF_LONG > SIZEOF_SIZE_T
+#error "unexpected: 'long' is larger than 'size_t'"
+#endif
/*
* Arg 2 type for gethostname in case it has not been defined in config file.
*/
lib/curlx/warnless.c+12 -0
@@ -333,6 +333,18 @@ bool curlx_sotouz_fits(curl_off_t sonum, size_t *puznum)
return TRUE;
}
+
+bool curlx_sltouz(long slnum, size_t *puznum)
+{
+ if(slnum < 0) {
+ *puznum = 0;
+ return FALSE;
+ }
+ /* We error in curl_setup.h if SIZEOF_LONG > SIZEOF_SIZE_T */
+ *puznum = (size_t)slnum;
+ return TRUE;
+}
+
curl_off_t curlx_uztoso(size_t uznum)
{
#if SIZEOF_SIZE_T >= SIZEOF_CURL_OFF_T
lib/curlx/warnless.h+4 -0
@@ -73,6 +73,10 @@ bool curlx_sztouz(ssize_t sznum, size_t *puznum);
* too large and set 0 */
bool curlx_sotouz_fits(curl_off_t sonum, size_t *puznum);
+/* Convert a long to size_t, return FALSE if negative or too large
+ * and set 0 */
+bool curlx_sltouz(long sznum, size_t *puznum);
+
#ifdef _WIN32
#undef read
#define read(fd, buf, count) (ssize_t)_read(fd, buf, curlx_uztoui(count))
lib/multi.c+4 -2
@@ -3271,10 +3271,12 @@ CURLMcode curl_multi_setopt(CURLM *m,
multi->maxconnects = (unsigned int)uarg;
break;
case CURLMOPT_MAX_HOST_CONNECTIONS:
- multi->max_host_connections = va_arg(param, long);
+ if(!curlx_sltouz(va_arg(param, long), &multi->max_host_connections))
+ res = CURLM_BAD_FUNCTION_ARGUMENT;
break;
case CURLMOPT_MAX_TOTAL_CONNECTIONS:
- multi->max_total_connections = va_arg(param, long);
+ if(!curlx_sltouz(va_arg(param, long), &multi->max_total_connections))
+ res = CURLM_BAD_FUNCTION_ARGUMENT;
break;
/* options formerly used for pipelining */
case CURLMOPT_MAX_PIPELINE_LENGTH:
lib/multihandle.h+4 -5
@@ -149,11 +149,10 @@ struct Curl_multi {
struct cshutdn cshutdn; /* connection shutdown handling */
struct cpool cpool; /* connection pool (bundles) */
- long max_host_connections; /* if >0, a fixed limit of the maximum number
- of connections per host */
-
- long max_total_connections; /* if >0, a fixed limit of the maximum number
- of connections in total */
+ size_t max_host_connections; /* if >0, a fixed limit of the maximum number
+ of connections per host */
+ size_t max_total_connections; /* if >0, a fixed limit of the maximum number
+ of connections in total */
/* timer callback and user data pointer for the *socket() API */
curl_multi_timer_callback timer_cb;
lib/url.c+1 -1
@@ -3690,7 +3690,7 @@ static CURLcode create_conn(struct Curl_easy *data,
CURL_TRC_M(data, "Allowing sub-requests (like DoH) to override "
"max connection limit");
else {
- infof(data, "No connections available, total of %ld reached.",
+ infof(data, "No connections available, total of %zu reached.",
data->multi->max_total_connections);
connections_available = FALSE;
}