Page MenuHomePhabricator

Misuse of the Visual Studio version preprocessor macro
ClosedPublic

Authored by Fabien on Mar 9 2020, 09:03.

Details

Summary

The gmtime_s function (used in src/util/time.cpp) is a Microsoft C
runtime (CRT) function (arguments are reversed wrt C11).

There is a preprocessor switch to only use this function with Visual
Studio, but this is inaccurate. This should be used with all the
compilers that use the CRT, including MinGw (but not Cygwin for
example). The correct preprocessor macro for this is _WIN32.

Note: MinGw used to define _MSC_VER under certain circumstances, but
it should not be relied upon (see discussion from
https://sourceforge.net/p/mingw-w64/bugs/282/). This definition appears
to be dependent on headers ordering (D5445 will break the Windows build
as is, but won't if chrono is included last). As a consequence it also
fixes the build with recent versions of MinGw (building on Debian
testing was broken).

Test Plan

Run the Gitian builds.
Build for windows on Debian testing.

Diff Detail

Repository
rABC Bitcoin ABC
Branch
fix_gmtime_s
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 9762
Build 17403: Default Diff Build & Tests
Build 17402: arc lint + arc unit

Event Timeline

This revision is now accepted and ready to land.Mar 10 2020, 07:34