Skip to content

Commit

Permalink
src PR curl#13470
Browse files Browse the repository at this point in the history
  • Loading branch information
vszakats committed Apr 29, 2024
1 parent 00ce0ba commit fab60a4
Show file tree
Hide file tree
Showing 15 changed files with 51 additions and 52 deletions.
2 changes: 1 addition & 1 deletion src/mkhelp.pl
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
memset(&z, 0, sizeof(z_stream));
z.zalloc = (alloc_func)zalloc_func;
z.zfree = (free_func)zfree_func;
z.avail_in = (unsigned int)(sizeof(hugehelpgz) - headerlen);
z.avail_in = (unsigned int)(sizeof(hugehelpgz) - (size_t)headerlen);
z.next_in = (unsigned char *)hugehelpgz + headerlen;
if(inflateInit2(&z, -MAX_WBITS) != Z_OK)
Expand Down
9 changes: 3 additions & 6 deletions src/tool_cb_hdr.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ size_t tool_header_cb(char *ptr, size_t size, size_t nmemb, void *userdata)
eot--;

if(eot >= etag_h) {
size_t etag_length = eot - etag_h + 1;
size_t etag_length = (size_t)(eot - etag_h + 1);
/*
* Truncate the etag save stream, it can have an existing etag value.
*/
Expand Down Expand Up @@ -187,10 +187,7 @@ size_t tool_header_cb(char *ptr, size_t size, size_t nmemb, void *userdata)
}
p += 9;

/* this expression below typecasts 'cb' only to avoid
warning: signed and unsigned type in conditional expression
*/
len = (ssize_t)cb - (p - str);
len = cb - (size_t)(p - str);
filename = parse_filename(p, len);
if(filename) {
if(outs->stream) {
Expand Down Expand Up @@ -250,7 +247,7 @@ size_t tool_header_cb(char *ptr, size_t size, size_t nmemb, void *userdata)
hdrcbdata->global->styled_output)
value = memchr(ptr, ':', cb);
if(value) {
size_t namelen = value - ptr;
size_t namelen = (size_t)(value - ptr);
fprintf(outs->stream, BOLD "%.*s" BOLDOFF ":", (int)namelen, ptr);
#ifndef LINK
fwrite(&value[1], cb - namelen - 1, 1, outs->stream);
Expand Down
18 changes: 9 additions & 9 deletions src/tool_cb_prg.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
printf "%d, ", sin($i/200 * 2 * $pi) * 500000 + 500000;
}
*/
static const unsigned int sinus[] = {
static const int sinus[] = {
515704, 531394, 547052, 562664, 578214, 593687, 609068, 624341, 639491,
654504, 669364, 684057, 698568, 712883, 726989, 740870, 754513, 767906,
781034, 793885, 806445, 818704, 830647, 842265, 853545, 864476, 875047,
Expand Down Expand Up @@ -86,7 +86,7 @@ static void fly(struct ProgressData *bar, bool moved)

/* bar->width is range checked when assigned */
DEBUGASSERT(bar->width <= MAX_BARLENGTH);
memset(buf, ' ', bar->width);
memset(buf, ' ', (size_t)bar->width);
buf[bar->width] = '\r';
buf[bar->width + 1] = '\0';

Expand Down Expand Up @@ -194,15 +194,15 @@ int tool_progress_cb(void *clientp,
double frac;
double percent;
int barwidth;
int num;
size_t num;
if(point > total)
/* we have got more than the expected total! */
total = point;

frac = (double)point / (double)total;
percent = frac * 100.0;
barwidth = bar->width - 7;
num = (int) (((double)barwidth) * frac);
num = (size_t) (((double)barwidth) * frac);
if(num > MAX_BARLENGTH)
num = MAX_BARLENGTH;
memset(line, '#', num);
Expand Down Expand Up @@ -257,7 +257,7 @@ unsigned int get_terminal_columns(void)
#elif defined(TIOCGWINSZ)
struct winsize ts;
if(!ioctl(STDIN_FILENO, TIOCGWINSZ, &ts))
cols = ts.ws_col;
cols = (int)ts.ws_col;
#elif defined(_WIN32)
{
HANDLE stderr_hnd = GetStdHandle(STD_ERROR_HANDLE);
Expand All @@ -274,8 +274,8 @@ unsigned int get_terminal_columns(void)
}
}
#endif /* TIOCGSIZE */
if(cols < 10000)
width = cols;
if(cols >= 0 && cols < 10000)
width = (unsigned int)cols;
}
if(!width)
width = 79;
Expand All @@ -285,7 +285,7 @@ unsigned int get_terminal_columns(void)
void progressbarinit(struct ProgressData *bar,
struct OperationConfig *config)
{
int cols;
unsigned int cols;
memset(bar, 0, sizeof(struct ProgressData));

/* pass the resume from value through to the progress function so it can
Expand All @@ -297,7 +297,7 @@ void progressbarinit(struct ProgressData *bar,
if(cols > MAX_BARLENGTH)
bar->width = MAX_BARLENGTH;
else if(cols > 20)
bar->width = cols;
bar->width = (int)cols;

bar->out = tool_stderr;
bar->tick = 150;
Expand Down
2 changes: 1 addition & 1 deletion src/tool_cb_wrt.c
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ size_t tool_write_cb(char *buffer, size_t sz, size_t nmemb, void *userdata)

if(bytes == rc)
/* we added this amount of data to the output */
outs->bytes += bytes;
outs->bytes += (curl_off_t)bytes;

if(config->readbusy) {
config->readbusy = FALSE;
Expand Down
7 changes: 4 additions & 3 deletions src/tool_getparam.c
Original file line number Diff line number Diff line change
Expand Up @@ -860,12 +860,13 @@ static ParameterError data_urlencode(struct GlobalConfig *global,
/* there was no '=' letter, check for a '@' instead */
p = strchr(nextarg, '@');
if(p) {
nlen = p - nextarg; /* length of the name part */
nlen = (size_t)(p - nextarg); /* length of the name part */
is_file = *p++; /* pass the separator */
}
else {
/* neither @ nor =, so no name and it isn't a file */
nlen = is_file = 0;
nlen = 0;
is_file = 0;
p = nextarg;
}
if('@' == is_file) {
Expand Down Expand Up @@ -1018,7 +1019,7 @@ static const struct LongShort *single(char letter)
unsigned int j;
for(j = 0; j < sizeof(aliases)/sizeof(aliases[0]); j++) {
if(aliases[j].letter != ' ') {
unsigned char l = aliases[j].letter;
unsigned char l = (unsigned char)aliases[j].letter;
singles[l - ' '] = &aliases[j];
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/tool_getpass.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,12 @@ static bool ttyecho(bool enable, int fd)
#ifdef HAVE_TERMIOS_H
tcgetattr(fd, &withecho);
noecho = withecho;
noecho.c_lflag &= ~ECHO;
noecho.c_lflag &= ~(tcflag_t)ECHO;
tcsetattr(fd, TCSANOW, &noecho);
#elif defined(HAVE_TERMIO_H)
ioctl(fd, TCGETA, &withecho);
noecho = withecho;
noecho.c_lflag &= ~ECHO;
noecho.c_lflag &= ~(tcflag_t)ECHO;
ioctl(fd, TCSETA, &noecho);
#else
/* neither HAVE_TERMIO_H nor HAVE_TERMIOS_H, we can't disable echo! */
Expand Down
6 changes: 3 additions & 3 deletions src/tool_help.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,15 @@ static void print_category(curlhelp_t category, unsigned int cols)

for(i = 0; helptext[i].opt; ++i)
if(helptext[i].categories & category) {
int opt = (int)longopt;
size_t opt = longopt;
size_t desclen = strlen(helptext[i].desc);
if(opt + desclen >= (cols - 2)) {
if(desclen < (cols - 2))
opt = (cols - 3) - (int)desclen;
opt = (cols - 3) - desclen;
else
opt = 0;
}
printf(" %-*s %s\n", opt, helptext[i].opt, helptext[i].desc);
printf(" %-*s %s\n", (int)opt, helptext[i].opt, helptext[i].desc);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/tool_libinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ CURLcode get_libcurl_info(void)
break;
}
}
proto_count = builtin - built_in_protos;
proto_count = (size_t)(builtin - built_in_protos);
}

if(curlinfo->age >= CURLVERSION_ELEVENTH && curlinfo->feature_names)
Expand Down
2 changes: 1 addition & 1 deletion src/tool_operate.c
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,7 @@ static CURLcode single_transfer(struct GlobalConfig *global,
*added = TRUE;
per->config = config;
per->curl = curl;
per->urlnum = urlnode->num;
per->urlnum = (unsigned int)urlnode->num;

/* default headers output stream is stdout */
heads = &per->heads;
Expand Down
4 changes: 2 additions & 2 deletions src/tool_paramhlp.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ static size_t memcrlf(char *orig,
for(ptr = orig; max; max--, ptr++) {
bool crlf = ISCRLF(*ptr);
if(countcrlf ^ crlf)
return ptr - orig;
return (size_t)(ptr - orig);
}
return total; /* no delimiter found */
}
Expand Down Expand Up @@ -319,7 +319,7 @@ static size_t protoset_index(const char * const *protoset, const char *proto)
for(; *p; p++)
if(proto == *p)
break;
return p - protoset;
return (size_t)(p - protoset);
}

/* Include protocol token in set. */
Expand Down
8 changes: 4 additions & 4 deletions src/tool_setopt.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ static char *c_escape(const char *str, curl_off_t len)
curlx_dyn_init(&escaped, 4 * MAX_STRING_LENGTH_OUTPUT + 3);

if(len == ZERO_TERMINATED)
len = strlen(str);
len = (curl_off_t)strlen(str);

if(len > MAX_STRING_LENGTH_OUTPUT) {
/* cap ridiculously long strings */
Expand All @@ -242,7 +242,7 @@ static char *c_escape(const char *str, curl_off_t len)
if(!p && ISPRINT(*s))
continue;

result = curlx_dyn_addn(&escaped, str, s - str);
result = curlx_dyn_addn(&escaped, str, (size_t)(s - str));
str = s + 1;

if(!result) {
Expand All @@ -259,7 +259,7 @@ static char *c_escape(const char *str, curl_off_t len)
}

if(!result)
result = curlx_dyn_addn(&escaped, str, s - str);
result = curlx_dyn_addn(&escaped, str, (size_t)(s - str));

if(!result)
(void) !curlx_dyn_addn(&escaped, "...", cutoff);
Expand Down Expand Up @@ -702,7 +702,7 @@ CURLcode tool_setopt(CURL *curl, bool str, struct GlobalConfig *global,
if(escape) {
curl_off_t len = ZERO_TERMINATED;
if(tag == CURLOPT_POSTFIELDS)
len = curlx_dyn_len(&config->postdata);
len = (curl_off_t)curlx_dyn_len(&config->postdata);
escaped = c_escape(value, len);
NULL_CHECK(escaped);
CODE2("curl_easy_setopt(hnd, %s, \"%s\");", name, escaped);
Expand Down
13 changes: 7 additions & 6 deletions src/tool_urlglob.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ static CURLcode glob_range(struct URLGlob *glob, char **patternp,
pattern += 4;
}

*posp += (pattern - *patternp);
*posp += (size_t)(pattern - *patternp);

if(rc != 3 || !step || step > (unsigned)INT_MAX ||
(min_c == max_c && step != 1) ||
Expand Down Expand Up @@ -307,7 +307,7 @@ static CURLcode glob_range(struct URLGlob *glob, char **patternp,
}

fail:
*posp += (pattern - *patternp);
*posp += (size_t)(pattern - *patternp);

if(!endp || !step_n ||
(min_n == max_n && step_n != 1) ||
Expand All @@ -317,9 +317,10 @@ static CURLcode glob_range(struct URLGlob *glob, char **patternp,

/* typecasting to ints are fine here since we make sure above that we
are within 31 bits */
pat->content.NumRange.ptr_n = pat->content.NumRange.min_n = min_n;
pat->content.NumRange.max_n = max_n;
pat->content.NumRange.step = step_n;
pat->content.NumRange.ptr_n = pat->content.NumRange.min_n =
(curl_off_t)min_n;
pat->content.NumRange.max_n = (curl_off_t)max_n;
pat->content.NumRange.step = (curl_off_t)step_n;

if(multiply(amount, ((pat->content.NumRange.max_n -
pat->content.NumRange.min_n) /
Expand Down Expand Up @@ -350,7 +351,7 @@ static bool peek_ipv6(const char *str, size_t *skip)
if(!endbr)
return FALSE;

hlen = endbr - str + 1;
hlen = (size_t)(endbr - str + 1);
if(hlen >= MAX_IP6LEN)
return FALSE;

Expand Down
6 changes: 3 additions & 3 deletions src/tool_writeout.c
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ void ourWriteOut(struct OperationConfig *config, struct per_transfer *per,
fputs("%{", stream);
continue;
}
vlen = end - ptr;
vlen = (size_t)(end - ptr);
for(i = 0; variables[i].name; i++) {
if((strlen(variables[i].name) == vlen) &&
curl_strnequal(ptr, variables[i].name, vlen)) {
Expand Down Expand Up @@ -596,7 +596,7 @@ void ourWriteOut(struct OperationConfig *config, struct per_transfer *per,
if(end) {
char hname[256]; /* holds the longest header field name */
struct curl_header *header;
vlen = end - ptr;
vlen = (size_t)(end - ptr);
if(vlen < sizeof(hname)) {
memcpy(hname, ptr, vlen);
hname[vlen] = 0;
Expand All @@ -619,7 +619,7 @@ void ourWriteOut(struct OperationConfig *config, struct per_transfer *per,
end = strchr(ptr, '}');
if(end) {
char fname[512]; /* holds the longest file name */
size_t flen = end - ptr;
size_t flen = (size_t)(end - ptr);
if(flen < sizeof(fname)) {
FILE *stream2;
memcpy(fname, ptr, flen);
Expand Down
2 changes: 1 addition & 1 deletion src/tool_writeout_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ int jsonquoted(const char *in, size_t len,
if(*i < 32)
result = curlx_dyn_addf(out, "\\u%04x", *i);
else {
char o = *i;
char o = (char)*i;
if(lowercase && (o >= 'A' && o <= 'Z'))
/* do not use tolower() since that's locale specific */
o |= ('a' - 'A');
Expand Down
18 changes: 9 additions & 9 deletions src/var.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ ParameterError varexpand(struct GlobalConfig *global,
/* preceding backslash, we want this verbatim */

/* insert the text up to this point, minus the backslash */
result = curlx_dyn_addn(out, line, envp - line - 1);
result = curlx_dyn_addn(out, line, (size_t)(envp - line - 1));
if(result)
return PARAM_NO_MEM;

Expand Down Expand Up @@ -250,21 +250,21 @@ ParameterError varexpand(struct GlobalConfig *global,
envp += 2; /* move over the {{ */

/* if there is a function, it ends the name with a colon */
funcp = memchr(envp, ':', clp - envp);
funcp = memchr(envp, ':', (size_t)(clp - envp));
if(funcp)
nlen = funcp - envp;
nlen = (size_t)(funcp - envp);
else
nlen = clp - envp;
nlen = (size_t)(clp - envp);
if(!nlen || (nlen >= sizeof(name))) {
warnf(global, "bad variable name length '%s'", input);
/* insert the text as-is since this is not an env variable */
result = curlx_dyn_addn(out, line, clp - line + prefix);
result = curlx_dyn_addn(out, line, (size_t)(clp - line) + prefix);
if(result)
return PARAM_NO_MEM;
}
else {
/* insert the text up to this point */
result = curlx_dyn_addn(out, line, envp - prefix - line);
result = curlx_dyn_addn(out, line, (size_t)(envp - line) - prefix);
if(result)
return PARAM_NO_MEM;

Expand All @@ -279,7 +279,7 @@ ParameterError varexpand(struct GlobalConfig *global,
warnf(global, "bad variable name: %s", name);
/* insert the text as-is since this is not an env variable */
result = curlx_dyn_addn(out, envp - prefix,
clp - envp + prefix + 2);
(size_t)(clp - envp) + prefix + 2);
if(result)
return PARAM_NO_MEM;
}
Expand All @@ -298,7 +298,7 @@ ParameterError varexpand(struct GlobalConfig *global,
curlx_dyn_init(&buf, MAX_EXPAND_CONTENT);
if(funcp) {
/* apply the list of functions on the value */
size_t flen = clp - funcp;
size_t flen = (size_t)(clp - funcp);
ParameterError err = varfunc(global, value, vlen, funcp, flen,
&buf);
if(err)
Expand Down Expand Up @@ -397,7 +397,7 @@ ParameterError setvariable(struct GlobalConfig *global,
name = line;
while(*line && (ISALNUM(*line) || (*line == '_')))
line++;
nlen = line - name;
nlen = (size_t)(line - name);
if(!nlen || (nlen >= MAX_VAR_LEN)) {
warnf(global, "Bad variable name length (%zd), skipping", nlen);
return PARAM_OK;
Expand Down

0 comments on commit fab60a4

Please sign in to comment.