lib: use size_t or int etc instead of longs

Since long is not using a consistent data size in curl builds, making it
often "waste" 32 bits.

Closes #10088
This commit is contained in:
Daniel Stenberg 2022-12-13 15:02:00 +01:00
parent 58f55ba57e
commit 57d2d9b6be
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2
5 changed files with 14 additions and 14 deletions

View File

@ -334,7 +334,7 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
struct ftp_parselist_data *parser = ftpwc->parser; struct ftp_parselist_data *parser = ftpwc->parser;
struct fileinfo *infop; struct fileinfo *infop;
struct curl_fileinfo *finfo; struct curl_fileinfo *finfo;
unsigned long i = 0; size_t i = 0;
CURLcode result; CURLcode result;
size_t retsize = bufflen; size_t retsize = bufflen;

View File

@ -1166,7 +1166,7 @@ CURLcode Curl_vsetopt(struct Curl_easy *data, CURLoption option, va_list param)
break; break;
case CURLOPT_SOCKS5_AUTH: case CURLOPT_SOCKS5_AUTH:
data->set.socks5auth = va_arg(param, unsigned long); data->set.socks5auth = (unsigned char)va_arg(param, unsigned long);
if(data->set.socks5auth & ~(CURLAUTH_BASIC | CURLAUTH_GSSAPI)) if(data->set.socks5auth & ~(CURLAUTH_BASIC | CURLAUTH_GSSAPI))
result = CURLE_NOT_BUILT_IN; result = CURLE_NOT_BUILT_IN;
break; break;

View File

@ -526,10 +526,11 @@ static CURLproxycode do_SOCKS5(struct Curl_cfilter *cf,
(conn->socks_proxy.proxytype == CURLPROXY_SOCKS5) ? TRUE : FALSE; (conn->socks_proxy.proxytype == CURLPROXY_SOCKS5) ? TRUE : FALSE;
const size_t hostname_len = strlen(sx->hostname); const size_t hostname_len = strlen(sx->hostname);
ssize_t len = 0; ssize_t len = 0;
const unsigned long auth = data->set.socks5auth; const unsigned char auth = data->set.socks5auth;
bool allow_gssapi = FALSE; bool allow_gssapi = FALSE;
struct Curl_dns_entry *dns = NULL; struct Curl_dns_entry *dns = NULL;
DEBUGASSERT(auth & (CURLAUTH_BASIC | CURLAUTH_GSSAPI));
switch(sx->state) { switch(sx->state) {
case CONNECT_SOCKS_INIT: case CONNECT_SOCKS_INIT:
if(conn->bits.httpproxy) if(conn->bits.httpproxy)

View File

@ -1627,7 +1627,7 @@ struct UserDefined {
unsigned long httpauth; /* kind of HTTP authentication to use (bitmask) */ unsigned long httpauth; /* kind of HTTP authentication to use (bitmask) */
unsigned long proxyauth; /* kind of proxy authentication to use (bitmask) */ unsigned long proxyauth; /* kind of proxy authentication to use (bitmask) */
#ifndef CURL_DISABLE_PROXY #ifndef CURL_DISABLE_PROXY
unsigned long socks5auth;/* kind of SOCKS5 authentication to use (bitmask) */ unsigned char socks5auth;/* kind of SOCKS5 authentication to use (bitmask) */
#endif #endif
long maxredirs; /* maximum no. of http(s) redirects to follow, set to -1 long maxredirs; /* maximum no. of http(s) redirects to follow, set to -1
for infinity */ for infinity */

View File

@ -182,7 +182,7 @@ static const char *getASN1Element(struct Curl_asn1Element *elem,
const char *beg, const char *end) const char *beg, const char *end)
{ {
unsigned char b; unsigned char b;
unsigned long len; size_t len;
struct Curl_asn1Element lelem; struct Curl_asn1Element lelem;
/* Get a single ASN.1 element into `elem', parse ASN.1 string at `beg' /* Get a single ASN.1 element into `elem', parse ASN.1 string at `beg'
@ -307,7 +307,7 @@ static const char *bit2str(const char *beg, const char *end)
*/ */
static const char *int2str(const char *beg, const char *end) static const char *int2str(const char *beg, const char *end)
{ {
unsigned long val = 0; unsigned int val = 0;
size_t n = end - beg; size_t n = end - beg;
if(!n) if(!n)
@ -323,7 +323,7 @@ static const char *int2str(const char *beg, const char *end)
do do
val = (val << 8) | *(const unsigned char *) beg++; val = (val << 8) | *(const unsigned char *) beg++;
while(beg < end); while(beg < end);
return curl_maprintf("%s%lx", val >= 10? "0x": "", val); return curl_maprintf("%s%x", val >= 10? "0x": "", val);
} }
/* /*
@ -953,8 +953,7 @@ static int do_pubkey(struct Curl_easy *data, int certnum,
* ECC public key is all the data, a value of type BIT STRING mapped to * ECC public key is all the data, a value of type BIT STRING mapped to
* OCTET STRING and should not be parsed as an ASN.1 value. * OCTET STRING and should not be parsed as an ASN.1 value.
*/ */
const unsigned long len = const size_t len = ((pubkey->end - pubkey->beg - 2) * 4);
(unsigned long)((pubkey->end - pubkey->beg - 2) * 4);
if(!certnum) if(!certnum)
infof(data, " ECC Public Key (%lu bits)", len); infof(data, " ECC Public Key (%lu bits)", len);
if(data->set.ssl.certinfo) { if(data->set.ssl.certinfo) {
@ -972,7 +971,7 @@ static int do_pubkey(struct Curl_easy *data, int certnum,
if(strcasecompare(algo, "rsaEncryption")) { if(strcasecompare(algo, "rsaEncryption")) {
const char *q; const char *q;
unsigned long len; size_t len;
p = getASN1Element(&elem, pk.beg, pk.end); p = getASN1Element(&elem, pk.beg, pk.end);
if(!p) if(!p)
@ -981,7 +980,7 @@ static int do_pubkey(struct Curl_easy *data, int certnum,
/* Compute key length. */ /* Compute key length. */
for(q = elem.beg; !*q && q < elem.end; q++) for(q = elem.beg; !*q && q < elem.end; q++)
; ;
len = (unsigned long)((elem.end - q) * 8); len = ((elem.end - q) * 8);
if(len) { if(len) {
unsigned int i; unsigned int i;
for(i = *(unsigned char *) q; !(i & 0x80); i <<= 1) for(i = *(unsigned char *) q; !(i & 0x80); i <<= 1)
@ -1073,7 +1072,7 @@ CURLcode Curl_extract_certinfo(struct Curl_easy *data,
size_t cl1; size_t cl1;
char *cp2; char *cp2;
CURLcode result = CURLE_OK; CURLcode result = CURLE_OK;
unsigned long version; unsigned int version;
size_t i; size_t i;
size_t j; size_t j;
@ -1361,8 +1360,8 @@ CURLcode Curl_verifyhost(struct Curl_cfilter *cf,
break; break;
case 7: /* IP address. */ case 7: /* IP address. */
matched = (size_t) (name.end - name.beg) == addrlen && matched = (name.end - name.beg) == addrlen &&
!memcmp(&addr, name.beg, addrlen); !memcmp(&addr, name.beg, addrlen);
break; break;
} }
} }