From: Daniel Stenberg Date: Sun, 5 Oct 2025 12:07:39 +0000 (+0200) Subject: url: make Curl_init_userdefined return void X-Git-Tag: rc-8_17_0-2~245 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b54b4697cad23fcf81577ce9e8f1ea18b8449427;p=thirdparty%2Fcurl.git url: make Curl_init_userdefined return void It cannot actually return an error, so the parent function does not need to check for error and have an exit path that cannot be reached. Pointed out by CodeSonar Closes #18855 --- diff --git a/lib/easy.c b/lib/easy.c index 0a4b6faf52..7a36034c03 100644 --- a/lib/easy.c +++ b/lib/easy.c @@ -1110,7 +1110,7 @@ void curl_easy_reset(CURL *d) /* zero out UserDefined data: */ Curl_freeset(data); memset(&data->set, 0, sizeof(struct UserDefined)); - (void)Curl_init_userdefined(data); + Curl_init_userdefined(data); /* zero out Progress data: */ memset(&data->progress, 0, sizeof(struct Progress)); diff --git a/lib/url.c b/lib/url.c index 0dface920d..ae4a6f6502 100644 --- a/lib/url.c +++ b/lib/url.c @@ -355,10 +355,9 @@ CURLcode Curl_close(struct Curl_easy **datap) * Initialize the UserDefined fields within a Curl_easy. * This may be safely called on a new or existing Curl_easy. */ -CURLcode Curl_init_userdefined(struct Curl_easy *data) +void Curl_init_userdefined(struct Curl_easy *data) { struct UserDefined *set = &data->set; - CURLcode result = CURLE_OK; set->out = stdout; /* default output to stdout */ set->in_set = stdin; /* default input from stdin */ @@ -476,8 +475,6 @@ CURLcode Curl_init_userdefined(struct Curl_easy *data) set->ws_raw_mode = FALSE; set->ws_no_auto_pong = FALSE; #endif - - return result; } /* easy->meta_hash destructor. Should never be called as elements @@ -501,7 +498,6 @@ static void easy_meta_freeentry(void *p) CURLcode Curl_open(struct Curl_easy **curl) { - CURLcode result; struct Curl_easy *data; /* simple start-up: alloc the struct, init it with zeroes and return */ @@ -532,21 +528,10 @@ CURLcode Curl_open(struct Curl_easy **curl) Curl_llist_init(&data->state.httphdrs, NULL); #endif Curl_netrc_init(&data->state.netrc); + Curl_init_userdefined(data); - result = Curl_init_userdefined(data); - - if(result) { - curlx_dyn_free(&data->state.headerb); - Curl_freeset(data); - Curl_req_free(&data->req, data); - Curl_hash_destroy(&data->meta_hash); - data->magic = 0; - free(data); - data = NULL; - } - else - *curl = data; - return result; + *curl = data; + return CURLE_OK; } void Curl_conn_free(struct Curl_easy *data, struct connectdata *conn) diff --git a/lib/url.h b/lib/url.h index 11a69d4157..82d869c5ff 100644 --- a/lib/url.h +++ b/lib/url.h @@ -31,7 +31,7 @@ CURLcode Curl_init_do(struct Curl_easy *data, struct connectdata *conn); CURLcode Curl_open(struct Curl_easy **curl); -CURLcode Curl_init_userdefined(struct Curl_easy *data); +void Curl_init_userdefined(struct Curl_easy *data); void Curl_freeset(struct Curl_easy *data); CURLcode Curl_uc_to_curlcode(CURLUcode uc); diff --git a/tests/unit/unit1620.c b/tests/unit/unit1620.c index 14b377b640..4851602eaa 100644 --- a/tests/unit/unit1620.c +++ b/tests/unit/unit1620.c @@ -97,9 +97,6 @@ static CURLcode test_unit1620(const char *arg) fail_unless(rc == CURLE_URL_MALFORMAT, "Curl_connect() failed to return CURLE_URL_MALFORMAT"); - rc = Curl_init_userdefined(empty); - fail_unless(rc == CURLE_OK, "Curl_userdefined() failed"); - rc = Curl_init_do(empty, empty->conn); fail_unless(rc == CURLE_OK, "Curl_init_do() failed");