]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
build: make `CURL_FORMAT_CURL_OFF_T[U]` work with mingw-w64 <=7.0.0
authorViktor Szakats <commit@vsz.me>
Wed, 21 Aug 2024 22:21:51 +0000 (00:21 +0200)
committerViktor Szakats <commit@vsz.me>
Thu, 22 Aug 2024 08:45:04 +0000 (10:45 +0200)
Add tweak for mingw-w64 when building tests/http/client programs to
avoid a bogus `-Wformat` warning when using mingw-w64 v7.0.0 or older.
The warning is bogus because these programs use curl's `printf()`
implementation that is guaranteed to support that format spec.

Add this for both CMake and autotools. (But only CMake is CI tested with
an old toolchain.)

Apply the workaround to `docs/examples`, and fix an example to use
curl's `printf()` with `CURL_FORMAT_CURL_OFF_T`.

Reintroduce curl `printf()` calls into `tests/http/client`, via #14625.
Also restore large number masks to a printf, changed earlier in #14382.

Follow-up to 232302f88a152a1d1722da9f69c383a766528918 #14382
Ref: https://github.com/curl/curl/pull/14625#issuecomment-2302361737

Closes #14640

12 files changed:
configure.ac
docs/examples/CMakeLists.txt
docs/examples/Makefile.am
docs/examples/ftpgetinfo.c
tests/http/clients/CMakeLists.txt
tests/http/clients/Makefile.am
tests/http/clients/h2-download.c
tests/http/clients/h2-pausing.c
tests/http/clients/h2-serverpush.c
tests/http/clients/h2-upgrade-extreme.c
tests/http/clients/tls-session-reuse.c
tests/http/clients/upload-pausing.c

index a6fe3e955e2e6799b7b5fb90a02c2b77dd47a271..9d494292d1c8ce530f03b275a4dff60fe96b60ce 100644 (file)
@@ -607,6 +607,16 @@ case $host_os in
     ;;
 esac
 
+have_mingw='no'
+case $host_os in
+  mingw*)
+    have_mingw='yes'
+    ;;
+esac
+
+AM_CONDITIONAL([HAVE_MINGW],
+  [test "$curl_cv_native_windows" = 'yes' -a "$have_mingw" = 'yes'])
+
 AM_CONDITIONAL([HAVE_WINDRES],
   [test "$curl_cv_native_windows" = "yes" && test -n "${RC}"])
 
index 16cda1714cac03731750caec88db00b881c97b7a..2dc92f3f255afdd88d2d11c8f851eab12f90245e 100644 (file)
@@ -34,6 +34,10 @@ foreach(_example IN LISTS check_PROGRAMS)
   if(LIB_SELECTED STREQUAL LIB_STATIC AND WIN32)
     set_property(TARGET ${_example_target} APPEND PROPERTY COMPILE_DEFINITIONS "CURL_STATICLIB")
   endif()
+  if(MINGW)
+    # For mingw-w64 7.0.0 and earlier to avoid '-Wformat='
+    set_property(TARGET ${_example_target} APPEND PROPERTY COMPILE_DEFINITIONS "__USE_MINGW_ANSI_STDIO=1")
+  endif()
   set_target_properties(${_example_target} PROPERTIES
     OUTPUT_NAME "${_example}" UNITY_BUILD OFF)
 endforeach()
index 3cccbdda8956f6f60ea649563288cd0380db700a..cfe4ec0ba2f53a5118c68cfe26cd68e56ad3e579 100644 (file)
@@ -46,6 +46,11 @@ if USE_CPPFLAG_CURL_STATICLIB
 AM_CPPFLAGS += -DCURL_STATICLIB
 endif
 
+if HAVE_MINGW
+# For mingw-w64 7.0.0 and earlier to avoid '-Wformat='
+AM_CPPFLAGS += -D__USE_MINGW_ANSI_STDIO=1
+endif
+
 # Prevent LIBS from being used for all link targets
 LIBS = $(BLANK_AT_MAKETIME)
 
index be24fa71ef303fea848f4a6e4fd51764e8bcad99..f1a3cefd629d12c9be0dc34abd6594ed16592146 100644 (file)
@@ -75,8 +75,8 @@ int main(void)
       res = curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD_T,
                               &filesize);
       if((CURLE_OK == res) && (filesize>0))
-        printf("filesize %s: %" CURL_FORMAT_CURL_OFF_T " bytes\n",
-               filename, filesize);
+        curl_mprintf("filesize %s: %" CURL_FORMAT_CURL_OFF_T " bytes\n",
+                     filename, filesize);
     }
     else {
       /* we failed */
index 974c3404537da7ecf7243080566ba9a142d9d992..0747a1926f30fb5dd9fe8a3a3ca38d1cc0f0a254 100644 (file)
@@ -39,6 +39,10 @@ foreach(_test_name IN LISTS check_PROGRAMS)
   if(LIB_SELECTED STREQUAL LIB_STATIC AND WIN32)
     set_property(TARGET ${_test_target} APPEND PROPERTY COMPILE_DEFINITIONS "CURL_STATICLIB")
   endif()
+  if(MINGW)
+    # For mingw-w64 7.0.0 and earlier to avoid '-Wformat='
+    set_property(TARGET ${_test_target} APPEND PROPERTY COMPILE_DEFINITIONS "__USE_MINGW_ANSI_STDIO=1")
+  endif()
   set_target_properties(${_test_target} PROPERTIES
     OUTPUT_NAME "${_test_name}" UNITY_BUILD OFF
     PROJECT_LABEL "Test client ${_test_target}")
index efe0d9551447137e4f57564e1a2c3113f617e2b5..9650d61a849d30b3215852e02b84bc458c78f049 100644 (file)
@@ -47,6 +47,11 @@ if USE_CPPFLAG_CURL_STATICLIB
 AM_CPPFLAGS += -DCURL_STATICLIB
 endif
 
+if HAVE_MINGW
+# For mingw-w64 7.0.0 and earlier to avoid '-Wformat='
+AM_CPPFLAGS += -D__USE_MINGW_ANSI_STDIO=1
+endif
+
 # Prevent LIBS from being used for all link targets
 LIBS = $(BLANK_AT_MAKETIME)
 
index 29745311cbcc51a082348279540ebaef4ffb2006..505a3864ae3a7a249d526294b65ba453ce3720ee 100644 (file)
 #include <unistd.h>  /* getopt() */
 #endif
 
-#ifdef _MSC_VER
-#define snprintf _snprintf
-#endif
-
 #ifndef CURLPIPE_MULTIPLEX
 #error "too old libcurl, cannot do HTTP/2 server push!"
 #endif
@@ -84,11 +80,12 @@ static int debug_cb(CURL *handle, curl_infotype type,
 
   if(!curl_easy_getinfo(handle, CURLINFO_XFER_ID, &xfer_id) && xfer_id >= 0) {
     if(!curl_easy_getinfo(handle, CURLINFO_CONN_ID, &conn_id) &&
-        conn_id >= 0) {
-      snprintf(idsbuf, sizeof(idsbuf), TRC_IDS_FORMAT_IDS_2, xfer_id, conn_id);
+       conn_id >= 0) {
+      curl_msnprintf(idsbuf, sizeof(idsbuf), TRC_IDS_FORMAT_IDS_2, xfer_id,
+                     conn_id);
     }
     else {
-      snprintf(idsbuf, sizeof(idsbuf), TRC_IDS_FORMAT_IDS_1, xfer_id);
+      curl_msnprintf(idsbuf, sizeof(idsbuf), TRC_IDS_FORMAT_IDS_1, xfer_id);
     }
   }
   else
@@ -184,7 +181,8 @@ static size_t my_write_cb(char *buf, size_t nitems, size_t buflen,
   fprintf(stderr, "[t-%d] RECV %ld bytes, total=%ld, pause_at=%ld\n",
           t->idx, (long)blen, (long)t->recv_size, (long)t->pause_at);
   if(!t->out) {
-    snprintf(t->filename, sizeof(t->filename)-1, "download_%u.data", t->idx);
+    curl_msnprintf(t->filename, sizeof(t->filename)-1, "download_%u.data",
+                   t->idx);
     t->out = fopen(t->filename, "wb");
     if(!t->out)
       return 0;
index dd27b2ff2e0193794e54d3e7add1752d88167bd6..8281f4dedccaad60caea329f526bea17aa3aa5e6 100644 (file)
 #include <unistd.h>  /* getopt() */
 #endif
 
-#ifdef _MSC_VER
-#define snprintf _snprintf
-#endif
-
 #ifndef _MSC_VER
 #define HANDLECOUNT 2
 
@@ -83,10 +79,11 @@ static int debug_cb(CURL *handle, curl_infotype type,
   if(!curl_easy_getinfo(handle, CURLINFO_XFER_ID, &xfer_id) && xfer_id >= 0) {
     if(!curl_easy_getinfo(handle, CURLINFO_CONN_ID, &conn_id) &&
         conn_id >= 0) {
-      snprintf(idsbuf, sizeof(idsbuf), TRC_IDS_FORMAT_IDS_2, xfer_id, conn_id);
+      curl_msnprintf(idsbuf, sizeof(idsbuf), TRC_IDS_FORMAT_IDS_2, xfer_id,
+                     conn_id);
     }
     else {
-      snprintf(idsbuf, sizeof(idsbuf), TRC_IDS_FORMAT_IDS_1, xfer_id);
+      curl_msnprintf(idsbuf, sizeof(idsbuf), TRC_IDS_FORMAT_IDS_1, xfer_id);
     }
   }
   else
@@ -272,7 +269,8 @@ int main(int argc, char *argv[])
     exit(1);
   }
   memset(&resolve, 0, sizeof(resolve));
-  snprintf(resolve_buf, sizeof(resolve_buf)-1, "%s:%s:127.0.0.1", host, port);
+  curl_msnprintf(resolve_buf, sizeof(resolve_buf)-1, "%s:%s:127.0.0.1",
+                 host, port);
   resolve = curl_slist_append(resolve, resolve_buf);
 
   for(i = 0; i<HANDLECOUNT; i++) {
index 0055add615a28817775854b6fae69b7294636fa3..9f54d6acdb9781df6f21b5d2d55a0bc88d7232f2 100644 (file)
 #error "too old libcurl, cannot do HTTP/2 server push!"
 #endif
 
-#ifdef _MSC_VER
-#define snprintf _snprintf
-#endif
-
 static
 void dump(const char *text, unsigned char *ptr, size_t size,
           char nohex)
@@ -170,7 +166,7 @@ static int server_push_callback(CURL *parent,
   int rv;
 
   (void)parent; /* we have no use for this */
-  snprintf(filename, sizeof(filename)-1, "push%u", count++);
+  curl_msnprintf(filename, sizeof(filename)-1, "push%u", count++);
 
   /* here's a new stream, save it in a new file for each new push */
   out = fopen(filename, "wb");
index 697362f974faaad9f2b46c7af98f0f962bf417b8..e6e39c17096a5c418d7d0353f600a0dcdd439db4 100644 (file)
 /* #include <error.h> */
 #include <errno.h>
 
-#ifdef _MSC_VER
-#define snprintf _snprintf
-#endif
-
 static void log_line_start(FILE *log, const char *idsbuf, curl_infotype type)
 {
   /*
@@ -73,10 +69,11 @@ static int debug_cb(CURL *handle, curl_infotype type,
   if(!curl_easy_getinfo(handle, CURLINFO_XFER_ID, &xfer_id) && xfer_id >= 0) {
     if(!curl_easy_getinfo(handle, CURLINFO_CONN_ID, &conn_id) &&
         conn_id >= 0) {
-      snprintf(idsbuf, sizeof(idsbuf), TRC_IDS_FORMAT_IDS_2, xfer_id, conn_id);
+      curl_msnprintf(idsbuf, sizeof(idsbuf), TRC_IDS_FORMAT_IDS_2, xfer_id,
+                     conn_id);
     }
     else {
-      snprintf(idsbuf, sizeof(idsbuf), TRC_IDS_FORMAT_IDS_1, xfer_id);
+      curl_msnprintf(idsbuf, sizeof(idsbuf), TRC_IDS_FORMAT_IDS_1, xfer_id);
     }
   }
   else
@@ -181,7 +178,11 @@ int main(int argc, char *argv[])
       curl_easy_setopt(easy, CURLOPT_WRITEFUNCTION, write_cb);
       curl_easy_setopt(easy, CURLOPT_WRITEDATA, NULL);
       curl_easy_setopt(easy, CURLOPT_HTTPGET, 1L);
-      snprintf(range, sizeof(range), "%d-%d", 0, 16384);
+      curl_msnprintf(range, sizeof(range),
+                     "%" CURL_FORMAT_CURL_OFF_TU "-"
+                     "%" CURL_FORMAT_CURL_OFF_TU,
+                     (curl_off_t)0,
+                     (curl_off_t)16384);
       curl_easy_setopt(easy, CURLOPT_RANGE, range);
 
       mc = curl_multi_add_handle(multi, easy);
index 97ec862c8b0ee1a7dd472c5a11edf9ec9b7e5c20..8e8d635597301c3bbb48c0be1a39cb169c484a23 100644 (file)
 /* #include <error.h> */
 #include <errno.h>
 
-#ifdef _MSC_VER
-#define snprintf _snprintf
-#endif
-
 static void log_line_start(FILE *log, const char *idsbuf, curl_infotype type)
 {
   /*
@@ -74,10 +70,11 @@ static int debug_cb(CURL *handle, curl_infotype type,
   if(!curl_easy_getinfo(handle, CURLINFO_XFER_ID, &xfer_id) && xfer_id >= 0) {
     if(!curl_easy_getinfo(handle, CURLINFO_CONN_ID, &conn_id) &&
         conn_id >= 0) {
-      snprintf(idsbuf, sizeof(idsbuf), TRC_IDS_FORMAT_IDS_2, xfer_id, conn_id);
+      curl_msnprintf(idsbuf, sizeof(idsbuf), TRC_IDS_FORMAT_IDS_2, xfer_id,
+                     conn_id);
     }
     else {
-      snprintf(idsbuf, sizeof(idsbuf), TRC_IDS_FORMAT_IDS_1, xfer_id);
+      curl_msnprintf(idsbuf, sizeof(idsbuf), TRC_IDS_FORMAT_IDS_1, xfer_id);
     }
   }
   else
@@ -223,7 +220,8 @@ int main(int argc, char *argv[])
   }
 
   memset(&resolve, 0, sizeof(resolve));
-  snprintf(resolve_buf, sizeof(resolve_buf)-1, "%s:%s:127.0.0.1", host, port);
+  curl_msnprintf(resolve_buf, sizeof(resolve_buf)-1, "%s:%s:127.0.0.1",
+                 host, port);
   curl_slist_append(&resolve, resolve_buf);
 
   multi = curl_multi_init();
index 80c030b89c366c7c3e5d014f0e98c303c0169f37..272d4157f42ecd76220df4feb30793bade2116f5 100644 (file)
 #include <unistd.h>  /* getopt() */
 #endif
 
-#ifdef _MSC_VER
-#define snprintf _snprintf
-#endif
-
 #ifndef _MSC_VER
 static void log_line_start(FILE *log, const char *idsbuf, curl_infotype type)
 {
@@ -80,10 +76,11 @@ static int debug_cb(CURL *handle, curl_infotype type,
   if(!curl_easy_getinfo(handle, CURLINFO_XFER_ID, &xfer_id) && xfer_id >= 0) {
     if(!curl_easy_getinfo(handle, CURLINFO_CONN_ID, &conn_id) &&
         conn_id >= 0) {
-      snprintf(idsbuf, sizeof(idsbuf), TRC_IDS_FORMAT_IDS_2, xfer_id, conn_id);
+      curl_msnprintf(idsbuf, sizeof(idsbuf), TRC_IDS_FORMAT_IDS_2, xfer_id,
+                     conn_id);
     }
     else {
-      snprintf(idsbuf, sizeof(idsbuf), TRC_IDS_FORMAT_IDS_1, xfer_id);
+      curl_msnprintf(idsbuf, sizeof(idsbuf), TRC_IDS_FORMAT_IDS_1, xfer_id);
     }
   }
   else
@@ -263,7 +260,8 @@ int main(int argc, char *argv[])
     exit(1);
   }
   memset(&resolve, 0, sizeof(resolve));
-  snprintf(resolve_buf, sizeof(resolve_buf)-1, "%s:%s:127.0.0.1", host, port);
+  curl_msnprintf(resolve_buf, sizeof(resolve_buf)-1, "%s:%s:127.0.0.1",
+                 host, port);
   resolve = curl_slist_append(resolve, resolve_buf);
 
   curl = curl_easy_init();