Skip to content

Commit

Permalink
src: tidy up types, add necessary casts
Browse files Browse the repository at this point in the history
Cherry-picked from #13489
Closes #13614
  • Loading branch information
vszakats committed May 17, 2024
1 parent d0728c9 commit 1a89538
Show file tree
Hide file tree
Showing 14 changed files with 30 additions and 32 deletions.
5 changes: 1 addition & 4 deletions src/tool_cb_hdr.c
Original file line number Diff line number Diff line change
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
16 changes: 8 additions & 8 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 @@ -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
7 changes: 4 additions & 3 deletions src/tool_cb_wrt.c
Original file line number Diff line number Diff line change
Expand Up @@ -318,16 +318,17 @@ size_t tool_write_cb(char *buffer, size_t sz, size_t nmemb, void *userdata)

if(rlen) {
/* calculate buffer size for wide characters */
wc_len = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)rbuf, rlen, NULL, 0);
wc_len = (DWORD)MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)rbuf, (int)rlen,
NULL, 0);
if(!wc_len)
return CURL_WRITEFUNC_ERROR;

wc_buf = (wchar_t*) malloc(wc_len * sizeof(wchar_t));
if(!wc_buf)
return CURL_WRITEFUNC_ERROR;

wc_len = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)rbuf, rlen, wc_buf,
wc_len);
wc_len = (DWORD)MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)rbuf, (int)rlen,
wc_buf, (int)wc_len);
if(!wc_len) {
free(wc_buf);
return CURL_WRITEFUNC_ERROR;
Expand Down
5 changes: 3 additions & 2 deletions src/tool_getparam.c
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,8 @@ static ParameterError data_urlencode(struct GlobalConfig *global,
}
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 @@ -1017,7 +1018,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
3 changes: 1 addition & 2 deletions src/tool_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@
** Helper functions that are used from more than one source file.
*/

const char *param2text(int res)
const char *param2text(ParameterError error)
{
ParameterError error = (ParameterError)res;
switch(error) {
case PARAM_GOT_EXTRA_PARAMETER:
return "had unsupported trailing garbage";
Expand Down
2 changes: 1 addition & 1 deletion src/tool_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
***************************************************************************/
#include "tool_setup.h"

const char *param2text(int res);
const char *param2text(ParameterError error);

int SetHTTPrequest(struct OperationConfig *config, HttpReq req,
HttpReq *store);
Expand Down
2 changes: 1 addition & 1 deletion src/tool_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ int main(int argc, char *argv[])
result = win32_init();
if(result) {
errorf(&global, "(%d) Windows-specific init failed", result);
return result;
return (int)result;
}
#endif

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_parsecfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ int parseconfig(const char *filename, struct GlobalConfig *global)
DEBUGASSERT(filename);

while(!rc && my_get_line(file, &buf, &fileerror)) {
int res;
ParameterError res;
bool alloced_param = FALSE;
lineno++;
line = curlx_dyn_ptr(&buf);
Expand Down Expand Up @@ -266,7 +266,7 @@ int parseconfig(const char *filename, struct GlobalConfig *global)
const char *reason = param2text(res);
errorf(operation->global, "%s:%d: '%s' %s",
filename, lineno, option, reason);
rc = res;
rc = (int)res;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/tool_sleep.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void tool_go_sleep(long ms)
#if defined(MSDOS)
delay(ms);
#elif defined(_WIN32)
Sleep(ms);
Sleep((DWORD)ms);
#elif defined(HAVE_POLL_FINE)
(void)poll((void *)0, 0, (int)ms);
#else
Expand Down
2 changes: 1 addition & 1 deletion src/tool_writeout.c
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ static int writeLong(FILE *stream, const struct writeoutvar *wovar,
valid = true;
break;
case VAR_EXITCODE:
longinfo = per_result;
longinfo = (long)per_result;
valid = true;
break;
case VAR_URLNUM:
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

0 comments on commit 1a89538

Please sign in to comment.