From 4651945822eaae1ac34ab1179f7bd620cee6e4a8 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 31 May 2022 13:42:31 +0200 Subject: [PATCH] urldata: reduce size of a few struct fields When the values are never larger than 32 bit, ints are better than longs. Closes #8940 --- lib/setopt.c | 12 ++++++------ lib/url.c | 6 +++--- lib/urldata.h | 16 ++++++++-------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/setopt.c b/lib/setopt.c index 47b8f84715..fa3c4766f3 100644 --- a/lib/setopt.c +++ b/lib/setopt.c @@ -2420,7 +2420,7 @@ CURLcode Curl_vsetopt(struct Curl_easy *data, CURLoption option, va_list param) #ifdef USE_SSH /* we only include SSH options if explicitly built to support SSH */ case CURLOPT_SSH_AUTH_TYPES: - data->set.ssh_auth_types = va_arg(param, long); + data->set.ssh_auth_types = (unsigned int)va_arg(param, long); break; case CURLOPT_SSH_PUBLIC_KEYFILE: @@ -2508,7 +2508,7 @@ CURLcode Curl_vsetopt(struct Curl_easy *data, CURLoption option, va_list param) arg = va_arg(param, long); if((arg < 0) || (arg > 0777)) return CURLE_BAD_FUNCTION_ARGUMENT; - data->set.new_file_perms = arg; + data->set.new_file_perms = (unsigned int)arg; break; case CURLOPT_NEW_DIRECTORY_PERMS: @@ -2518,7 +2518,7 @@ CURLcode Curl_vsetopt(struct Curl_easy *data, CURLoption option, va_list param) arg = va_arg(param, long); if((arg < 0) || (arg > 0777)) return CURLE_BAD_FUNCTION_ARGUMENT; - data->set.new_directory_perms = arg; + data->set.new_directory_perms = (unsigned int)arg; break; #endif @@ -2543,14 +2543,14 @@ CURLcode Curl_vsetopt(struct Curl_easy *data, CURLoption option, va_list param) transfer, which thus helps the app which takes URLs from users or other external inputs and want to restrict what protocol(s) to deal with. Defaults to CURLPROTO_ALL. */ - data->set.allowed_protocols = va_arg(param, long); + data->set.allowed_protocols = (unsigned int)va_arg(param, long); break; case CURLOPT_REDIR_PROTOCOLS: /* set the bitmask for the protocols that libcurl is allowed to follow to, as a subset of the CURLOPT_PROTOCOLS ones. That means the protocol needs to be set in both bitmasks to be allowed to get redirected to. */ - data->set.redir_protocols = va_arg(param, long); + data->set.redir_protocols = (unsigned int)va_arg(param, long); break; case CURLOPT_DEFAULT_PROTOCOL: @@ -2584,7 +2584,7 @@ CURLcode Curl_vsetopt(struct Curl_easy *data, CURLoption option, va_list param) #if (!defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_MIME)) || \ !defined(CURL_DISABLE_SMTP) || !defined(CURL_DISABLE_IMAP) case CURLOPT_MIME_OPTIONS: - data->set.mime_options = va_arg(param, long); + data->set.mime_options = (unsigned int)va_arg(param, long); break; #endif diff --git a/lib/url.c b/lib/url.c index 26ed3dd936..3168d79f4c 100644 --- a/lib/url.c +++ b/lib/url.c @@ -547,8 +547,8 @@ CURLcode Curl_init_userdefined(struct Curl_easy *data) #ifdef USE_TLS_SRP set->ssl.primary.authtype = CURL_TLSAUTH_NONE; #endif - set->ssh_auth_types = CURLSSH_AUTH_DEFAULT; /* defaults to any auth - type */ + /* defaults to any auth type */ + set->ssh_auth_types = CURLSSH_AUTH_DEFAULT; set->ssl.primary.sessionid = TRUE; /* session ID caching enabled by default */ #ifndef CURL_DISABLE_PROXY @@ -561,7 +561,7 @@ CURLcode Curl_init_userdefined(struct Curl_easy *data) /* for the *protocols fields we don't use the CURLPROTO_ALL convenience define since we internally only use the lower 16 bits for the passed in bitmask to not conflict with the private bits */ - set->allowed_protocols = CURLPROTO_ALL; + set->allowed_protocols = (unsigned int)CURLPROTO_ALL; set->redir_protocols = CURLPROTO_HTTP | CURLPROTO_HTTPS | CURLPROTO_FTP | CURLPROTO_FTPS; diff --git a/lib/urldata.h b/lib/urldata.h index e86c241abe..63026063a5 100644 --- a/lib/urldata.h +++ b/lib/urldata.h @@ -1637,8 +1637,6 @@ struct UserDefined { long maxredirs; /* maximum no. of http(s) redirects to follow, set to -1 for infinity */ - int keep_post; /* keep POSTs as POSTs after a 30x request; each - bit represents a request, from 301 to 303 */ void *postfields; /* if POST, set the fields' values here */ curl_seek_callback seek_func; /* function that seeks the input */ curl_off_t postfieldsize; /* if POST, this might have a size to use instead @@ -1746,17 +1744,17 @@ struct UserDefined { #endif curl_usessl use_ssl; /* if AUTH TLS is to be attempted etc, for FTP or IMAP or POP3 or others! */ - long new_file_perms; /* Permissions to use when creating remote files */ - long new_directory_perms; /* Permissions to use when creating remote dirs */ - long ssh_auth_types; /* allowed SSH auth types */ + unsigned int new_file_perms; /* when creating remote files */ + unsigned int new_directory_perms; /* when creating remote dirs */ + int ssh_auth_types; /* allowed SSH auth types */ char *str[STRING_LAST]; /* array of strings, pointing to allocated memory */ struct curl_blob *blobs[BLOB_LAST]; #ifdef ENABLE_IPV6 unsigned int scope_id; /* Scope id for IPv6 */ #endif - long allowed_protocols; - long redir_protocols; - long mime_options; /* Mime option flags. */ + unsigned int allowed_protocols; + unsigned int redir_protocols; + unsigned int mime_options; /* Mime option flags. */ struct curl_slist *mail_rcpt; /* linked list of mail recipients */ /* Common RTSP header options */ Curl_RtspReq rtspreq; /* RTSP request type */ @@ -1791,6 +1789,8 @@ struct UserDefined { CURLU *uh; /* URL handle for the current parsed URL */ void *trailer_data; /* pointer to pass to trailer data callback */ curl_trailer_callback trailer_callback; /* trailing data callback */ + char keep_post; /* keep POSTs as POSTs after a 30x request; each + bit represents a request, from 301 to 303 */ BIT(is_fread_set); /* has read callback been set to non-NULL? */ #ifndef CURL_DISABLE_TFTP BIT(tftp_no_options); /* do not send TFTP options requests */