Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: make CURL_FORMAT_CURL_OFF_T[U] work with mingw-w64 <=7.0.0 #14640

Closed
wants to merge 10 commits into from

Conversation

vszakats
Copy link
Member

@vszakats vszakats commented Aug 21, 2024

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 232302f #14382
Ref: #14625 (comment)


  • add the same for autotools.
  • fix it in curl/system.h instead?

@github-actions github-actions bot added the tests label Aug 21, 2024
@vszakats vszakats added build Windows Windows-specific labels Aug 21, 2024
@vszakats
Copy link
Member Author

Here's an untested alternative plan:

--- a/include/curl/system.h
+++ b/include/curl/system.h
@@ -178,10 +178,16 @@
 #  define CURL_TYPEOF_CURL_SOCKLEN_T int
 
 #elif defined(__MINGW32__)
+#  include <_mingw.h>
 #  include <inttypes.h>
 #  define CURL_TYPEOF_CURL_OFF_T     long long
+#if defined(__MINGW64_VERSION_MAJOR) && __MINGW64_VERSION_MAJOR <= 7
+#  define CURL_FORMAT_CURL_OFF_T     "lld"
+#  define CURL_FORMAT_CURL_OFF_TU    "llu"
+#else
 #  define CURL_FORMAT_CURL_OFF_T     PRId64
 #  define CURL_FORMAT_CURL_OFF_TU    PRIu64
+#endif
 #  define CURL_SUFFIX_CURL_OFF_T     LL
 #  define CURL_SUFFIX_CURL_OFF_TU    ULL
 #  define CURL_TYPEOF_CURL_SOCKLEN_T int
--- a/lib/curl_setup.h
+++ b/lib/curl_setup.h
@@ -317,17 +317,6 @@
 #define CURL_CONC_MACROS_(A,B) A ## B
 #define CURL_CONC_MACROS(A,B) CURL_CONC_MACROS_(A,B)
 
-/* curl uses its own printf() function internally. It understands the GNU
- * format. Use this format, so that is matches the GNU format attribute we
- * use with the MinGW compiler, allowing it to verify them at compile-time.
- */
-#ifdef  __MINGW32__
-#  undef CURL_FORMAT_CURL_OFF_T
-#  undef CURL_FORMAT_CURL_OFF_TU
-#  define CURL_FORMAT_CURL_OFF_T   "lld"
-#  define CURL_FORMAT_CURL_OFF_TU  "llu"
-#endif
-
 /* based on logic in "curl/mprintf.h" */
 
 #if (defined(__GNUC__) || defined(__clang__) ||                         \

configure.ac Show resolved Hide resolved
@vszakats
Copy link
Member Author

@bagder Regarding the alternative patch (targeting system.h), what about landing this PR first, then make a test with it to see if it works?

@bagder
Copy link
Member

bagder commented Aug 22, 2024

Sure!

@vszakats vszakats closed this in c730c85 Aug 22, 2024
@vszakats vszakats deleted the tests-client-mingw-printf branch August 22, 2024 08:46
vszakats added a commit to vszakats/curl that referenced this pull request Aug 22, 2024
vszakats added a commit to vszakats/curl that referenced this pull request Aug 22, 2024
vszakats added a commit to vszakats/curl that referenced this pull request Aug 26, 2024
vszakats added a commit to vszakats/curl that referenced this pull request Aug 27, 2024
vszakats added a commit to vszakats/curl that referenced this pull request Aug 28, 2024
vszakats added a commit to vszakats/curl that referenced this pull request Sep 1, 2024
vszakats added a commit that referenced this pull request Sep 2, 2024
Change mingw-w64 printf format checks in public curl headers to use
`__MINGW_PRINTF_FORMAT` instead of `gnu_printf`. This syncs the format
checker with format string macros published via `curl/system.h`. (Also
disable format checks for mingw-w64 older than 3.0.0 (2013-09-20) and
classic-mingw, which do not support this macro.)

This fixes bogus format checker `-Wformat` warnings in 3rd party code
using curl format strings with the curl printf functions, when using
mingw-w64 7.0.0 (2019-11-10) and older (with GCC, MSVCRT).

It also allows to delete two workaounds for this within curl itself:
- setting `-D__USE_MINGW_ANSI_STDIO=1` for mingw-w64 via cmake and
  configure for `docs/examples` and `tests/http/clients`.
  Ref: c730c85 #14640

The format check macro is incompatible (depending on mingw-w64 version
and configuration) with the C99 `%z` (`size_t`) format string used
internally by curl.

To work around this problem, override the format check style in curl
public headers to use `gnu_printf`. This is compatible with `%z` in all
mingw-w64 versions and allows keeping the C99 format strings internally.

Also:
- lib/ws.c: add missing space to an error message.
- docs/examples/ftpgetinfo.c: fix to use standard printf.

Ref: #14643 (take 1)
Follow-up to 3829759 #12489

Closes #14703
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

2 participants