Skip to content

Commit d8e7f36

Browse files
authoredMar 15, 2025
ext/curl: Various minor clean-up refactorings (#18042)
1 parent c5f6a8b commit d8e7f36

File tree

3 files changed

+8
-17
lines changed

3 files changed

+8
-17
lines changed
 

‎ext/curl/interface.c

+4-5
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,7 @@ static size_t curl_read(char *data, size_t size, size_t nmemb, void *ctx)
843843
{
844844
php_curl *ch = (php_curl *)ctx;
845845
php_curl_read *read_handler = ch->handlers.read;
846-
int length = 0;
846+
size_t length = 0;
847847

848848
switch (read_handler->method) {
849849
case PHP_CURL_DIRECT:
@@ -1184,15 +1184,14 @@ static void create_certinfo(struct curl_certinfo *ci, zval *listcode)
11841184

11851185
array_init(&certhash);
11861186
for (slist = ci->certinfo[i]; slist; slist = slist->next) {
1187-
int len;
11881187
char s[64];
11891188
char *tmp;
11901189
strncpy(s, slist->data, sizeof(s));
11911190
s[sizeof(s)-1] = '\0';
11921191
tmp = memchr(s, ':', sizeof(s));
11931192
if(tmp) {
11941193
*tmp = '\0';
1195-
len = strlen(s);
1194+
size_t len = strlen(s);
11961195
add_assoc_string(&certhash, s, &slist->data[len+1]);
11971196
} else {
11981197
php_error_docref(NULL, E_WARNING, "Could not extract hash key from certificate info");
@@ -1445,7 +1444,6 @@ static inline zend_result build_mime_structure_from_hash(php_curl *ch, zval *zpo
14451444
zval *prop, rv;
14461445
char *type = NULL, *filename = NULL;
14471446
struct mime_data_cb_arg *cb_arg;
1448-
php_stream *stream;
14491447
php_stream_statbuf ssb;
14501448
size_t filesize = -1;
14511449
curl_seek_callback seekfunc = seek_cb;
@@ -1475,6 +1473,7 @@ static inline zend_result build_mime_structure_from_hash(php_curl *ch, zval *zpo
14751473
zval_ptr_dtor(&ch->postfields);
14761474
ZVAL_COPY(&ch->postfields, zpostfields);
14771475

1476+
php_stream *stream;
14781477
if ((stream = php_stream_open_wrapper(ZSTR_VAL(postval), "rb", STREAM_MUST_SEEK, NULL))) {
14791478
if (!stream->readfilters.head && !php_stream_stat(stream, &ssb)) {
14801479
filesize = ssb.sb.st_size;
@@ -2409,7 +2408,7 @@ PHP_FUNCTION(curl_setopt_array)
24092408
ch = Z_CURL_P(zid);
24102409

24112410
ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(arr), option, string_key, entry) {
2412-
if (string_key) {
2411+
if (UNEXPECTED(string_key)) {
24132412
zend_argument_value_error(2, "contains an invalid cURL option");
24142413
RETURN_THROWS();
24152414
}

‎ext/curl/multi.c

+2-6
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ static int _php_server_push_callback(CURL *parent_ch, CURL *easy, size_t num_hea
403403
php_curl *ch;
404404
php_curl *parent;
405405
php_curlm *mh = (php_curlm *)userp;
406-
size_t rval = CURL_PUSH_DENY;
406+
int rval = CURL_PUSH_DENY;
407407
zval *pz_parent_ch = NULL;
408408
zval pz_ch;
409409
zval headers;
@@ -524,11 +524,7 @@ PHP_FUNCTION(curl_multi_setopt)
524524

525525
mh = Z_CURL_MULTI_P(z_mh);
526526

527-
if (_php_curl_multi_setopt(mh, options, zvalue, return_value)) {
528-
RETURN_TRUE;
529-
} else {
530-
RETURN_FALSE;
531-
}
527+
RETURN_BOOL(_php_curl_multi_setopt(mh, options, zvalue, return_value));
532528
}
533529
/* }}} */
534530

‎ext/curl/share.c

+2-6
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ PHP_FUNCTION(curl_share_close)
5454
}
5555
/* }}} */
5656

57-
static bool _php_curl_share_setopt(php_curlsh *sh, zend_long option, zval *zvalue, zval *return_value) /* {{{ */
57+
static bool _php_curl_share_setopt(php_curlsh *sh, zend_long option, const zval *zvalue) /* {{{ */
5858
{
5959
CURLSHcode error = CURLSHE_OK;
6060

@@ -91,11 +91,7 @@ PHP_FUNCTION(curl_share_setopt)
9191

9292
sh = Z_CURL_SHARE_P(z_sh);
9393

94-
if (_php_curl_share_setopt(sh, options, zvalue, return_value)) {
95-
RETURN_TRUE;
96-
} else {
97-
RETURN_FALSE;
98-
}
94+
RETURN_BOOL(_php_curl_share_setopt(sh, options, zvalue));
9995
}
10096
/* }}} */
10197

0 commit comments

Comments
 (0)
Failed to load comments.