Opened 5 years ago

Closed 5 years ago

#7373 closed Bugs (fixed)

Boost ASIO has a wrong swprintf interface definition for MinGW

Reported by: Lukas Dürrenberger <eXpl0it3r@…> Owned by: chris_kohlhoff
Milestone: To Be Determined Component: asio
Version: Boost Development Trunk Severity: Problem
Keywords: Cc:


In the file win_static_mutex.ipp on the lines 45-51 one can read:

#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400) && !defined(UNDER_CE)
  swprintf_s(mutex_name, 128,
#else // BOOST_WORKAROUND(BOOST_MSVC, >= 1400) && !defined(UNDER_CE)
#endif // BOOST_WORKAROUND(BOOST_MSVC, >= 1400) && !defined(UNDER_CE)
      static_cast<unsigned int>(::GetCurrentProcessId()), this);

As one can see there are two different signatures. The first one is for Visual Studio's swprintf_s function and the second one should be for the rest, but this function is declared differently in MinGW and also takes an integer as second argument. The correct interface is declared in MinGW's libintl.h header on line 419 as following:

extern int swprintf (wchar_t *, size_t, const wchar_t *, ...);

That deceleration is also what the C99 standard declares: § (p. 362)

A fix would either involve to change the #else statement completely to add a second parameter as with swprintf_s or another check for MinGW. Probably the better solution would be to completely eliminate the swprintf function and make use of streams.

If tested the version 1.49, 1.50 and 1.51 and for all, my application fails to build, simply by including the ASIO header.

Attachments (0)

Change History (2)

comment:1 Changed 5 years ago by viboes

Component: Noneasio
Owner: set to chris_kohlhoff

comment:2 Changed 5 years ago by chris_kohlhoff

Resolution: fixed
Status: newclosed

(In [82290]) Merge from trunk:

  • Fix some 64-to-32-bit conversion warnings. Fixes #7459
  • Fix typos in comments. Fixes #7761
  • Fix error in example embedded in basic_socket::get_option's documentation. Fixes #7562
  • Use long rather than int for SSL_CTX options, to match OpenSSL. Fixes #7209
  • Use _snwprintf to address a compile error due to the changed swprintf signature in recent versions of MinGW. Fixes #7373
  • Fix deadlock that can occur on Windows when shutting down a pool of io_service threads due to running out of work. Fixes #7552
  • Enable noexcept qualifier for error categories. Fixes #7797
  • Treat errors from accept as non-fatal. Fixes #7488
  • Add a small block recycling optimisation.
  • Version bump.
  • Regenerate documentation.

Modify Ticket

Change Properties
Set your email in Preferences
as closed The owner will remain chris_kohlhoff.
The resolution will be deleted.

Add Comment

E-mail address and name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.