]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
checksrc: reduce directory-specific exceptions
authorViktor Szakats <commit@vsz.me>
Thu, 2 Oct 2025 19:33:48 +0000 (21:33 +0200)
committerViktor Szakats <commit@vsz.me>
Fri, 3 Oct 2025 22:48:58 +0000 (00:48 +0200)
By making them defaults, then fixing and/or reshuffling remaining
exceptions as necessary.

- checksrc: ban by default: `snprintf`, `vsnprintf`, `sscanf`, `strtol`.
- examples: replace `strtol` with `atoi` to avoid a checksrc exception.
- tests/libtest: replace `strtol` with `atol`.
- tests/server: replace most `strtol` with `atol`.
- tests/server: replace most `strtoul` with `atol`/`atoi`.
- tests/server: drop no longer used `util_ultous`.
- fix typo in checksrc rules: `vsnprint` -> `vsnprintf`.
- update local exceptions.

Also:
- examples: ban curl printf functions. They're discouraged in user code.
- examples: replace curl printf with system printf.
  Add `snprintf` workaround for <VS2015.
- examples/synctime: fix `-Wfloat-equal`.
- examples/synctime: exclude for non-Windows and non-UWP Windows.
- examples/synctime: build by default.

Closes #18823

36 files changed:
docs/examples/.checksrc
docs/examples/Makefile.inc
docs/examples/chkspeed.c
docs/examples/cookie_interface.c
docs/examples/http2-download.c
docs/examples/http2-serverpush.c
docs/examples/http2-upload.c
docs/examples/synctime.c
docs/internals/CODE_STYLE.md
lib/.checksrc
lib/curlx/.checksrc
lib/vauth/.checksrc
lib/vquic/.checksrc
lib/vssh/.checksrc
lib/vtls/.checksrc
scripts/checksrc.pl
src/.checksrc
tests/libtest/cli_hx_download.c
tests/libtest/cli_hx_upload.c
tests/libtest/cli_ws_data.c
tests/libtest/first.c
tests/libtest/lib1560.c
tests/libtest/lib1568.c
tests/libtest/lib521.c
tests/libtest/lib562.c
tests/libtest/lib591.c
tests/server/.checksrc
tests/server/dnsd.c
tests/server/first.h
tests/server/mqttd.c
tests/server/rtspd.c
tests/server/sockfilt.c
tests/server/socksd.c
tests/server/sws.c
tests/server/tftpd.c
tests/server/util.c

index 259058cad5808c9bedf422d9cad6114a254aedec..a83f0edb9f804a601ceb630ca14b5e1b1e8f5395 100644 (file)
@@ -4,4 +4,14 @@ allowfunc fopen
 allowfunc gmtime
 allowfunc localtime
 allowfunc open
+allowfunc snprintf
 allowfunc socket
+allowfunc sscanf
+banfunc curl_maprintf
+banfunc curl_mfprintf
+banfunc curl_mprintf
+banfunc curl_msnprintf
+banfunc curl_mvaprintf
+banfunc curl_mvfprintf
+banfunc curl_mvprintf
+banfunc curl_mvsnprintf
index acec3b93854b0b0e6e9ffa6ea53aacb9cc239514..bb6e42971b7673db0c5e12c5314d68e3f4d25ed4 100644 (file)
@@ -132,6 +132,7 @@ check_PROGRAMS = \
   smtp-tls \
   smtp-vrfy \
   sslbackend \
+  synctime \
   unixsocket \
   url2file \
   urlapi \
@@ -155,7 +156,6 @@ COMPLICATED_EXAMPLES = \
   multithread.c \
   sessioninfo.c \
   smooth-gtk-thread.c \
-  synctime.c \
   threaded-ssl.c \
   usercertinmem.c \
   version-check.pl \
index 264c514ba4c777f4ba56b22e73716eae56201039..32bd92005d5bb09ec21b6ca8b59137074f544372 100644 (file)
@@ -100,7 +100,7 @@ int main(int argc, char *argv[])
         case 'm':
         case 'M':
           if(argv[0][2] == '=') {
-            long m = strtol((*argv) + 3, NULL, 10);
+            int m = atoi((*argv) + 3);
             switch(m) {
             case 1:
               url = URL_1M;
index da40953d918a1b164789d9b4dfeee52bd782468e..113429bbda03a8ac44c77137f29444a501dab72e 100644 (file)
 #include <curl/curl.h>
 #include <curl/mprintf.h>
 
+#if defined(_MSC_VER) && (_MSC_VER < 1900)
+#define snprintf _snprintf
+#endif
+
 static int print_cookies(CURL *curl)
 {
   CURLcode res;
@@ -93,10 +97,10 @@ main(void)
     printf("-----------------------------------------------\n"
            "Setting a cookie \"PREF\" via cookie interface:\n");
     /* Netscape format cookie */
-    curl_msnprintf(nline, sizeof(nline), "%s\t%s\t%s\t%s\t%.0f\t%s\t%s",
-                   ".example.com", "TRUE", "/", "FALSE",
-                   difftime(time(NULL) + 31337, (time_t)0),
-                   "PREF", "hello example, i like you!");
+    snprintf(nline, sizeof(nline), "%s\t%s\t%s\t%s\t%.0f\t%s\t%s",
+             ".example.com", "TRUE", "/", "FALSE",
+             difftime(time(NULL) + 31337, (time_t)0),
+             "PREF", "hello example, I like you!");
     res = curl_easy_setopt(curl, CURLOPT_COOKIELIST, nline);
     if(res != CURLE_OK) {
       fprintf(stderr, "Curl curl_easy_setopt failed: %s\n",
@@ -109,7 +113,7 @@ main(void)
        modified, likely not what you intended. For more information refer to
        the CURLOPT_COOKIELIST documentation.
     */
-    curl_msnprintf(nline, sizeof(nline),
+    snprintf(nline, sizeof(nline),
       "Set-Cookie: OLD_PREF=3d141414bf4209321; "
       "expires=Sun, 17-Jan-2038 19:14:07 GMT; path=/; domain=.example.com");
     res = curl_easy_setopt(curl, CURLOPT_COOKIELIST, nline);
index 954cdcbc6d94a71d67560acd1be469117bdda36a..68c4f456295b83d16fc3eb938fad6943d76cc6cc 100644 (file)
 #include <curl/curl.h>
 #include <curl/mprintf.h>
 
+#if defined(_MSC_VER) && (_MSC_VER < 1900)
+#define snprintf _snprintf
+#endif
+
 #ifndef CURLPIPE_MULTIPLEX
 /* This little trick makes sure that we do not enable pipelining for libcurls
    old enough to not have this symbol. It is _not_ defined to zero in a recent
@@ -149,7 +153,7 @@ static int setup(struct transfer *t, int num)
 
   hnd = t->easy = curl_easy_init();
 
-  curl_msnprintf(filename, 128, "dl-%d", num);
+  snprintf(filename, sizeof(filename), "dl-%d", num);
 
   t->out = fopen(filename, "wb");
   if(!t->out) {
index df4e49ea588719f3f8845bd2df9b74d684445251..734d35beb79cd7d000e4dc3ec381b1cb40a2bd9c 100644 (file)
 #include <curl/curl.h>
 #include <curl/mprintf.h>
 
+#if defined(_MSC_VER) && (_MSC_VER < 1900)
+#define snprintf _snprintf
+#endif
+
 #ifndef CURLPIPE_MULTIPLEX
 #error "too old libcurl, cannot do HTTP/2 server push!"
 #endif
@@ -173,7 +177,7 @@ static int server_push_callback(CURL *parent,
 
   (void)parent;
 
-  curl_msnprintf(filename, 128, "push%u", count++);
+  snprintf(filename, sizeof(filename), "push%u", count++);
 
   /* here's a new stream, save it in a new file for each new push */
   out = fopen(filename, "wb");
index b08e8fc102eb2d19197f427762d7a58085ebc124..dc474cc54951905cd43df12a93f58e8ab9641186 100644 (file)
@@ -40,6 +40,8 @@
 #ifndef _MSC_VER
 #include <sys/time.h>
 #include <unistd.h>
+#elif (_MSC_VER < 1900)
+#define snprintf _snprintf
 #endif
 
 #ifdef _WIN32
@@ -162,8 +164,8 @@ int my_trace(CURL *handle, curl_infotype type,
   }
   secs = epoch_offset + tv.tv_sec;
   now = localtime(&secs);  /* not thread safe but we do not care */
-  curl_msnprintf(timebuf, sizeof(timebuf), "%02d:%02d:%02d.%06ld",
-                 now->tm_hour, now->tm_min, now->tm_sec, (long)tv.tv_usec);
+  snprintf(timebuf, sizeof(timebuf), "%02d:%02d:%02d.%06ld",
+           now->tm_hour, now->tm_min, now->tm_sec, (long)tv.tv_usec);
 
   switch(type) {
   case CURLINFO_TEXT:
@@ -215,7 +217,7 @@ static int setup(struct input *i, int num, const char *upload)
   hnd = i->hnd = NULL;
 
   i->num = num;
-  curl_msnprintf(filename, 128, "dl-%d", num);
+  snprintf(filename, sizeof(filename), "dl-%d", num);
   out = fopen(filename, "wb");
   if(!out) {
     fprintf(stderr, "error: could not open file %s for writing: %s\n", upload,
@@ -223,7 +225,7 @@ static int setup(struct input *i, int num, const char *upload)
     return 1;
   }
 
-  curl_msnprintf(url, 256, "https://localhost:8443/upload-%d", num);
+  snprintf(url, sizeof(url), "https://localhost:8443/upload-%d", num);
 
   i->in = fopen(upload, "rb");
   if(!i->in) {
index 8d7af7c8c4c33d4285d232eb7c92482072663345..dd21082446a7164bb9bdb33dcf06741168c356de 100644 (file)
  */
 
 #include <stdio.h>
-#include <time.h>
-#include <curl/curl.h>
 
-#ifdef _WIN32
-#include <windows.h>
+#ifndef _WIN32
+int main(void) { printf("Platform not supported.\n"); return 1; }
 #else
-#error "This example requires Windows."
+
+#if (defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0602)) || \
+   defined(WINAPI_FAMILY)
+#  include <winapifamily.h>
+#  if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) &&  \
+     !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
+#    define CURL_WINDOWS_UWP
+#  endif
 #endif
 
+#ifdef CURL_WINDOWS_UWP
+int main(void) { printf("Platform not supported.\n"); return 1; }
+#else
+
+#include <windows.h>
+#include <time.h>
+
+#include <curl/curl.h>
+
+#if defined(_MSC_VER) && (_MSC_VER < 1900)
+#define snprintf _snprintf
+#endif
 
 #define MAX_STRING              256
 #define MAX_STRING1             MAX_STRING + 1
@@ -139,7 +156,7 @@ static size_t SyncTime_CURL_WriteHeader(void *ptr, size_t size, size_t nmemb,
       *TmpStr1 = 0;
       *TmpStr2 = 0;
       if(strlen((char *)(ptr)) > 50) /* Can prevent buffer overflow to
-                                         TmpStr1 & 2? */
+                                        TmpStr1 & 2? */
         AutoSyncTime = 0;
       else {
         int RetVal = sscanf((char *)(ptr), "Date: %25s %hu %s %hu %hu:%hu:%hu",
@@ -305,7 +322,7 @@ int main(int argc, char *argv[])
     tzonediffFloat = difftime(tt_local, tt_gmt);
     tzonediffWord  = (int)(tzonediffFloat/3600.0);
 
-    if((double)(tzonediffWord * 3600) == tzonediffFloat)
+    if(tzonediffWord == (int)(tzonediffFloat/3600.0))
       snprintf(tzoneBuf, sizeof(tzoneBuf), "%+03d'00'", tzonediffWord);
     else
       snprintf(tzoneBuf, sizeof(tzoneBuf), "%+03d'30'", tzonediffWord);
@@ -358,3 +375,5 @@ int main(int argc, char *argv[])
   }
   return RetValue;
 }
+#endif /* CURL_WINDOWS_UWP */
+#endif /* _WIN32 */
index aef5103fed6ffca53dc21c40e17fd8ee6a605052..0d072c04c306dca4ad096c88728190d510cb9603 100644 (file)
@@ -362,6 +362,6 @@ This is the full list of functions generally banned.
     strtok_r
     strtol
     strtoul
-    vsnprint
+    vsnprintf
     vsprintf
     wcsdup
index 22ca8e0b53702d3b36b57427046caefc5892e81e..9b8d799ea2852ed5bc2c54429bfcb07490e164f4 100644 (file)
@@ -1,5 +1 @@
-banfunc snprintf
-banfunc sscanf
 banfunc strerror
-banfunc strtol
-banfunc vsnprint
index 22ca8e0b53702d3b36b57427046caefc5892e81e..9b8d799ea2852ed5bc2c54429bfcb07490e164f4 100644 (file)
@@ -1,5 +1 @@
-banfunc snprintf
-banfunc sscanf
 banfunc strerror
-banfunc strtol
-banfunc vsnprint
index 22ca8e0b53702d3b36b57427046caefc5892e81e..9b8d799ea2852ed5bc2c54429bfcb07490e164f4 100644 (file)
@@ -1,5 +1 @@
-banfunc snprintf
-banfunc sscanf
 banfunc strerror
-banfunc strtol
-banfunc vsnprint
index 22ca8e0b53702d3b36b57427046caefc5892e81e..9b8d799ea2852ed5bc2c54429bfcb07490e164f4 100644 (file)
@@ -1,5 +1 @@
-banfunc snprintf
-banfunc sscanf
 banfunc strerror
-banfunc strtol
-banfunc vsnprint
index 22ca8e0b53702d3b36b57427046caefc5892e81e..9b8d799ea2852ed5bc2c54429bfcb07490e164f4 100644 (file)
@@ -1,5 +1 @@
-banfunc snprintf
-banfunc sscanf
 banfunc strerror
-banfunc strtol
-banfunc vsnprint
index 22ca8e0b53702d3b36b57427046caefc5892e81e..9b8d799ea2852ed5bc2c54429bfcb07490e164f4 100644 (file)
@@ -1,5 +1 @@
-banfunc snprintf
-banfunc sscanf
 banfunc strerror
-banfunc strtol
-banfunc vsnprint
index af705d10c4dbfb72b1601d734661c40a5683d988..637c0b7c8b5d11c0cc625376e77fb2195f2537fe 100755 (executable)
@@ -53,11 +53,15 @@ my %banfunc = (
     "gets" => 1,
     "strtok" => 1,
     "sprintf" => 1,
+    "snprintf" => 1,
     "vsprintf" => 1,
+    "vsnprintf" => 1,
+    "sscanf" => 1,
     "strcat" => 1,
     "strncat" => 1,
     "strncpy" => 1,
     "strtok_r" => 1,
+    "strtol" => 1,
     "strtoul" => 1,
     "_mbscat" => 1,
     "_mbsncat" => 1,
index 7b71afb23689b17583825311cc38973f6d0fa67d..946367c4999f6f2961afc23db1d2bfb4211b2443 100644 (file)
@@ -1,5 +1 @@
 enable STDERR
-banfunc snprintf
-banfunc sscanf
-banfunc strtol
-banfunc vsnprint
index 7a6a48c171b5393b712d38dfd755b6470b2c2d55..5ab4db024c5854f52b01827598481c732a7058ff 100644 (file)
@@ -317,32 +317,32 @@ static CURLcode test_cli_hx_download(const char *URL)
       forbid_reuse_d = 1;
       break;
     case 'm':
-      max_parallel = (size_t)strtol(coptarg, NULL, 10);
+      max_parallel = (size_t)atol(coptarg);
       break;
     case 'n':
-      transfer_count_d = (size_t)strtol(coptarg, NULL, 10);
+      transfer_count_d = (size_t)atol(coptarg);
       break;
     case 'x':
       fresh_connect = 1;
       break;
     case 'A':
-      abort_offset = (size_t)strtol(coptarg, NULL, 10);
+      abort_offset = (size_t)atol(coptarg);
       break;
     case 'F':
-      fail_offset = (size_t)strtol(coptarg, NULL, 10);
+      fail_offset = (size_t)atol(coptarg);
       break;
     case 'M':
-      max_host_conns = (size_t)strtol(coptarg, NULL, 10);
+      max_host_conns = (size_t)atol(coptarg);
       break;
     case 'P':
-      pause_offset = (size_t)strtol(coptarg, NULL, 10);
+      pause_offset = (size_t)atol(coptarg);
       break;
     case 'r':
       free(resolve);
       resolve = strdup(coptarg);
       break;
     case 'T':
-      max_total_conns = (size_t)strtol(coptarg, NULL, 10);
+      max_total_conns = (size_t)atol(coptarg);
       break;
     case 'V': {
       if(!strcmp("http/1.1", coptarg))
index 40e486c41a1a69304561978bb346d1d18bbb391f..a0a6b95db84782b3f8f0ab70d0aee6cf57bba2dc 100644 (file)
@@ -257,22 +257,22 @@ static CURLcode test_cli_hx_upload(const char *URL)
       announce_length = 1;
       break;
     case 'm':
-      max_parallel = (size_t)strtol(coptarg, NULL, 10);
+      max_parallel = (size_t)atol(coptarg);
       break;
     case 'n':
-      transfer_count_u = (size_t)strtol(coptarg, NULL, 10);
+      transfer_count_u = (size_t)atol(coptarg);
       break;
     case 'A':
-      abort_offset = (size_t)strtol(coptarg, NULL, 10);
+      abort_offset = (size_t)atol(coptarg);
       break;
     case 'F':
-      fail_offset = (size_t)strtol(coptarg, NULL, 10);
+      fail_offset = (size_t)atol(coptarg);
       break;
     case 'M':
       method = coptarg;
       break;
     case 'P':
-      pause_offset = (size_t)strtol(coptarg, NULL, 10);
+      pause_offset = (size_t)atol(coptarg);
       break;
     case 'r':
       resolve = coptarg;
@@ -281,7 +281,7 @@ static CURLcode test_cli_hx_upload(const char *URL)
       reuse_easy = 1;
       break;
     case 'S':
-      send_total = (size_t)strtol(coptarg, NULL, 10);
+      send_total = (size_t)atol(coptarg);
       break;
     case 'V': {
       if(!strcmp("http/1.1", coptarg))
index 32356552a80761cc5ccfaa2d4df893d34b4cabd4..26cecc19fea38043ebddde6e0feef9d579d9a6eb 100644 (file)
@@ -431,13 +431,13 @@ static CURLcode test_cli_ws_data(const char *URL)
       res = CURLE_BAD_FUNCTION_ARGUMENT;
       goto cleanup;
     case 'c':
-      count = (size_t)strtol(coptarg, NULL, 10);
+      count = (size_t)atol(coptarg);
       break;
     case 'm':
-      plen_min = (size_t)strtol(coptarg, NULL, 10);
+      plen_min = (size_t)atol(coptarg);
       break;
     case 'M':
-      plen_max = (size_t)strtol(coptarg, NULL, 10);
+      plen_max = (size_t)atol(coptarg);
       break;
     default:
       test_ws_data_usage("invalid option");
index 49ec8a5f91b49624f3a27b2adfb6de31aec98020..79baca331ea9661ccceb31013f5c8a20c725e0ef 100644 (file)
@@ -137,9 +137,8 @@ static void memory_tracking_init(void)
   /* if CURL_MEMLIMIT is set, this enables fail-on-alloc-number-N feature */
   env = getenv("CURL_MEMLIMIT");
   if(env) {
-    char *endptr;
-    long num = strtol(env, &endptr, 10);
-    if((endptr != env) && (endptr == env + strlen(env)) && (num > 0))
+    long num = atol(env);
+    if(num > 0)
       curl_dbg_memlimit(num);
   }
 }
index 1973d8a916e9b474588d77843c391104345348fa..0071bb0f8b8f4c6f66d0681970acf4bf15e83c87 100644 (file)
@@ -1198,6 +1198,7 @@ static CURLUcode updateurl(CURLU *u, const char *cmd, unsigned int setflags)
       memset(value, 0, sizeof(value)); /* Avoid valgrind false positive. */
       memcpy(buf, p, n);
       buf[n] = 0;
+      /* !checksrc! disable BANNEDFUNC 1 */
       if(sscanf(buf, "%79[^=]=%79[^,]", part, value) == 2) {
         CURLUPart what = part2id(part);
 #if 0
index a2451486fd41715ce163d8699dc67f6a61568588..695badc85ce238c7a958fd9338769dc204973f01 100644 (file)
@@ -39,7 +39,7 @@ static CURLcode test_lib1568(const char *URL)
   curl_easy_setopt(hnd, CURLOPT_USERAGENT, "lib1568");
   curl_easy_setopt(hnd, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
   curl_easy_setopt(hnd, CURLOPT_MAXREDIRS, 50L);
-  curl_easy_setopt(hnd, CURLOPT_PORT, strtol(libtest_arg2, NULL, 10));
+  curl_easy_setopt(hnd, CURLOPT_PORT, atol(libtest_arg2));
 
   ret = curl_easy_perform(hnd);
 
index 32bf7b3022a2aacbda35571957535cc1254beed4..c02c45a3c103cccfd067af253b95c60b7c556df4 100644 (file)
@@ -43,7 +43,7 @@ static CURLcode test_lib521(const char *URL)
   }
 
   test_setopt(curl, CURLOPT_URL, URL);
-  test_setopt(curl, CURLOPT_PORT, strtol(libtest_arg2, NULL, 10));
+  test_setopt(curl, CURLOPT_PORT, atol(libtest_arg2));
   test_setopt(curl, CURLOPT_USERPWD, "xxx:yyy");
   test_setopt(curl, CURLOPT_VERBOSE, 1L);
 
index 016dffe1bda1aaf0d3cbf852955bbbee3dba033b..1c3bf8cff8371d41192208c078c30360535b7ce1 100644 (file)
@@ -55,7 +55,7 @@ static CURLcode test_lib562(const char *URL)
   test_setopt(curl, CURLOPT_VERBOSE, 1L);
 
   /* set port number */
-  test_setopt(curl, CURLOPT_PORT, strtol(libtest_arg2, NULL, 10));
+  test_setopt(curl, CURLOPT_PORT, atol(libtest_arg2));
 
   /* specify target */
   test_setopt(curl, CURLOPT_URL, URL);
index 77a038c7c3204ec9abdc0ae83a0f0802d4e9d4d9..c85c42b0c228e8e93640218c703eebb3cdef5892 100644 (file)
@@ -71,8 +71,7 @@ static CURLcode test_lib591(const char *URL)
   easy_setopt(easy, CURLOPT_FTPPORT, "-");
 
   /* server connection timeout */
-  easy_setopt(easy, CURLOPT_ACCEPTTIMEOUT_MS,
-              strtol(libtest_arg2, NULL, 10)*1000);
+  easy_setopt(easy, CURLOPT_ACCEPTTIMEOUT_MS, atol(libtest_arg2)*1000);
 
   multi_init(multi);
 
index 29331433c2cb8fda080057d4bfbc04a33636992e..d6506e14020acad2ef077bf32e30b3e3d5b6b3cb 100644 (file)
@@ -6,5 +6,7 @@ allowfunc getaddrinfo
 allowfunc open
 allowfunc recv
 allowfunc send
+allowfunc snprintf
 allowfunc socket
-allowfunc strtoul
+allowfunc sscanf
+allowfunc vsnprintf
index dc49723da313a9b22c54df0ba56c3154318f7f9a..2d0ce35e6f40260a084a4e79c61bf25b6ddb6401 100644 (file)
@@ -441,9 +441,7 @@ static int test_dnsd(int argc, char **argv)
     else if(!strcmp("--port", argv[arg])) {
       arg++;
       if(argc > arg) {
-        char *endptr;
-        unsigned long ulnum = strtoul(argv[arg], &endptr, 10);
-        port = util_ultous(ulnum);
+        port = (unsigned short)atoi(argv[arg]);
         arg++;
       }
     }
index 44dd272ce2b35f49aa73c5d14ed8d095e3be7233..4d3ae61de7edaaab79a13fd53cda7163c234cdcd 100644 (file)
@@ -148,7 +148,6 @@ extern void restore_signal_handlers(bool keep_sigalrm);
 extern int bind_unix_socket(curl_socket_t sock, const char *unix_socket,
                             struct sockaddr_un *sau);
 #endif
-extern unsigned short util_ultous(unsigned long ulnum);
 extern curl_socket_t sockdaemon(curl_socket_t sock,
                                 unsigned short *listenport,
                                 const char *unix_socket,
index 7f5abf1b5d6e6bb9501fa2a913aaa294f9eedcc0..9414eef504f12965ffcb7b35a007219c08a486a3 100644 (file)
@@ -782,15 +782,13 @@ static int test_mqttd(int argc, char *argv[])
     else if(!strcmp("--port", argv[arg])) {
       arg++;
       if(argc > arg) {
-        char *endptr;
-        unsigned long ulnum = strtoul(argv[arg], &endptr, 10);
-        if((endptr != argv[arg] + strlen(argv[arg])) ||
-           ((ulnum != 0UL) && ((ulnum < 1025UL) || (ulnum > 65535UL)))) {
+        int inum = atoi(argv[arg]);
+        if(inum && ((inum < 1025) || (inum > 65535))) {
           fprintf(stderr, "mqttd: invalid --port argument (%s)\n",
                   argv[arg]);
           return 0;
         }
-        server_port = util_ultous(ulnum);
+        server_port = (unsigned short)inum;
         arg++;
       }
     }
index 67829922dc92b74a1b8983fbc08f20a27bb14227..0a4f9159c054aab9424ecdaefc0378cf498a439b 100644 (file)
@@ -211,7 +211,7 @@ static int rtspd_ProcessRequest(struct rtspd_httprequest *req)
       while(*ptr && !ISDIGIT(*ptr))
         ptr++;
 
-      req->testno = strtol(ptr, &ptr, 10);
+      req->testno = atol(ptr);
 
       if(req->testno > 10000) {
         req->partno = req->testno % 10000;
@@ -358,7 +358,7 @@ static int rtspd_ProcessRequest(struct rtspd_httprequest *req)
              CONNECT line will be used as test number! */
           char *portp = strchr(doc, ':');
           if(portp && (*(portp + 1) != '\0') && ISDIGIT(*(portp + 1)))
-            req->testno = strtol(portp + 1, NULL, 10);
+            req->testno = atol(portp + 1);
           else
             req->testno = DOCNUMBER_CONNECT;
         }
@@ -1045,9 +1045,7 @@ static int test_rtspd(int argc, char *argv[])
     else if(!strcmp("--port", argv[arg])) {
       arg++;
       if(argc > arg) {
-        char *endptr;
-        unsigned long ulnum = strtoul(argv[arg], &endptr, 10);
-        port = util_ultous(ulnum);
+        port = (unsigned short)atol(argv[arg]);
         arg++;
       }
     }
index a52efe0a1bf6aa64b25fca3c813710b840289a8d..c6536fee4a31d13e1670a2acdd30fc15b400dfd4 100644 (file)
@@ -376,6 +376,7 @@ static bool read_data_block(unsigned char *buffer, ssize_t maxlen,
 
   buffer[5] = '\0';
 
+  /* !checksrc! disable BANNEDFUNC 1 */
   *buffer_len = (ssize_t)strtol((char *)buffer, NULL, 16);
   if(*buffer_len > maxlen) {
     logmsg("Buffer size (%zd bytes) too small for data size error "
@@ -1278,9 +1279,7 @@ static int test_sockfilt(int argc, char *argv[])
     else if(!strcmp("--port", argv[arg])) {
       arg++;
       if(argc > arg) {
-        char *endptr;
-        unsigned long ulnum = strtoul(argv[arg], &endptr, 10);
-        server_port = util_ultous(ulnum);
+        server_port = (unsigned short)atol(argv[arg]);
         arg++;
       }
     }
@@ -1289,15 +1288,13 @@ static int test_sockfilt(int argc, char *argv[])
          doing a passive server-style listening. */
       arg++;
       if(argc > arg) {
-        char *endptr;
-        unsigned long ulnum = strtoul(argv[arg], &endptr, 10);
-        if((endptr != argv[arg] + strlen(argv[arg])) ||
-           (ulnum < 1025UL) || (ulnum > 65535UL)) {
+        int inum = atoi(argv[arg]);
+        if(inum && ((inum < 1025) || (inum > 65535))) {
           fprintf(stderr, "sockfilt: invalid --connect argument (%s)\n",
                   argv[arg]);
           return 0;
         }
-        server_connectport = util_ultous(ulnum);
+        server_connectport = (unsigned short)inum;
         arg++;
       }
     }
index 4d599e16b61a5ad80205fe83ec42c35d484765ba..06283e0424037545cf79437f67c5358cdff8de16 100644 (file)
@@ -108,7 +108,7 @@ static void socksd_resetdefaults(void)
 
 static unsigned short shortval(char *value)
 {
-  unsigned long num = strtoul(value, NULL, 10);
+  unsigned long num = (unsigned long)atol(value);
   return num & 0xffff;
 }
 
@@ -831,9 +831,7 @@ static int test_socksd(int argc, char *argv[])
     else if(!strcmp("--port", argv[arg])) {
       arg++;
       if(argc > arg) {
-        char *endptr;
-        unsigned long ulnum = strtoul(argv[arg], &endptr, 10);
-        server_port = util_ultous(ulnum);
+        server_port = (unsigned short)atol(argv[arg]);
         arg++;
       }
     }
index a512a7a31e2610cd2268a467856b0f67ebfa1f12..20d2bf763261383b4eb234234693a3a4fe0579e9 100644 (file)
@@ -389,7 +389,7 @@ static int sws_ProcessRequest(struct sws_httprequest *req)
 
         ptr++; /* skip the slash */
 
-        req->testno = strtol(ptr, &ptr, 10);
+        req->testno = atol(ptr);
 
         if(req->testno > 10000) {
           req->partno = req->testno % 10000;
@@ -430,6 +430,7 @@ static int sws_ProcessRequest(struct sws_httprequest *req)
                in the 'part' variable and use as test case number!! */
             while(*p && (ISXDIGIT(*p) || (*p == ':') || (*p == '.'))) {
               char *endp;
+              /* !checksrc! disable BANNEDFUNC 1 */
               part = strtoul(p, &endp, 16);
               if(ISXDIGIT(*p))
                 p = endp;
@@ -449,11 +450,11 @@ static int sws_ProcessRequest(struct sws_httprequest *req)
             portp = strchr(doc, ':');
 
           if(portp && (*(portp + 1) != '\0') && ISDIGIT(*(portp + 1))) {
-            unsigned long ulnum = strtoul(portp + 1, NULL, 10);
-            if(!ulnum || (ulnum > 65535UL))
+            int inum = atoi(portp + 1);
+            if((inum <= 0) || (inum > 65535))
               logmsg("Invalid CONNECT port received");
             else
-              req->connect_port = util_ultous(ulnum);
+              req->connect_port = (unsigned short)inum;
 
           }
           logmsg("Port number: %d, test case number: %ld",
@@ -490,7 +491,7 @@ static int sws_ProcessRequest(struct sws_httprequest *req)
     /* check for a Testno: header with the test case number */
     char *testno = strstr(line, "\nTestno: ");
     if(testno) {
-      req->testno = strtol(&testno[9], NULL, 10);
+      req->testno = atol(&testno[9]);
       logmsg("Found test number %ld in Testno: header!", req->testno);
     }
     else {
@@ -516,7 +517,7 @@ static int sws_ProcessRequest(struct sws_httprequest *req)
       while(*ptr && !ISDIGIT(*ptr))
         ptr++;
 
-      req->testno = strtol(ptr, &ptr, 10);
+      req->testno = atol(ptr);
 
       if(req->testno > 10000) {
         req->partno = req->testno % 10000;
@@ -2071,15 +2072,13 @@ static int test_sws(int argc, char *argv[])
     else if(!strcmp("--port", argv[arg])) {
       arg++;
       if(argc > arg) {
-        char *endptr;
-        unsigned long ulnum = strtoul(argv[arg], &endptr, 10);
-        if((endptr != argv[arg] + strlen(argv[arg])) ||
-           (ulnum && ((ulnum < 1025UL) || (ulnum > 65535UL)))) {
+        int inum = atoi(argv[arg]);
+        if(inum && ((inum < 1025) || (inum > 65535))) {
           fprintf(stderr, "sws: invalid --port argument (%s)\n",
                   argv[arg]);
           return 0;
         }
-        port = util_ultous(ulnum);
+        port = (unsigned short)inum;
         arg++;
       }
     }
@@ -2093,15 +2092,13 @@ static int test_sws(int argc, char *argv[])
     else if(!strcmp("--keepalive", argv[arg])) {
       arg++;
       if(argc > arg) {
-        char *endptr;
-        unsigned long ulnum = strtoul(argv[arg], &endptr, 10);
-        if((endptr != argv[arg] + strlen(argv[arg])) ||
-           (ulnum && (ulnum > 65535UL))) {
+        int inum = atoi(argv[arg]);
+        if(inum && (inum > 65535)) {
           fprintf(stderr, "sws: invalid --keepalive argument (%s), must "
                   "be number of seconds\n", argv[arg]);
           return 0;
         }
-        keepalive_secs = util_ultous(ulnum);
+        keepalive_secs = (unsigned short)inum;
         arg++;
       }
     }
index 193afac1377e6b598846bc1c0261c0ed8d0892c5..4c37685ab71617c9de735405535ebff107122ed9 100644 (file)
@@ -607,9 +607,7 @@ static int test_tftpd(int argc, char **argv)
     else if(!strcmp("--port", argv[arg])) {
       arg++;
       if(argc > arg) {
-        char *endptr;
-        unsigned long ulnum = strtoul(argv[arg], &endptr, 10);
-        port = util_ultous(ulnum);
+        port = (unsigned short)atol(argv[arg]);
         arg++;
       }
     }
@@ -1100,7 +1098,7 @@ static int validate_access(struct testcase *test,
       ptr++;
 
     /* get the number */
-    testno = strtol(ptr, &ptr, 10);
+    testno = atol(ptr);
 
     if(testno > 10000) {
       partno = testno % 10000;
index 749e33003c29b7009e4eae57da6fd6ca42794c85..f4802745c8d658f8f62d0a358c496473da474c87 100644 (file)
@@ -133,7 +133,7 @@ void logmsg(const char *msg, ...)
 
 unsigned char byteval(char *value)
 {
-  unsigned long num = strtoul(value, NULL, 10);
+  unsigned int num = (unsigned int)atoi(value);
   return num & 0xff;
 }
 
@@ -748,27 +748,6 @@ int bind_unix_socket(curl_socket_t sock, const char *unix_socket,
 }
 #endif
 
-/*
-** unsigned long to unsigned short
-*/
-#define CURL_MASK_USHORT  ((unsigned short)~0)
-#define CURL_MASK_SSHORT  (CURL_MASK_USHORT >> 1)
-
-unsigned short util_ultous(unsigned long ulnum)
-{
-#ifdef __INTEL_COMPILER
-#  pragma warning(push)
-#  pragma warning(disable:810) /* conversion may lose significant bits */
-#endif
-
-  DEBUGASSERT(ulnum <= (unsigned long) CURL_MASK_USHORT);
-  return (unsigned short)(ulnum & (unsigned long) CURL_MASK_USHORT);
-
-#ifdef __INTEL_COMPILER
-#  pragma warning(pop)
-#endif
-}
-
 curl_socket_t sockdaemon(curl_socket_t sock,
                          unsigned short *listenport,
                          const char *unix_socket,