]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
src: tidy up types, add necessary casts
authorViktor Szakats <commit@vsz.me>
Mon, 13 May 2024 10:17:33 +0000 (12:17 +0200)
committerViktor Szakats <commit@vsz.me>
Fri, 17 May 2024 10:32:04 +0000 (12:32 +0200)
Cherry-picked from #13489
Closes #13614

14 files changed:
src/tool_cb_hdr.c
src/tool_cb_prg.c
src/tool_cb_wrt.c
src/tool_getparam.c
src/tool_getpass.c
src/tool_help.c
src/tool_helpers.c
src/tool_helpers.h
src/tool_main.c
src/tool_operate.c
src/tool_parsecfg.c
src/tool_sleep.c
src/tool_writeout.c
src/tool_writeout_json.c

index 21407aa2095ab728db0908b3cbea03e99f1af99e..dab4bb01c15bf5e7528e0034bb000ec720009d9c 100644 (file)
@@ -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) {
index d25109eaa835ef1a45c748646e3006dced0c7838..8e50908ddd76579bc7b9e38fb9a7c14b3cda592d 100644 (file)
@@ -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,
@@ -194,7 +194,7 @@ 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;
@@ -202,7 +202,7 @@ int tool_progress_cb(void *clientp,
     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);
@@ -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);
@@ -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;
@@ -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
@@ -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;
index a17b1af5a9683b0cafb560ca94ed3e5fd2d1001f..e01658fd8800ca3916412c1a5a6087c00eaaf514 100644 (file)
@@ -318,7 +318,8 @@ 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;
 
@@ -326,8 +327,8 @@ size_t tool_write_cb(char *buffer, size_t sz, size_t nmemb, void *userdata)
       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;
index 7c265c9afe182416f8f58ba09b00ef627768f7be..508e56797a573f5e4a103a73a7eb1af2dcf0a0ea 100644 (file)
@@ -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) {
@@ -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];
       }
     }
index 8ccccdfb8a3311aecb364e151f2c956aeef39fc6..a7d4260537996d6c83ab9e18a77b8a74a0e1fe6d 100644 (file)
@@ -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! */
index 443e6b492b19caaa2c3cb17c57d955f4866d38c3..f74033d0adf7ee2d4838e3bfb5f2727f2ce172c3 100644 (file)
@@ -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);
     }
 }
 
index 67924a26e8c243eb502b517f46f4d80fad496fe0..8d7a0387a337e6f8230a47081d4a7a24714470b9 100644 (file)
@@ -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";
index 2cfbad21a343f06b6b18a8ceea4f115544a2a8ab..dd085e2cc7902f93556883ac7d45fe53ed8308de 100644 (file)
@@ -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);
index f9a5f9baa02f10949602f8b86bb2ece7e0bf7d43..d0f03336913b4b84540d1264c898bf03d432d895 100644 (file)
@@ -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
 
index 77b2dbd2f0fccda7668da62416bfce28d4dea1d7..d81d59f280e50a40ddf2b6c0c2de334ec7977b1a 100644 (file)
@@ -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;
index a07d4f07b686200de378fe2d3702fef9e5107160..130a3933d29fc78a588b9837a9211f781cf963c2 100644 (file)
@@ -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);
@@ -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;
         }
       }
 
index c24f73729edede06c7b4c45b6d6b9910a2d398d3..31b5f01c929daf716c302aa9e78280e8ca096b8b 100644 (file)
@@ -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
index b8bb174ec7caf0118d33f7fdad07d16e440b8985..ca8424a3c3d4814b39e34faffcf062fdc7fa0f0b 100644 (file)
@@ -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:
index 4ed6b93fb7e53f534f574005797d8fe5149820cf..1a7c1bc1183fd468e217101e167a9482d80cac35 100644 (file)
@@ -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');