From fdb4607280fd98617cbc441f79a49ae7393fb840 Mon Sep 17 00:00:00 2001 From: Billy Robert O'Neal III Date: Mon, 6 Jul 2020 22:37:30 -0700 Subject: [PATCH 01/17] Turn on /analyze. --- CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0ed60548213..c8eed90234b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -63,8 +63,7 @@ add_compile_definitions( _ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH WIN32_LEAN_AND_MEAN STRICT _CRT_STDIO_ARBITRARY_WIDE_SPECIFIERS _CRT_DECLARE_NONSTDC_NAMES=1 ) -# TRANSITION, /analyze ? -add_compile_options(/diagnostics:caret /W4 /WX /w14265 /w15038 /d1FastFail /guard:cf /Z7 /d2Zi+ /Gm- /Gy /Zp8 /std:c++latest /permissive- /Zc:threadSafeInit- /Zl) +add_compile_options(/diagnostics:caret /analyze /W4 /WX /w14265 /w15038 /d1FastFail /guard:cf /Z7 /d2Zi+ /Gm- /Gy /Zp8 /std:c++latest /permissive- /Zc:threadSafeInit- /Zl) set(VCLIBS_DEBUG_OPTIONS "/Od") set(VCLIBS_RELEASE_OPTIONS "/O2;/Os") # TRANSITION: Potentially remove /Os From 60fe5d91ab634905420f65246805e23c1f45f5a3 Mon Sep 17 00:00:00 2001 From: Billy Robert O'Neal III Date: Mon, 6 Jul 2020 22:33:13 -0700 Subject: [PATCH 02/17] Add matching set_new_handler annotation. --- stl/src/stdhndlr.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stl/src/stdhndlr.cpp b/stl/src/stdhndlr.cpp index 3c0b777eba2..af55e61873e 100644 --- a/stl/src/stdhndlr.cpp +++ b/stl/src/stdhndlr.cpp @@ -17,7 +17,7 @@ int __cdecl _New_handler_interface(size_t) { // interface to existing Microsoft return 1; } -_CRTIMP2 new_handler __cdecl set_new_handler(new_handler pnew) noexcept { // remove current handler +_CRTIMP2 new_handler __cdecl set_new_handler(_In_opt_ new_handler pnew) noexcept { // remove current handler _BEGIN_LOCK(_LOCK_MALLOC) // lock thread to ensure atomicity new_handler pold = _New_handler; _New_handler = pnew; From a878d5ca01e9e0ad6f94eff09c8b63fda405daa9 Mon Sep 17 00:00:00 2001 From: Billy Robert O'Neal III Date: Mon, 6 Jul 2020 22:37:22 -0700 Subject: [PATCH 03/17] Suppress C6326 'Potential comparison of a constant with another constant' by making the constant comparison constexpr. --- stl/src/xxxprec.hpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/stl/src/xxxprec.hpp b/stl/src/xxxprec.hpp index a5990e030d7..9fefcb7ee6e 100644 --- a/stl/src/xxxprec.hpp +++ b/stl/src/xxxprec.hpp @@ -75,8 +75,9 @@ FTYPE* FNAME(Xp_setw)(FTYPE* p, int n, FTYPE x) { // load a full-precision value p[0] = x0; // ms bits p[1] = x - x0; // ls bits -#pragma warning(suppress : 4127) - if ((FBITS & 1) != 0 && 2 < n && p[1] != FLIT(0.0)) { // may need a third word + + constexpr bool _Fbits_odd = (FBITS & 1) != 0; + if (_Fbits_odd && 2 < n && p[1] != FLIT(0.0)) { // may need a third word x = p[1]; FNAME(Dunscale)(&xexp, &p[1]); FNAME(Dint)(&p[1], BITS_WORD); From def3994b2348c076d087f1a4702aac87da876c2b Mon Sep 17 00:00:00 2001 From: Billy Robert O'Neal III Date: Mon, 6 Jul 2020 22:46:20 -0700 Subject: [PATCH 04/17] Unpack Xp_setw to get the constant comparison into an if constexpr block. --- stl/src/xxxprec.hpp | 46 ++++++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/stl/src/xxxprec.hpp b/stl/src/xxxprec.hpp index 9fefcb7ee6e..e708ffbf059 100644 --- a/stl/src/xxxprec.hpp +++ b/stl/src/xxxprec.hpp @@ -63,21 +63,31 @@ FTYPE* FNAME(Xp_setw)(FTYPE* p, int n, FTYPE x) { // load a full-precision value short errx; short xexp; - if (n > 0) { - if (n == 1 || (errx = FNAME(Dunscale)(&xexp, &x0)) == 0) { - p[0] = x0; // zero or no extra room, store original value - } else if (0 < errx) { // store Inf or NaN with backstop for safety - p[0] = x0; - p[1] = FLIT(0.0); - } else { // finite, unpack it - FNAME(Dint)(&x0, BITS_WORD); - FNAME(Dscale)(&x0, xexp); - - p[0] = x0; // ms bits - p[1] = x - x0; // ls bits - - constexpr bool _Fbits_odd = (FBITS & 1) != 0; - if (_Fbits_odd && 2 < n && p[1] != FLIT(0.0)) { // may need a third word + if (n <= 0) { + return p; + } + + if (n == 1 || (errx = FNAME(Dunscale)(&xexp, &x0)) == 0) { + p[0] = x0; // zero or no extra room, store original value + return p; + } + + if (0 < errx) { // store Inf or NaN with backstop for safety + p[0] = x0; + p[1] = FLIT(0.0); + return p; + } + + // finite, unpack it + FNAME(Dint)(&x0, BITS_WORD); + FNAME(Dscale)(&x0, xexp); + + p[0] = x0; // ms bits + p[1] = x - x0; // ls bits + + if (2 < n) { + if constexpr ((FBITS & 1) != 0) { + if (p[1] != FLIT(0.0)) { // may need a third word x = p[1]; FNAME(Dunscale)(&xexp, &p[1]); FNAME(Dint)(&p[1], BITS_WORD); @@ -86,10 +96,12 @@ FTYPE* FNAME(Xp_setw)(FTYPE* p, int n, FTYPE x) { // load a full-precision value if (3 < n && p[2] != FLIT(0.0)) { p[3] = FLIT(0.0); } - } else if (2 < n) { - p[2] = FLIT(0.0); + + return p; } } + + p[2] = FLIT(0.0); } return p; From cefc151aac7e83817a2806204859d7433e7f4271 Mon Sep 17 00:00:00 2001 From: Billy Robert O'Neal III Date: Mon, 6 Jul 2020 23:02:39 -0700 Subject: [PATCH 05/17] Teach PREfast about maxsig in the _Stoflt family. --- stl/src/xmath.hpp | 11 +++++++---- stl/src/xstoflt.cpp | 5 +++-- stl/src/xstoxflt.cpp | 5 +++-- stl/src/xwstoflt.cpp | 5 +++-- stl/src/xwstoxfl.cpp | 5 +++-- stl/src/xxstod.hpp | 2 ++ 6 files changed, 21 insertions(+), 12 deletions(-) diff --git a/stl/src/xmath.hpp b/stl/src/xmath.hpp index 32bd8b60f7b..d3967ab9ae2 100644 --- a/stl/src/xmath.hpp +++ b/stl/src/xmath.hpp @@ -49,11 +49,14 @@ _EXTERN_C_UNLESS_PURE int _Stopfx(const char**, char**); -int _Stoflt(const char*, const char*, char**, long[], int); -int _Stoxflt(const char*, const char*, char**, long[], int); +_In_range_(0, maxsig) int _Stoflt(const char*, const char*, char**, _Out_writes_(maxsig) long[], _In_range_(1, 4) int maxsig); +_In_range_(0, maxsig) int _Stoxflt( + const char*, const char*, char**, _Out_writes_(maxsig) long[], _In_range_(1, 4) int maxsig); int _WStopfx(const wchar_t**, wchar_t**); -int _WStoflt(const wchar_t*, const wchar_t*, wchar_t**, long[], int); -int _WStoxflt(const wchar_t*, const wchar_t*, wchar_t**, long[], int); +_In_range_(0, maxsig) int _WStoflt( + const wchar_t*, const wchar_t*, wchar_t**, _Out_writes_(maxsig) long[], _In_range_(1, 4) int maxsig); +_In_range_(0, maxsig) int _WStoxflt( + const wchar_t*, const wchar_t*, wchar_t**, _Out_writes_(maxsig) long[], _In_range_(1, 4) int maxsig); // double declarations union _Dval { // pun floating type as integer array diff --git a/stl/src/xstoflt.cpp b/stl/src/xstoflt.cpp index 98c203cdd7a..57dfdaf5707 100644 --- a/stl/src/xstoflt.cpp +++ b/stl/src/xstoflt.cpp @@ -15,8 +15,9 @@ constexpr int _Base = 10; // decimal constexpr int _Ndig = 9; // decimal digits per long word constexpr int _Maxsig = 5 * _Ndig; // maximum significant digits to keep -int _Stoflt(const char* s0, const char* s, char** endptr, long lo[], - int maxsig) { // convert string to array of long plus exponent +_In_range_(0, maxsig) int _Stoflt( + const char* s0, const char* s, char** endptr, _Out_writes_(maxsig) long lo[], _In_range_(1, 4) int maxsig) { + // convert string to array of long plus exponent char buf[_Maxsig + 1]; // worst case, with room for rounding digit int nsig = 0; // number of significant digits seen int seen = 0; // any valid field characters seen diff --git a/stl/src/xstoxflt.cpp b/stl/src/xstoxflt.cpp index 7ef6b4d2018..3c18095a71d 100644 --- a/stl/src/xstoxflt.cpp +++ b/stl/src/xstoxflt.cpp @@ -16,8 +16,9 @@ constexpr int _Base = 16; // hexadecimal constexpr int _Ndig = 7; // hexadecimal digits per long element constexpr int _Maxsig = 5 * _Ndig; // maximum significant digits to keep -int _Stoxflt(const char* s0, const char* s, char** endptr, long lo[], - int maxsig) { // convert string to array of long plus exponent +_In_range_(0, maxsig) int _Stoxflt( + const char* s0, const char* s, char** endptr, _Out_writes_(maxsig) long lo[], _In_range_(1, 4) int maxsig) { + // convert string to array of long plus exponent char buf[_Maxsig + 1]; // worst case, with room for rounding digit int nsig = 0; // number of significant digits seen int seen = 0; // any valid field characters seen diff --git a/stl/src/xwstoflt.cpp b/stl/src/xwstoflt.cpp index 7f5f3fddac4..0631679e5d2 100644 --- a/stl/src/xwstoflt.cpp +++ b/stl/src/xwstoflt.cpp @@ -15,8 +15,9 @@ constexpr int _Base = 10; // decimal constexpr int _Ndig = 9; // decimal digits per long element constexpr int _Maxsig = 5 * _Ndig; // maximum significant digits to keep -int _WStoflt(const wchar_t* s0, const wchar_t* s, wchar_t** endptr, long lo[], - int maxsig) { // convert wide string to array of long plus exponent +_In_range_(0, maxsig) int _WStoflt(const wchar_t* s0, const wchar_t* s, wchar_t** endptr, + _Out_writes_(maxsig) long lo[], _In_range_(1, 4) int maxsig) { + // convert wide string to array of long plus exponent char buf[_Maxsig + 1]; // worst case, with room for rounding digit int nsig = 0; // number of significant digits seen int seen = 0; // any valid field characters seen diff --git a/stl/src/xwstoxfl.cpp b/stl/src/xwstoxfl.cpp index f694b9bd201..871501031e3 100644 --- a/stl/src/xwstoxfl.cpp +++ b/stl/src/xwstoxfl.cpp @@ -16,8 +16,9 @@ constexpr int _Base = 16; // hexadecimal constexpr int _Ndig = 7; // hexadecimal digits per long element constexpr int _Maxsig = 5 * _Ndig; // maximum significant digits to keep -int _WStoxflt(const wchar_t* s0, const wchar_t* s, wchar_t** endptr, long lo[], - int maxsig) { // convert wide string to array of long plus exponent +_In_range_(0, maxsig) int _WStoxflt(const wchar_t* s0, const wchar_t* s, wchar_t** endptr, + _Out_writes_(maxsig) long lo[], _In_range_(1, 4) int maxsig) { + // convert wide string to array of long plus exponent char buf[_Maxsig + 1]; // worst case, with room for rounding digit int nsig = 0; // number of significant digits seen int seen = 0; // any valid field characters seen diff --git a/stl/src/xxstod.hpp b/stl/src/xxstod.hpp index 25f93fb7f47..0e6a4167e9f 100644 --- a/stl/src/xxstod.hpp +++ b/stl/src/xxstod.hpp @@ -35,6 +35,7 @@ if ((code &= ~FL_NEG) == FL_DEC) { // parse decimal format const int nlo = CNAME(Stoflt)(s0, s, endptr, lo, NLONG); + _Analysis_assume_(nlo <= NLONG); FTYPE xpx[ACSIZE], xpf[ACSIZE]; int i; @@ -56,6 +57,7 @@ x = FNAME(Dtento)(xpx, pten, perr); } else if (code == FL_HEX) { // parse hexadecimal format const int nlo = CNAME(Stoxflt)(s0, s, endptr, lo, NLONG); + _Analysis_assume_(nlo <= NLONG); FTYPE xpx[ACSIZE], xpf[ACSIZE]; int i; From efbb5e8ded31adb796e4d775b0fe60d99281fc1b Mon Sep 17 00:00:00 2001 From: Billy Robert O'Neal III Date: Tue, 7 Jul 2020 00:09:57 -0700 Subject: [PATCH 06/17] Fix annotations on __crtLocale functions in awint.h. --- stl/src/StlCompareStringA.cpp | 6 ++++-- stl/src/StlCompareStringW.cpp | 5 +++-- stl/src/StlLCMapStringA.cpp | 6 ++++-- stl/src/StlLCMapStringW.cpp | 5 +++-- stl/src/awint.hpp | 12 ++++++------ 5 files changed, 20 insertions(+), 14 deletions(-) diff --git a/stl/src/StlCompareStringA.cpp b/stl/src/StlCompareStringA.cpp index 70aad1a6442..977838a3768 100644 --- a/stl/src/StlCompareStringA.cpp +++ b/stl/src/StlCompareStringA.cpp @@ -30,8 +30,9 @@ // 2 - if lpString1 == lpString2 // 3 - if lpString1 > lpString2 // Failure: 0 -extern "C" int __cdecl __crtCompareStringA(LPCWSTR LocaleName, DWORD dwCmpFlags, LPCSTR lpString1, int cchCount1, - LPCSTR lpString2, int cchCount2, int code_page) { +extern "C" int __cdecl __crtCompareStringA(_In_z_ LPCWSTR LocaleName, _In_ DWORD dwCmpFlags, + _In_reads_(cchCount1) LPCSTR lpString1, _In_ int cchCount1, _In_reads_(cchCount2) LPCSTR lpString2, + _In_ int cchCount2, _In_ int code_page) { // CompareString will compare past null terminator. Must find null terminator if in string before cchCountn chars. if (cchCount1 > 0) { cchCount1 = static_cast(__strncnt(lpString1, cchCount1)); @@ -133,6 +134,7 @@ extern "C" int __cdecl __crtCompareStringA(LPCWSTR LocaleName, DWORD dwCmpFlags, } // allocate enough space for chars +#pragma warning(suppress : 6386) // TRANSITION, VSO-1152705 false buffer overrun report in _malloca_crt_t const __crt_scoped_stack_ptr wbuffer2(_malloca_crt_t(wchar_t, buff_size2)); if (wbuffer2.get() == nullptr) { return 0; diff --git a/stl/src/StlCompareStringW.cpp b/stl/src/StlCompareStringW.cpp index 05d24f2c172..d4c80042608 100644 --- a/stl/src/StlCompareStringW.cpp +++ b/stl/src/StlCompareStringW.cpp @@ -26,8 +26,9 @@ // 2 - if lpString1 == lpString2 // 3 - if lpString1 > lpString2 // Failure: 0 -extern "C" int __cdecl __crtCompareStringW( - LPCWSTR LocaleName, DWORD dwCmpFlags, LPCWSTR lpString1, int cchCount1, LPCWSTR lpString2, int cchCount2) { +extern "C" int __cdecl __crtCompareStringW(_In_z_ LPCWSTR LocaleName, _In_ DWORD dwCmpFlags, + _In_reads_(cchCount1) LPCWSTR lpString1, _In_ int cchCount1, _In_reads_(cchCount2) LPCWSTR lpString2, + _In_ int cchCount2) { // CompareString will compare past null terminator. Must find null terminator if in string before cchCountn wide // characters. if (cchCount1 > 0) { diff --git a/stl/src/StlLCMapStringA.cpp b/stl/src/StlLCMapStringA.cpp index 0829495a1d7..3236a5708b5 100644 --- a/stl/src/StlLCMapStringA.cpp +++ b/stl/src/StlLCMapStringA.cpp @@ -29,8 +29,9 @@ // Exit: // Success: number of chars written to lpDestStr (including null terminator) // Failure: 0 -extern "C" int __cdecl __crtLCMapStringA(LPCWSTR LocaleName, DWORD dwMapFlags, LPCSTR lpSrcStr, int cchSrc, - LPSTR lpDestStr, int cchDest, int code_page, BOOL bError) { +extern "C" int __cdecl __crtLCMapStringA(_In_z_ LPCWSTR LocaleName, _In_ DWORD dwMapFlags, + _In_reads_(cchSrc) LPCSTR lpSrcStr, _In_ int cchSrc, _Out_writes_opt_(cchDest) char* lpDestStr, _In_ int cchDest, + _In_ int code_page, _In_ BOOL bError) { // LCMapString will map past the null terminator. We must find the null // terminator if it occurs in the string before cchSrc characters // and cap the number of characters to be considered. @@ -94,6 +95,7 @@ extern "C" int __cdecl __crtLCMapStringA(LPCWSTR LocaleName, DWORD dwMapFlags, L int outbuff_size = retval; // allocate enough space for wide chars (includes null terminator if any) +#pragma warning(suppress : 6386) // TRANSITION, VSO-1152705 false buffer overrun report in _malloca_crt_t const __crt_scoped_stack_ptr outwbuffer(_malloca_crt_t(wchar_t, outbuff_size)); if (!outwbuffer) { return retval; diff --git a/stl/src/StlLCMapStringW.cpp b/stl/src/StlLCMapStringW.cpp index 33899e40319..da354609a2f 100644 --- a/stl/src/StlLCMapStringW.cpp +++ b/stl/src/StlLCMapStringW.cpp @@ -31,8 +31,9 @@ // else // number of wide characters written to destination (including null terminator) // Failure: 0 -extern "C" int __cdecl __crtLCMapStringW(LPCWSTR const locale_name, DWORD const map_flags, LPCWSTR const source, - int source_count, LPWSTR const destination, int const destination_count) { +extern "C" int __cdecl __crtLCMapStringW(_In_z_ LPCWSTR const locale_name, _In_ DWORD const map_flags, + _In_reads_(source_count) LPCWSTR const source, _In_ int source_count, + _Out_writes_opt_(destination_count) wchar_t* const destination, _In_ int const destination_count) { // LCMapString will map past the null terminator. We must find the null terminator if it occurs in the string // before source_count characters and cap the number of characters to be considered. if (source_count > 0) { diff --git a/stl/src/awint.hpp b/stl/src/awint.hpp index 9ed1b0d3d23..31077ed39fe 100644 --- a/stl/src/awint.hpp +++ b/stl/src/awint.hpp @@ -342,20 +342,20 @@ using PFNLCMAPSTRINGEX = int(WINAPI*)(LPCWSTR, DWORD, LPCWSTR, int, LPWSTR, in DYNAMICGETCACHEDFUNCTION(function_pointer_type, function_name, variable_name); \ if (variable_name != nullptr) -_CRTIMP2 int __cdecl __crtCompareStringA(_In_ LPCWSTR _LocaleName, _In_ DWORD _DwCmpFlags, +_CRTIMP2 int __cdecl __crtCompareStringA(_In_z_ LPCWSTR _LocaleName, _In_ DWORD _DwCmpFlags, _In_reads_(_CchCount1) LPCSTR _LpString1, _In_ int _CchCount1, _In_reads_(_CchCount2) LPCSTR _LpString2, _In_ int _CchCount2, _In_ int _CodePage); -_CRTIMP2 int __cdecl __crtCompareStringW(_In_ LPCWSTR _LocaleName, _In_ DWORD _DwCmpFlags, +_CRTIMP2 int __cdecl __crtCompareStringW(_In_z_ LPCWSTR _LocaleName, _In_ DWORD _DwCmpFlags, _In_reads_(_CchCount1) LPCWSTR _LpString1, _In_ int _CchCount1, _In_reads_(_CchCount2) LPCWSTR _LpString2, _In_ int _CchCount2); -_CRTIMP2 int __cdecl __crtLCMapStringA(_In_ LPCWSTR _LocaleName, _In_ DWORD _DwMapFlag, - _In_reads_(_CchSrc) LPCSTR _LpSrcStr, _In_ int _CchSrc, _Out_writes_opt_(_CchDest) LPSTR _LpDestStr, +_CRTIMP2 int __cdecl __crtLCMapStringA(_In_z_ LPCWSTR _LocaleName, _In_ DWORD _DwMapFlag, + _In_reads_(_CchSrc) LPCSTR _LpSrcStr, _In_ int _CchSrc, _Out_writes_opt_(_CchDest) char* _LpDestStr, _In_ int _CchDest, _In_ int _CodePage, _In_ BOOL _BError); -_CRTIMP2 int __cdecl __crtLCMapStringW(_In_ LPCWSTR _LocaleName, _In_ DWORD _DWMapFlag, - _In_reads_(_CchSrc) LPCWSTR _LpSrcStr, _In_ int _CchSrc, _Out_writes_opt_(_CchDest) LPWSTR _LpDestStr, +_CRTIMP2 int __cdecl __crtLCMapStringW(_In_z_ LPCWSTR _LocaleName, _In_ DWORD _DWMapFlag, + _In_reads_(_CchSrc) LPCWSTR _LpSrcStr, _In_ int _CchSrc, _Out_writes_opt_(_CchDest) wchar_t* _LpDestStr, _In_ int _CchDest); _CRT_END_C_HEADER From 626ed31646bd10d98989f8afc201f1c08b76c23b Mon Sep 17 00:00:00 2001 From: Billy Robert O'Neal III Date: Tue, 7 Jul 2020 02:05:49 -0700 Subject: [PATCH 07/17] Fix a bunch of annotations. --- stl/inc/exception | 2 +- stl/inc/xfilesystem_abi.h | 27 +++++----- stl/inc/xlocinfo.h | 6 ++- stl/src/StlLCMapStringA.cpp | 2 +- stl/src/StlLCMapStringW.cpp | 2 +- stl/src/awint.hpp | 9 ++-- stl/src/excptptr.cpp | 24 +++++---- stl/src/filesystem.cpp | 101 ++++++++++++++++++++---------------- stl/src/winapinls.cpp | 14 ++--- stl/src/winapisupp.cpp | 84 ++++++++++++++++-------------- stl/src/xmbtowc.cpp | 3 +- stl/src/xstrxfrm.cpp | 5 +- stl/src/xwcsxfrm.cpp | 5 +- stl/src/xwctomb.cpp | 3 +- 14 files changed, 160 insertions(+), 127 deletions(-) diff --git a/stl/inc/exception b/stl/inc/exception index 37cf6e1227e..0b0f52e749c 100644 --- a/stl/inc/exception +++ b/stl/inc/exception @@ -204,7 +204,7 @@ _CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL __ExceptionPtrAssign(_Inout_ void*, _ _CRTIMP2_PURE bool __CLRCALL_PURE_OR_CDECL __ExceptionPtrCompare(_In_ const void*, _In_ const void*) noexcept; _CRTIMP2_PURE bool __CLRCALL_PURE_OR_CDECL __ExceptionPtrToBool(_In_ const void*) noexcept; _CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL __ExceptionPtrSwap(_Inout_ void*, _Inout_ void*) noexcept; -_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL __ExceptionPtrCurrentException(_Out_ void*) noexcept; +_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL __ExceptionPtrCurrentException(void*) noexcept; [[noreturn]] _CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL __ExceptionPtrRethrow(_In_ const void*); _CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL __ExceptionPtrCopyException( _Inout_ void*, _In_ const void*, _In_ const void*) noexcept; diff --git a/stl/inc/xfilesystem_abi.h b/stl/inc/xfilesystem_abi.h index 0d3ce7035a9..60b4800ec21 100644 --- a/stl/inc/xfilesystem_abi.h +++ b/stl/inc/xfilesystem_abi.h @@ -239,8 +239,9 @@ _NODISCARD __std_win_error __stdcall __std_fs_open_handle(_Out_ __std_fs_file_ha void __stdcall __std_fs_close_handle(__std_fs_file_handle _Handle) noexcept; -_NODISCARD __std_win_error __stdcall __std_fs_get_file_attributes_by_handle( - _In_ __std_fs_file_handle _Handle, _Out_ unsigned long* _File_attributes) noexcept; +_NODISCARD _Success_(return == __std_win_error::_Success) __std_win_error + __stdcall __std_fs_get_file_attributes_by_handle( + _In_ __std_fs_file_handle _Handle, _Out_ unsigned long* _File_attributes) noexcept; _NODISCARD __std_ulong_and_error __stdcall __std_fs_get_final_path_name_by_handle(_In_ __std_fs_file_handle _Handle, _Out_writes_z_(_Target_size) wchar_t* _Target, _In_ unsigned long _Target_size, @@ -259,8 +260,8 @@ _NODISCARD __std_win_error __stdcall __std_fs_directory_iterator_open(_In_z_ con void __stdcall __std_fs_directory_iterator_close(_In_ __std_fs_dir_handle _Handle) noexcept; -_NODISCARD __std_win_error __stdcall __std_fs_get_stats(_In_z_ const wchar_t* _Path, _Out_ __std_fs_stats* _Stats, - _In_ __std_fs_stats_flags _Flags, +_NODISCARD _Success_(return == __std_win_error::_Success) __std_win_error __stdcall __std_fs_get_stats( + _In_z_ const wchar_t* _Path, _Out_ __std_fs_stats* _Stats, _In_ __std_fs_stats_flags _Flags, _In_ __std_fs_file_attr _Symlink_attribute_hint = __std_fs_file_attr::_Invalid) noexcept; _NODISCARD __std_win_error __stdcall __std_fs_directory_iterator_advance( @@ -276,8 +277,8 @@ _NODISCARD __std_fs_convert_result __stdcall __std_fs_convert_wide_to_narrow(_In _In_reads_(_Input_len) const wchar_t* _Input_str, _In_ int _Input_len, _Out_writes_opt_(_Output_len) char* _Output_str, _In_ int _Output_len) noexcept; -_NODISCARD __std_win_error __stdcall __std_fs_get_file_id( - _Out_ __std_fs_file_id* _Id, _In_z_ const wchar_t* _Path) noexcept; +_NODISCARD _Success_(return == __std_win_error::_Success) __std_win_error + __stdcall __std_fs_get_file_id(_Out_ __std_fs_file_id* _Id, _In_z_ const wchar_t* _Path) noexcept; _NODISCARD __std_win_error __stdcall __std_fs_set_last_write_time( _In_ long long _Last_write_filetime, _In_z_ const wchar_t* _Path) noexcept; @@ -285,11 +286,12 @@ _NODISCARD __std_win_error __stdcall __std_fs_set_last_write_time( _NODISCARD __std_win_error __stdcall __std_fs_change_permissions( _In_z_ const wchar_t* _Path, _In_ bool _Follow_symlinks, _In_ bool _Readonly) noexcept; -_NODISCARD __std_ulong_and_error __stdcall __std_fs_get_temp_path( - _Out_writes_z_(__std_fs_temp_path_max) wchar_t* _Target) noexcept; +_NODISCARD _Success_(return._Error == __std_win_error::_Success) __std_ulong_and_error + __stdcall __std_fs_get_temp_path(_Out_writes_z_(__std_fs_temp_path_max) wchar_t* _Target) noexcept; -_NODISCARD __std_ulong_and_error __stdcall __std_fs_get_current_path( - _In_ unsigned long _Target_size, _Out_writes_z_(_Target_size) wchar_t* _Target) noexcept; +_NODISCARD _Success_(return._Error == __std_win_error::_Success) __std_ulong_and_error + __stdcall __std_fs_get_current_path( + _In_ unsigned long _Target_size, _Out_writes_z_(_Target_size) wchar_t* _Target) noexcept; _NODISCARD __std_win_error __stdcall __std_fs_set_current_path(_In_z_ const wchar_t* _Target) noexcept; @@ -305,8 +307,9 @@ _NODISCARD __std_win_error __stdcall __std_fs_create_symbolic_link( _NODISCARD __std_win_error __stdcall __std_fs_read_reparse_data_buffer(_In_ __std_fs_file_handle _Handle, _Out_writes_bytes_(_Buffer_size) void* _Buffer, _In_ unsigned long _Buffer_size) noexcept; -_NODISCARD __std_win_error __stdcall __std_fs_read_name_from_reparse_data_buffer( - _In_ __std_fs_reparse_data_buffer* _Handle, _Out_ wchar_t** _Offset, _Out_ unsigned short* _Length) noexcept; +_NODISCARD _Success_(return == __std_win_error::_Success) __std_win_error + __stdcall __std_fs_read_name_from_reparse_data_buffer( + _In_ __std_fs_reparse_data_buffer* _Handle, _Out_ wchar_t** _Offset, _Out_ unsigned short* _Length) noexcept; struct __std_fs_create_directory_result { bool _Created; diff --git a/stl/inc/xlocinfo.h b/stl/inc/xlocinfo.h index b9756b03dd2..5cfba660a07 100644 --- a/stl/inc/xlocinfo.h +++ b/stl/inc/xlocinfo.h @@ -87,7 +87,8 @@ _CRTIMP2_PURE int __CLRCALL_PURE_OR_CDECL _Getdateorder(); _Mbrtowc(_Out_opt_ wchar_t*, const char*, size_t, mbstate_t*, const _Cvtvec*); #else // _M_CEE_PURE -_MRTIMP2 int __cdecl _Mbrtowc(_Out_opt_ wchar_t*, const char*, size_t, mbstate_t*, const _Cvtvec*); +_MRTIMP2 _Success_(return >= 0) int __cdecl _Mbrtowc( + _When_(_Max_multibyte != 0, _Out_) wchar_t*, const char*, size_t _Max_multibyte, mbstate_t*, const _Cvtvec*); #endif // _M_CEE_PURE _CRTIMP2_PURE float __CLRCALL_PURE_OR_CDECL _Stof(const char*, _Out_opt_ _Deref_post_opt_valid_ char**, long); @@ -100,7 +101,8 @@ _CRTIMP2_PURE size_t __CLRCALL_PURE_OR_CDECL _Strxfrm(_Out_writes_(_End1 - _Stri _In_z_ char* _End1, const char*, const char*, const _Collvec*); _CRTIMP2_PURE int __CLRCALL_PURE_OR_CDECL _Tolower(int, const _Ctypevec*); _CRTIMP2_PURE int __CLRCALL_PURE_OR_CDECL _Toupper(int, const _Ctypevec*); -_CRTIMP2_PURE int __CLRCALL_PURE_OR_CDECL _Wcrtomb(_Out_ char*, wchar_t, mbstate_t*, const _Cvtvec*); +_CRTIMP2_PURE _Success_(return != -1) int __CLRCALL_PURE_OR_CDECL + _Wcrtomb(_Out_ char*, wchar_t, mbstate_t*, const _Cvtvec*); _CRTIMP2_PURE int __CLRCALL_PURE_OR_CDECL _Wcscoll( const wchar_t*, const wchar_t*, const wchar_t*, const wchar_t*, const _Collvec*); _CRTIMP2_PURE size_t __CLRCALL_PURE_OR_CDECL _Wcsxfrm(_Out_writes_(_End1 - _String1) _Post_readable_size_(return ) diff --git a/stl/src/StlLCMapStringA.cpp b/stl/src/StlLCMapStringA.cpp index 3236a5708b5..bb5651e3bce 100644 --- a/stl/src/StlLCMapStringA.cpp +++ b/stl/src/StlLCMapStringA.cpp @@ -29,7 +29,7 @@ // Exit: // Success: number of chars written to lpDestStr (including null terminator) // Failure: 0 -extern "C" int __cdecl __crtLCMapStringA(_In_z_ LPCWSTR LocaleName, _In_ DWORD dwMapFlags, +extern "C" int __cdecl __crtLCMapStringA(_In_opt_z_ LPCWSTR LocaleName, _In_ DWORD dwMapFlags, _In_reads_(cchSrc) LPCSTR lpSrcStr, _In_ int cchSrc, _Out_writes_opt_(cchDest) char* lpDestStr, _In_ int cchDest, _In_ int code_page, _In_ BOOL bError) { // LCMapString will map past the null terminator. We must find the null diff --git a/stl/src/StlLCMapStringW.cpp b/stl/src/StlLCMapStringW.cpp index da354609a2f..d388a2a7770 100644 --- a/stl/src/StlLCMapStringW.cpp +++ b/stl/src/StlLCMapStringW.cpp @@ -31,7 +31,7 @@ // else // number of wide characters written to destination (including null terminator) // Failure: 0 -extern "C" int __cdecl __crtLCMapStringW(_In_z_ LPCWSTR const locale_name, _In_ DWORD const map_flags, +extern "C" int __cdecl __crtLCMapStringW(_In_opt_z_ LPCWSTR const locale_name, _In_ DWORD const map_flags, _In_reads_(source_count) LPCWSTR const source, _In_ int source_count, _Out_writes_opt_(destination_count) wchar_t* const destination, _In_ int const destination_count) { // LCMapString will map past the null terminator. We must find the null terminator if it occurs in the string diff --git a/stl/src/awint.hpp b/stl/src/awint.hpp index 31077ed39fe..aad3ccbd768 100644 --- a/stl/src/awint.hpp +++ b/stl/src/awint.hpp @@ -122,8 +122,9 @@ BOOL __cdecl __crtFlsSetValue(__in DWORD dwFlsIndex, __in_opt PVOID lpFlsData); _CRTIMP2 BOOL __cdecl __crtInitializeCriticalSectionEx( __out LPCRITICAL_SECTION lpCriticalSection, __in DWORD dwSpinCount, __in DWORD Flags); +// N.B. Context is not used _CRTIMP2 BOOL __cdecl __crtInitOnceExecuteOnce( - _Inout_ PINIT_ONCE InitOnce, _In_ PINIT_ONCE_FN InitFn, _Inout_opt_ PVOID Parameter, _Out_opt_ LPVOID* Context); + _Inout_ PINIT_ONCE InitOnce, _In_ PINIT_ONCE_FN InitFn, _Inout_opt_ PVOID Parameter, LPVOID* Context); _CRTIMP2 HANDLE __cdecl __crtCreateEventExW(__in_opt LPSECURITY_ATTRIBUTES lpEventAttributes, __in_opt LPCWSTR lpName, __reserved DWORD dwFlags, __in DWORD dwDesiredAccess); @@ -158,7 +159,7 @@ _CRTIMP2 DWORD __cdecl __crtGetCurrentProcessorNumber(); _CRTIMP2 BOOLEAN __cdecl __crtCreateSymbolicLinkW( __in LPCWSTR lpSymlinkFileName, __in LPCWSTR lpTargetFileName, __in DWORD dwFlags); -_CRTIMP2 BOOL __cdecl __crtGetFileInformationByHandleEx(_In_ HANDLE hFile, +_CRTIMP2 _Success_(return ) BOOL __cdecl __crtGetFileInformationByHandleEx(_In_ HANDLE hFile, _In_ FILE_INFO_BY_HANDLE_CLASS FileInformationClass, _Out_ LPVOID lpFileInformation, _In_ DWORD dwBufferSize); _CRTIMP2 BOOL __cdecl __crtSetFileInformationByHandle(_In_ HANDLE hFile, @@ -350,11 +351,11 @@ _CRTIMP2 int __cdecl __crtCompareStringW(_In_z_ LPCWSTR _LocaleName, _In_ DWORD _In_reads_(_CchCount1) LPCWSTR _LpString1, _In_ int _CchCount1, _In_reads_(_CchCount2) LPCWSTR _LpString2, _In_ int _CchCount2); -_CRTIMP2 int __cdecl __crtLCMapStringA(_In_z_ LPCWSTR _LocaleName, _In_ DWORD _DwMapFlag, +_CRTIMP2 int __cdecl __crtLCMapStringA(_In_opt_z_ LPCWSTR _LocaleName, _In_ DWORD _DwMapFlag, _In_reads_(_CchSrc) LPCSTR _LpSrcStr, _In_ int _CchSrc, _Out_writes_opt_(_CchDest) char* _LpDestStr, _In_ int _CchDest, _In_ int _CodePage, _In_ BOOL _BError); -_CRTIMP2 int __cdecl __crtLCMapStringW(_In_z_ LPCWSTR _LocaleName, _In_ DWORD _DWMapFlag, +_CRTIMP2 int __cdecl __crtLCMapStringW(_In_opt_z_ LPCWSTR _LocaleName, _In_ DWORD _DWMapFlag, _In_reads_(_CchSrc) LPCWSTR _LpSrcStr, _In_ int _CchSrc, _Out_writes_opt_(_CchDest) wchar_t* _LpDestStr, _In_ int _CchDest); diff --git a/stl/src/excptptr.cpp b/stl/src/excptptr.cpp index 821697998c6..c1a828083d5 100644 --- a/stl/src/excptptr.cpp +++ b/stl/src/excptptr.cpp @@ -316,7 +316,8 @@ namespace { const auto _ExceptionObjectSize = static_cast(_PType->sizeOrOffset); const auto _AllocSize = sizeof(_ExceptionPtr_normal) + _ExceptionObjectSize; - auto _RxRaw = malloc(_AllocSize); + _Analysis_assume_(_AllocSize >= sizeof(_ExceptionPtr_normal)); + auto _RxRaw = malloc(_AllocSize); if (!_RxRaw) { _Dest = _ExceptionPtr_static::_Get(); return; @@ -398,33 +399,34 @@ namespace { } } // unnamed namespace -_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL __ExceptionPtrCreate(void* _Ptr) noexcept { +_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL __ExceptionPtrCreate(_Out_ void* _Ptr) noexcept { ::new (_Ptr) shared_ptr(); } -_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL __ExceptionPtrDestroy(void* _Ptr) noexcept { +_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL __ExceptionPtrDestroy(_Inout_ void* _Ptr) noexcept { static_cast*>(_Ptr)->~shared_ptr(); } -_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL __ExceptionPtrCopy(void* _Dest, const void* _Src) noexcept { +_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL __ExceptionPtrCopy(_Out_ void* _Dest, _In_ const void* _Src) noexcept { ::new (_Dest) shared_ptr(*static_cast*>(_Src)); } -_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL __ExceptionPtrAssign(void* _Dest, const void* _Src) noexcept { +_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL __ExceptionPtrAssign(_Inout_ void* _Dest, _In_ const void* _Src) noexcept { *static_cast*>(_Dest) = *static_cast*>(_Src); } -_CRTIMP2_PURE bool __CLRCALL_PURE_OR_CDECL __ExceptionPtrCompare(const void* _Lhs, const void* _Rhs) noexcept { +_CRTIMP2_PURE bool __CLRCALL_PURE_OR_CDECL __ExceptionPtrCompare( + _In_ const void* _Lhs, _In_ const void* _Rhs) noexcept { return *static_cast*>(_Lhs) == *static_cast*>(_Rhs); } -_CRTIMP2_PURE bool __CLRCALL_PURE_OR_CDECL __ExceptionPtrToBool(const void* _Ptr) noexcept { +_CRTIMP2_PURE bool __CLRCALL_PURE_OR_CDECL __ExceptionPtrToBool(_In_ const void* _Ptr) noexcept { return static_cast(*static_cast*>(_Ptr)); } -_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL __ExceptionPtrSwap(void* _Lhs, void* _Rhs) noexcept { +_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL __ExceptionPtrSwap(_Inout_ void* _Lhs, _Inout_ void* _Rhs) noexcept { static_cast*>(_Lhs)->swap( *static_cast*>(_Rhs)); } @@ -446,7 +448,7 @@ _CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL __ExceptionPtrCurrentException(void* } } -[[noreturn]] _CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL __ExceptionPtrRethrow(const void* _PtrRaw) { +[[noreturn]] _CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL __ExceptionPtrRethrow(_In_ const void* _PtrRaw) { const shared_ptr* _Ptr = static_cast*>(_PtrRaw); // throwing a bad_exception if they give us a nullptr exception_ptr if (!*_Ptr) { @@ -488,6 +490,8 @@ _CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL __ExceptionPtrCurrentException(void* // Alloc memory on stack for exception object. This might cause a stack overflow SEH exception, or another C++ // exception when copying the C++ exception object. In that case, we just let that become the thrown exception. + +#pragma warning(suppress : 6255) // _alloca indicates failure by raising a stack overflow exception void* _PExceptionBuffer = alloca(_PType->sizeOrOffset); _CopyExceptionObject(_PExceptionBuffer, _CppRecord.params.pExceptionObject, _PType #if _EH_RELATIVE_TYPEINFO @@ -507,7 +511,7 @@ _CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL __ExceptionPtrCurrentException(void* } _CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL __ExceptionPtrCopyException( - void* _Ptr, const void* _PExceptRaw, const void* _PThrowRaw) noexcept { + _Inout_ void* _Ptr, _In_ const void* _PExceptRaw, _In_ const void* _PThrowRaw) noexcept { _EXCEPTION_RECORD _Record; _PopulateCppExceptionRecord(_Record, _PExceptRaw, static_cast(_PThrowRaw)); _Assign_cpp_exception_ptr_from_record( diff --git a/stl/src/filesystem.cpp b/stl/src/filesystem.cpp index ca312314f04..bc9f40abe4e 100644 --- a/stl/src/filesystem.cpp +++ b/stl/src/filesystem.cpp @@ -261,15 +261,15 @@ namespace { _EXTERN_C -[[nodiscard]] __std_ulong_and_error __stdcall __std_fs_get_full_path_name( - const wchar_t* _Source, unsigned long _Target_size, wchar_t* _Target) noexcept { // calls GetFullPathNameW +[[nodiscard]] __std_ulong_and_error __stdcall __std_fs_get_full_path_name(_In_z_ const wchar_t* _Source, + _In_ unsigned long _Target_size, _Out_writes_z_(_Target_size) wchar_t* _Target) noexcept { // calls GetFullPathNameW const auto _Result = GetFullPathNameW(_Source, _Target_size, _Target, nullptr); return {_Result, _Result == 0 ? __std_win_error{GetLastError()} : __std_win_error::_Success}; } -[[nodiscard]] __std_win_error __stdcall __std_fs_open_handle(__std_fs_file_handle* const _Handle, - const wchar_t* const _File_name, const __std_access_rights _Desired_access, - const __std_fs_file_flags _Flags) noexcept { // calls CreateFile2 or CreateFileW +[[nodiscard]] __std_win_error __stdcall __std_fs_open_handle(_Out_ __std_fs_file_handle* const _Handle, + _In_z_ const wchar_t* const _File_name, _In_ const __std_access_rights _Desired_access, + _In_ const __std_fs_file_flags _Flags) noexcept { // calls CreateFile2 or CreateFileW const HANDLE _Result = __vcp_CreateFile(_File_name, static_cast(_Desired_access), FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, nullptr, OPEN_EXISTING, static_cast(_Flags), 0); @@ -283,9 +283,10 @@ void __stdcall __std_fs_close_handle(const __std_fs_file_handle _Handle) noexcep } } -[[nodiscard]] __std_win_error __stdcall __std_fs_get_file_attributes_by_handle(const __std_fs_file_handle _Handle, - unsigned long* const - _File_attributes) noexcept { // read the attributes from _Handle and store it in _File_attributes +[[nodiscard]] _Success_(return == __std_win_error::_Success) __std_win_error + __stdcall __std_fs_get_file_attributes_by_handle( + _In_ const __std_fs_file_handle _Handle, _Out_ unsigned long* const _File_attributes) noexcept { + // read the attributes from _Handle and store it in _File_attributes __std_win_error _Last_error; const HANDLE _As_plain_handle = reinterpret_cast(_Handle); @@ -312,9 +313,10 @@ void __stdcall __std_fs_close_handle(const __std_fs_file_handle _Handle) noexcep return _Last_error; } -[[nodiscard]] __std_ulong_and_error __stdcall __std_fs_get_final_path_name_by_handle(const __std_fs_file_handle _Handle, - wchar_t* const _Target, const unsigned long _Target_size, - const __std_fs_volume_name_kind _Flags) noexcept { // calls GetFinalPathNameByHandleW +[[nodiscard]] __std_ulong_and_error __stdcall __std_fs_get_final_path_name_by_handle( + _In_ const __std_fs_file_handle _Handle, _Out_writes_z_(_Target_size) wchar_t* const _Target, + _In_ const unsigned long _Target_size, + _In_ const __std_fs_volume_name_kind _Flags) noexcept { // calls GetFinalPathNameByHandleW const auto _Result = __vcrt_GetFinalPathNameByHandleW( reinterpret_cast(_Handle), _Target, _Target_size, static_cast(_Flags)); return {_Result, _Result == 0 ? __std_win_error{GetLastError()} : __std_win_error::_Success}; @@ -323,8 +325,8 @@ void __stdcall __std_fs_close_handle(const __std_fs_file_handle _Handle) noexcep static_assert(sizeof(WIN32_FIND_DATAW) == sizeof(__std_fs_find_data)); static_assert(alignof(WIN32_FIND_DATAW) == alignof(__std_fs_find_data)); -[[nodiscard]] __std_win_error __stdcall __std_fs_directory_iterator_open( - const wchar_t* const _Path_spec, __std_fs_dir_handle* const _Handle, __std_fs_find_data* const _Results) noexcept { +[[nodiscard]] __std_win_error __stdcall __std_fs_directory_iterator_open(_In_z_ const wchar_t* const _Path_spec, + _Inout_ __std_fs_dir_handle* const _Handle, _Out_ __std_fs_find_data* const _Results) noexcept { __std_fs_directory_iterator_close(*_Handle); *_Handle = __std_fs_dir_handle{reinterpret_cast( FindFirstFileExW(_Path_spec, FindExInfoBasic, _Results, FindExSearchNameMatch, nullptr, 0))}; @@ -350,14 +352,14 @@ static_assert(alignof(WIN32_FIND_DATAW) == alignof(__std_fs_find_data)); return __std_win_error{GetLastError()}; } -void __stdcall __std_fs_directory_iterator_close(const __std_fs_dir_handle _Handle) noexcept { +void __stdcall __std_fs_directory_iterator_close(_In_ const __std_fs_dir_handle _Handle) noexcept { if (_Handle != __std_fs_dir_handle::_Invalid && !FindClose(reinterpret_cast(_Handle))) { terminate(); } } [[nodiscard]] __std_win_error __stdcall __std_fs_directory_iterator_advance( - const __std_fs_dir_handle _Handle, __std_fs_find_data* const _Results) noexcept { + _In_ const __std_fs_dir_handle _Handle, _Out_ __std_fs_find_data* const _Results) noexcept { if (FindNextFileW(reinterpret_cast(_Handle), reinterpret_cast(_Results))) { return __std_win_error::_Success; } @@ -379,15 +381,17 @@ void __stdcall __std_fs_directory_iterator_close(const __std_fs_dir_handle _Hand return __std_code_page{CP_ACP}; } -[[nodiscard]] __std_fs_convert_result __stdcall __std_fs_convert_narrow_to_wide(const __std_code_page _Code_page, - const char* const _Input_str, const int _Input_len, wchar_t* const _Output_str, const int _Output_len) noexcept { +[[nodiscard]] __std_fs_convert_result __stdcall __std_fs_convert_narrow_to_wide(_In_ const __std_code_page _Code_page, + _In_reads_(_Input_len) const char* const _Input_str, _In_ const int _Input_len, + _Out_writes_opt_(_Output_len) wchar_t* const _Output_str, _In_ const int _Output_len) noexcept { const int _Len = MultiByteToWideChar( static_cast(_Code_page), MB_ERR_INVALID_CHARS, _Input_str, _Input_len, _Output_str, _Output_len); return {_Len, _Len == 0 ? __std_win_error{GetLastError()} : __std_win_error::_Success}; } -[[nodiscard]] __std_fs_convert_result __stdcall __std_fs_convert_wide_to_narrow(const __std_code_page _Code_page, - const wchar_t* const _Input_str, const int _Input_len, char* const _Output_str, const int _Output_len) noexcept { +[[nodiscard]] __std_fs_convert_result __stdcall __std_fs_convert_wide_to_narrow(_In_ const __std_code_page _Code_page, + _In_reads_(_Input_len) const wchar_t* const _Input_str, _In_ const int _Input_len, + _Out_writes_opt_(_Output_len) char* const _Output_str, _In_ const int _Output_len) noexcept { __std_fs_convert_result _Result; if (_Code_page == __std_code_page{CP_UTF8} || _Code_page == __std_code_page{54936}) { @@ -421,8 +425,8 @@ void __stdcall __std_fs_directory_iterator_close(const __std_fs_dir_handle _Hand return _Result; } -[[nodiscard]] __std_fs_copy_file_result __stdcall __std_fs_copy_file(const wchar_t* const _Source, - const wchar_t* const _Target, __std_fs_copy_options _Options) noexcept { // copy _Source to _Target +[[nodiscard]] __std_fs_copy_file_result __stdcall __std_fs_copy_file(_In_z_ const wchar_t* const _Source, + _In_z_ const wchar_t* const _Target, _In_ __std_fs_copy_options _Options) noexcept { // copy _Source to _Target _Options &= __std_fs_copy_options::_Existing_mask; if (_Options != __std_fs_copy_options::_Overwrite_existing) { const __std_fs_copy_file_result _First_try_result = @@ -486,7 +490,8 @@ void __stdcall __std_fs_directory_iterator_close(const __std_fs_dir_handle _Hand return __vcp_Copyfile(_Source, _Target, /* _Fail_if_exists = */ false); } -__std_win_error __stdcall __std_fs_get_file_id(__std_fs_file_id* const _Id, const wchar_t* const _Path) noexcept { +_Success_(return == __std_win_error::_Success) __std_win_error + __stdcall __std_fs_get_file_id(_Out_ __std_fs_file_id* const _Id, _In_z_ const wchar_t* const _Path) noexcept { __std_win_error _Last_error; const _STD _Fs_file _Handle( _Path, __std_access_rights::_File_read_attributes, __std_fs_file_flags::_Backup_semantics, &_Last_error); @@ -498,7 +503,8 @@ __std_win_error __stdcall __std_fs_get_file_id(__std_fs_file_id* const _Id, cons static_assert(alignof(FILE_ID_INFO) == alignof(__std_fs_file_id)); if (__vcrt_GetFileInformationByHandleEx( _Handle._Get(), FileIdInfo, reinterpret_cast(_Id), sizeof(*_Id)) - != 0) { // if we could get FILE_ID_INFO, use that as the source of truth + != 0) { + // if we could get FILE_ID_INFO, use that as the source of truth return __std_win_error::_Success; } @@ -528,12 +534,12 @@ __std_win_error __stdcall __std_fs_get_file_id(__std_fs_file_id* const _Id, cons } [[nodiscard]] __std_win_error __stdcall __std_fs_create_directory_symbolic_link( - const wchar_t* const _Symlink_file_name, const wchar_t* const _Target_file_name) noexcept { + _In_z_ const wchar_t* const _Symlink_file_name, _In_z_ const wchar_t* const _Target_file_name) noexcept { return _Create_symlink(_Symlink_file_name, _Target_file_name, SYMBOLIC_LINK_FLAG_DIRECTORY); } [[nodiscard]] __std_win_error __stdcall __std_fs_create_hard_link( - const wchar_t* const _File_name, const wchar_t* const _Existing_file_name) noexcept { + _In_z_ const wchar_t* const _File_name, _In_z_ const wchar_t* const _Existing_file_name) noexcept { #if defined(_CRT_APP) (void) _File_name; (void) _Existing_file_name; @@ -548,12 +554,12 @@ __std_win_error __stdcall __std_fs_get_file_id(__std_fs_file_id* const _Id, cons } [[nodiscard]] __std_win_error __stdcall __std_fs_create_symbolic_link( - const wchar_t* const _Symlink_file_name, const wchar_t* const _Target_file_name) noexcept { + _In_z_ const wchar_t* const _Symlink_file_name, _In_z_ const wchar_t* const _Target_file_name) noexcept { return _Create_symlink(_Symlink_file_name, _Target_file_name, 0); } -[[nodiscard]] __std_win_error __stdcall __std_fs_read_reparse_data_buffer( - const __std_fs_file_handle _Handle, void* const _Buffer, const unsigned long _Buffer_size) noexcept { +[[nodiscard]] __std_win_error __stdcall __std_fs_read_reparse_data_buffer(_In_ const __std_fs_file_handle _Handle, + _Out_writes_bytes_(_Buffer_size) void* const _Buffer, _In_ const unsigned long _Buffer_size) noexcept { unsigned long _Bytes_returned; // If DeviceIoControl fails, it returns 0 and _Bytes_returned is 0. if (0 @@ -565,8 +571,9 @@ __std_win_error __stdcall __std_fs_get_file_id(__std_fs_file_id* const _Id, cons return __std_win_error::_Success; } -[[nodiscard]] __std_win_error __stdcall __std_fs_read_name_from_reparse_data_buffer( - __std_fs_reparse_data_buffer* const _Buffer, wchar_t** const _Offset, unsigned short* const _Length) noexcept { +[[nodiscard]] _Success_(return == __std_win_error::_Success) __std_win_error + __stdcall __std_fs_read_name_from_reparse_data_buffer(_In_ __std_fs_reparse_data_buffer* const _Buffer, + _Out_ wchar_t** const _Offset, _Out_ unsigned short* const _Length) noexcept { if (_Buffer->_Reparse_tag == IO_REPARSE_TAG_SYMLINK) { auto& _Symlink_buffer = _Buffer->_Symbolic_link_reparse_buffer; const unsigned short _Temp_length = _Symlink_buffer._Print_name_length / sizeof(wchar_t); @@ -586,7 +593,7 @@ __std_win_error __stdcall __std_fs_get_file_id(__std_fs_file_id* const _Id, cons } [[nodiscard]] __std_win_error __stdcall __std_fs_set_last_write_time( - const long long _Last_write_filetime, const wchar_t* const _Path) noexcept { + _In_ const long long _Last_write_filetime, _In_z_ const wchar_t* const _Path) noexcept { __std_win_error _Last_error; const _STD _Fs_file _Handle( _Path, __std_access_rights::_File_write_attributes, __std_fs_file_flags::_Backup_semantics, &_Last_error); @@ -601,7 +608,7 @@ __std_win_error __stdcall __std_fs_get_file_id(__std_fs_file_id* const _Id, cons return __std_win_error{GetLastError()}; } -[[nodiscard]] __std_fs_remove_result __stdcall __std_fs_remove(const wchar_t* const _Target) noexcept { +[[nodiscard]] __std_fs_remove_result __stdcall __std_fs_remove(_In_z_ const wchar_t* const _Target) noexcept { // remove _Target without caring whether _Target is a file or directory __std_win_error _Last_error; #if _STL_ALWAYS_HAS_SetFileInformationByHandle @@ -675,7 +682,7 @@ __std_win_error __stdcall __std_fs_get_file_id(__std_fs_file_id* const _Id, cons } [[nodiscard]] __std_win_error __stdcall __std_fs_change_permissions( - const wchar_t* const _Path, const bool _Follow_symlinks, const bool _Readonly) noexcept { + _In_z_ const wchar_t* const _Path, _In_ const bool _Follow_symlinks, _In_ const bool _Readonly) noexcept { const DWORD _Old_attributes = GetFileAttributesW(_Path); if (_Old_attributes == INVALID_FILE_ATTRIBUTES) { return __std_win_error{GetLastError()}; @@ -721,7 +728,7 @@ __std_win_error __stdcall __std_fs_get_file_id(__std_fs_file_id* const _Id, cons } [[nodiscard]] __std_win_error __stdcall __std_fs_rename( - const wchar_t* const _Source, const wchar_t* const _Target) noexcept { + _In_z_ const wchar_t* const _Source, _In_z_ const wchar_t* const _Target) noexcept { if (MoveFileExW(_Source, _Target, MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING)) { return __std_win_error::_Success; } @@ -730,7 +737,7 @@ __std_win_error __stdcall __std_fs_get_file_id(__std_fs_file_id* const _Id, cons } [[nodiscard]] __std_win_error __stdcall __std_fs_resize_file( - const wchar_t* const _Target, const uintmax_t _New_size) noexcept { + _In_z_ const wchar_t* const _Target, const uintmax_t _New_size) noexcept { __std_win_error _Err; const _STD _Fs_file _Handle(_Target, __std_access_rights::_File_generic_write, __std_fs_file_flags::_None, &_Err); if (_Err != __std_win_error::_Success) { @@ -746,8 +753,9 @@ __std_win_error __stdcall __std_fs_get_file_id(__std_fs_file_id* const _Id, cons return __std_win_error::_Success; } -[[nodiscard]] __std_win_error __stdcall __std_fs_space(const wchar_t* const _Target, uintmax_t* const _Available, - uintmax_t* const _Total_bytes, uintmax_t* const _Free_bytes) noexcept { +[[nodiscard]] __std_win_error __stdcall __std_fs_space(_In_z_ const wchar_t* const _Target, + _Out_ uintmax_t* const _Available, _Out_ uintmax_t* const _Total_bytes, + _Out_ uintmax_t* const _Free_bytes) noexcept { // get capacity information for the volume on which the file _Target resides static_assert(sizeof(uintmax_t) == sizeof(ULARGE_INTEGER) && alignof(uintmax_t) == alignof(ULARGE_INTEGER), "Size and alignment must match for reinterpret_cast"); @@ -823,7 +831,8 @@ __std_win_error __stdcall __std_fs_get_file_id(__std_fs_file_id* const _Id, cons return __std_win_error{GetLastError()}; } -[[nodiscard]] __std_ulong_and_error __stdcall __std_fs_get_temp_path(wchar_t* const _Target) noexcept { +[[nodiscard]] _Success_(return._Error == __std_win_error::_Success) __std_ulong_and_error + __stdcall __std_fs_get_temp_path(_Out_writes_z_(__std_fs_temp_path_max) wchar_t* const _Target) noexcept { // calls GetTempPathW // If getting the path failed, returns 0 size; otherwise, returns the size of the // expected directory. If the path could be resolved to an existing directory, @@ -881,8 +890,9 @@ struct alignas(long long) _Aligned_file_attrs { } }; -[[nodiscard]] __std_win_error __stdcall __std_fs_get_stats(const wchar_t* const _Path, __std_fs_stats* const _Stats, - __std_fs_stats_flags _Flags, const __std_fs_file_attr _Symlink_attribute_hint) noexcept { +[[nodiscard]] _Success_(return == __std_win_error::_Success) __std_win_error + __stdcall __std_fs_get_stats(_In_z_ const wchar_t* const _Path, _Out_ __std_fs_stats* const _Stats, + _In_ __std_fs_stats_flags _Flags, _In_ const __std_fs_file_attr _Symlink_attribute_hint) noexcept { static_assert((offsetof(_Aligned_file_attrs, _Data._Last_write_time) % 8) == 0, "_Last_write_time not aligned"); static_assert(sizeof(_File_attr_data) == sizeof(WIN32_FILE_ATTRIBUTE_DATA)); static_assert(alignof(_File_attr_data) == alignof(WIN32_FILE_ATTRIBUTE_DATA)); @@ -1034,7 +1044,7 @@ struct alignas(long long) _Aligned_file_attrs { } [[nodiscard]] __std_fs_create_directory_result __stdcall __std_fs_create_directory( - const wchar_t* const _New_directory) noexcept { + _In_z_ const wchar_t* const _New_directory) noexcept { if (CreateDirectoryW(_New_directory, nullptr)) { return {true, __std_win_error::_Success}; } @@ -1055,7 +1065,7 @@ struct alignas(long long) _Aligned_file_attrs { // TRANSITION, ABI: __std_fs_create_directory_template() is preserved for binary compatibility [[nodiscard]] __std_fs_create_directory_result __stdcall __std_fs_create_directory_template( - const wchar_t* const _Template_directory, const wchar_t* const _New_directory) noexcept { + _In_z_ const wchar_t* const _Template_directory, _In_z_ const wchar_t* const _New_directory) noexcept { #if defined(_CRT_APP) (void) _Template_directory; return __std_fs_create_directory(_New_directory); @@ -1073,8 +1083,9 @@ struct alignas(long long) _Aligned_file_attrs { #endif // defined(_CRT_APP) } -[[nodiscard]] __std_ulong_and_error __stdcall __std_fs_get_current_path( - const unsigned long _Target_size, wchar_t* const _Target) noexcept { +[[nodiscard]] _Success_(return._Error == __std_win_error::_Success) __std_ulong_and_error + __stdcall __std_fs_get_current_path( + _In_ const unsigned long _Target_size, _Out_writes_z_(_Target_size) wchar_t* const _Target) noexcept { // If getting the path failed, GetCurrentDirectoryW returns 0; otherwise, returns the size of the expected // directory. const auto _Size = GetCurrentDirectoryW(_Target_size, _Target); @@ -1085,7 +1096,7 @@ struct alignas(long long) _Aligned_file_attrs { return {_Size, __std_win_error::_Success}; } -[[nodiscard]] __std_win_error __stdcall __std_fs_set_current_path(const wchar_t* const _Target) noexcept { +[[nodiscard]] __std_win_error __stdcall __std_fs_set_current_path(_In_z_ const wchar_t* const _Target) noexcept { // If setting the path failed, SetCurrentDirectoryW returns 0; otherwise returns non-zero. const auto _Succeeded = SetCurrentDirectoryW(_Target); if (_Succeeded == 0) { diff --git a/stl/src/winapinls.cpp b/stl/src/winapinls.cpp index 55badb6a18b..bf71f4479b7 100644 --- a/stl/src/winapinls.cpp +++ b/stl/src/winapinls.cpp @@ -622,8 +622,9 @@ extern "C" int __cdecl __crtDownlevelLCIDToLocaleName(LCID lcid, LPWSTR outLocal } // __crtCompareStringEx() - Wrapper for CompareStringEx(). -extern "C" int __cdecl __crtCompareStringEx( - LPCWSTR lpLocaleName, DWORD dwCmpFlags, LPCWSTR lpString1, int cchCount1, LPCWSTR lpString2, int cchCount2) { +extern "C" int __cdecl __crtCompareStringEx(_In_opt_ LPCWSTR lpLocaleName, _In_ DWORD dwCmpFlags, + _In_NLS_string_(cchCount1) LPCWSTR lpString1, _In_ int cchCount1, _In_NLS_string_(cchCount2) LPCWSTR lpString2, + _In_ int cchCount2) { // use CompareStringEx if it is available (only on Windows Vista+)... IFDYNAMICGETCACHEDFUNCTION(PFNCOMPARESTRINGEX, CompareStringEx, pfCompareStringEx) { return pfCompareStringEx( @@ -636,8 +637,9 @@ extern "C" int __cdecl __crtCompareStringEx( } // __crtLCMapStringEx() - Wrapper for LCMapStringEx(). -extern "C" int __cdecl __crtLCMapStringEx( - LPCWSTR lpLocaleName, DWORD dwMapFlags, LPCWSTR lpSrcStr, int cchSrc, LPWSTR lpDestStr, int cchDest) { +extern "C" int __cdecl __crtLCMapStringEx(_In_opt_ LPCWSTR lpLocaleName, _In_ DWORD dwMapFlags, + _In_reads_(cchSrc) LPCWSTR lpSrcStr, _In_ int cchSrc, _Out_writes_opt_(cchDest) LPWSTR lpDestStr, + _In_ int cchDest) { // use LCMapStringEx if it is available (only on Windows Vista+)... IFDYNAMICGETCACHEDFUNCTION(PFNLCMAPSTRINGEX, LCMapStringEx, pfLCMapStringEx) { return pfLCMapStringEx(lpLocaleName, dwMapFlags, lpSrcStr, cchSrc, lpDestStr, cchDest, nullptr, nullptr, 0); @@ -649,8 +651,8 @@ extern "C" int __cdecl __crtLCMapStringEx( // __crtGetLocaleInfoEx() - Wrapper for GetLocaleInfoEx(). -extern "C" int __cdecl __crtGetLocaleInfoEx( - LPCWSTR const lpLocaleName, LCTYPE const LCType, LPWSTR const lpLCData, int const cchData) { +extern "C" int __cdecl __crtGetLocaleInfoEx(_In_opt_ LPCWSTR const lpLocaleName, _In_ LCTYPE const LCType, + _Out_opt_ LPWSTR const lpLCData, _In_ int const cchData) { IFDYNAMICGETCACHEDFUNCTION(PFNGETLOCALEINFOEX, GetLocaleInfoEx, pfGetLocaleInfoEx) { return pfGetLocaleInfoEx(lpLocaleName, LCType, lpLCData, cchData); } diff --git a/stl/src/winapisupp.cpp b/stl/src/winapisupp.cpp index 202995a9e1f..84b9e8ab9aa 100644 --- a/stl/src/winapisupp.cpp +++ b/stl/src/winapisupp.cpp @@ -131,7 +131,7 @@ extern "C" BOOL __cdecl __crtIsPackagedApp() { #if _STL_WIN32_WINNT < _WIN32_WINNT_WS03 -extern "C" DWORD __cdecl __crtFlsAlloc(PFLS_CALLBACK_FUNCTION const lpCallback) { +extern "C" DWORD __cdecl __crtFlsAlloc(__in PFLS_CALLBACK_FUNCTION const lpCallback) { // use FlsAlloc if it is available (only on Windows Server 2003+)... IFDYNAMICGETCACHEDFUNCTION(PFNFLSALLOC, FlsAlloc, pfFlsAlloc) { return pfFlsAlloc(lpCallback); @@ -141,7 +141,7 @@ extern "C" DWORD __cdecl __crtFlsAlloc(PFLS_CALLBACK_FUNCTION const lpCallback) return TlsAlloc(); } -extern "C" BOOL __cdecl __crtFlsFree(DWORD const dwFlsIndex) { +extern "C" BOOL __cdecl __crtFlsFree(__in DWORD const dwFlsIndex) { // use FlsFree if it is available (only on Windows Server 2003+)... IFDYNAMICGETCACHEDFUNCTION(PFNFLSFREE, FlsFree, pfFlsFree) { return pfFlsFree(dwFlsIndex); @@ -151,7 +151,7 @@ extern "C" BOOL __cdecl __crtFlsFree(DWORD const dwFlsIndex) { return TlsFree(dwFlsIndex); } -extern "C" PVOID __cdecl __crtFlsGetValue(DWORD const dwFlsIndex) { +extern "C" PVOID __cdecl __crtFlsGetValue(__in DWORD const dwFlsIndex) { // use FlsGetValue if it is available (only on Windows Server 2003+)... IFDYNAMICGETCACHEDFUNCTION(PFNFLSGETVALUE, FlsGetValue, pfFlsGetValue) { return pfFlsGetValue(dwFlsIndex); @@ -161,7 +161,7 @@ extern "C" PVOID __cdecl __crtFlsGetValue(DWORD const dwFlsIndex) { return TlsGetValue(dwFlsIndex); } -extern "C" BOOL __cdecl __crtFlsSetValue(DWORD const dwFlsIndex, PVOID const lpFlsData) { +extern "C" BOOL __cdecl __crtFlsSetValue(__in DWORD const dwFlsIndex, __in_opt PVOID const lpFlsData) { // use FlsSetValue if it is available (only on Windows Server 2003+)... IFDYNAMICGETCACHEDFUNCTION(PFNFLSSETVALUE, FlsSetValue, pfFlsSetValue) { return pfFlsSetValue(dwFlsIndex, lpFlsData); @@ -183,11 +183,12 @@ extern "C" ULONGLONG __cdecl __crtGetTickCount64() { } // ...otherwise fall back to using GetTickCount. +#pragma warning(suppress : 28159) // Consider using 'GetTickCount64' instead of 'GetTickCount'. return GetTickCount(); } extern "C" BOOL __cdecl __crtInitializeCriticalSectionEx( - LPCRITICAL_SECTION const lpCriticalSection, DWORD const dwSpinCount, DWORD const Flags) { + __out LPCRITICAL_SECTION const lpCriticalSection, __in DWORD const dwSpinCount, __in DWORD const Flags) { // use InitializeCriticalSectionEx if it is available (only on Windows Vista+)... IFDYNAMICGETCACHEDFUNCTION( PFNINITIALIZECRITICALSECTIONEX, InitializeCriticalSectionEx, pfInitializeCriticalSectionEx) { @@ -199,8 +200,8 @@ extern "C" BOOL __cdecl __crtInitializeCriticalSectionEx( return TRUE; } -extern "C" BOOL __cdecl __crtInitOnceExecuteOnce( - PINIT_ONCE const InitOnce, PINIT_ONCE_FN const InitFn, PVOID const Parameter, LPVOID* const Context) { +extern "C" BOOL __cdecl __crtInitOnceExecuteOnce(_Inout_ PINIT_ONCE const InitOnce, _In_ PINIT_ONCE_FN const InitFn, + _Inout_opt_ PVOID const Parameter, LPVOID* const Context) { // use InitOnceExecuteOnce if it is available (only on Windows Vista+)... IFDYNAMICGETCACHEDFUNCTION(PFNINITONCEEXECUTEONCE, InitOnceExecuteOnce, pfInitOnceExecuteOnce) { return pfInitOnceExecuteOnce(InitOnce, InitFn, Parameter, Context); @@ -242,8 +243,8 @@ extern "C" BOOL __cdecl __crtInitOnceExecuteOnce( } } -extern "C" HANDLE __cdecl __crtCreateEventExW(LPSECURITY_ATTRIBUTES const lpEventAttributes, LPCWSTR const lpName, - DWORD const dwFlags, DWORD const dwDesiredAccess) { +extern "C" HANDLE __cdecl __crtCreateEventExW(__in_opt LPSECURITY_ATTRIBUTES const lpEventAttributes, + __in_opt LPCWSTR const lpName, __reserved DWORD const dwFlags, __in DWORD const dwDesiredAccess) { // use CreateEventEx if it is available (only on Windows Vista+)... IFDYNAMICGETCACHEDFUNCTION(PFNCREATEEVENTEXW, CreateEventExW, pfCreateEventExW) { return pfCreateEventExW(lpEventAttributes, lpName, dwFlags, dwDesiredAccess); @@ -254,9 +255,9 @@ extern "C" HANDLE __cdecl __crtCreateEventExW(LPSECURITY_ATTRIBUTES const lpEven lpEventAttributes, dwFlags & CREATE_EVENT_MANUAL_RESET, dwFlags & CREATE_EVENT_INITIAL_SET, lpName); } -extern "C" HANDLE __cdecl __crtCreateSemaphoreExW(LPSECURITY_ATTRIBUTES const lpSemaphoreAttributes, - LONG const lInitialCount, LONG const lMaximumCount, LPCWSTR const lpName, DWORD const dwFlags, - DWORD const dwDesiredAccess) { +extern "C" HANDLE __cdecl __crtCreateSemaphoreExW(__in_opt LPSECURITY_ATTRIBUTES const lpSemaphoreAttributes, + __in LONG const lInitialCount, __in LONG const lMaximumCount, __in_opt LPCWSTR const lpName, + __reserved DWORD const dwFlags, __in DWORD const dwDesiredAccess) { // use CreateSemaphoreEx if it is available (only on Windows Vista+)... IFDYNAMICGETCACHEDFUNCTION(PFNCREATESEMAPHOREEXW, CreateSemaphoreExW, pfCreateSemaphoreExW) { return pfCreateSemaphoreExW( @@ -273,7 +274,7 @@ extern "C" HANDLE __cdecl __crtCreateSemaphoreExW(LPSECURITY_ATTRIBUTES const lp } extern "C" PTP_TIMER __cdecl __crtCreateThreadpoolTimer( - PTP_TIMER_CALLBACK const pfnti, PVOID const pv, PTP_CALLBACK_ENVIRON const pcbe) { + __in PTP_TIMER_CALLBACK const pfnti, __inout_opt PVOID const pv, __in_opt PTP_CALLBACK_ENVIRON const pcbe) { // use CreateThreadpoolTimer if it is available (only on Windows Vista+)... IFDYNAMICGETCACHEDFUNCTION(PFNCREATETHREADPOOLTIMER, CreateThreadpoolTimer, pfCreateThreadpoolTimer) { return pfCreateThreadpoolTimer(pfnti, pv, pcbe); @@ -283,8 +284,8 @@ extern "C" PTP_TIMER __cdecl __crtCreateThreadpoolTimer( return nullptr; } -extern "C" VOID __cdecl __crtSetThreadpoolTimer( - PTP_TIMER const pti, PFILETIME const pftDueTime, DWORD const msPeriod, DWORD const msWindowLength) { +extern "C" VOID __cdecl __crtSetThreadpoolTimer(__inout PTP_TIMER const pti, __in_opt PFILETIME const pftDueTime, + __in DWORD const msPeriod, __in_opt DWORD const msWindowLength) { // use SetThreadpoolTimer if it is available (only on Windows Vista+)... IFDYNAMICGETCACHEDFUNCTION(PFNSETTHREADPOOLTIMER, SetThreadpoolTimer, pfSetThreadpoolTimer) { pfSetThreadpoolTimer(pti, pftDueTime, msPeriod, msWindowLength); @@ -294,7 +295,8 @@ extern "C" VOID __cdecl __crtSetThreadpoolTimer( return; } -extern "C" VOID __cdecl __crtWaitForThreadpoolTimerCallbacks(PTP_TIMER const pti, BOOL const fCancelPendingCallbacks) { +extern "C" VOID __cdecl __crtWaitForThreadpoolTimerCallbacks( + __inout PTP_TIMER const pti, __in BOOL const fCancelPendingCallbacks) { // use WaitForThreadpoolTimerCallbacks if it is available (only on Windows Vista+)... IFDYNAMICGETCACHEDFUNCTION( PFNWAITFORTHREADPOOLTIMERCALLBACKS, WaitForThreadpoolTimerCallbacks, pfWaitForThreadpoolTimerCallbacks) { @@ -305,7 +307,7 @@ extern "C" VOID __cdecl __crtWaitForThreadpoolTimerCallbacks(PTP_TIMER const pti return; } -extern "C" VOID __cdecl __crtCloseThreadpoolTimer(PTP_TIMER const pti) { +extern "C" VOID __cdecl __crtCloseThreadpoolTimer(__inout PTP_TIMER const pti) { // use CloseThreadpoolTimer if it is available (only on Windows Vista+)... IFDYNAMICGETCACHEDFUNCTION(PFNCLOSETHREADPOOLTIMER, CloseThreadpoolTimer, pfCloseThreadpoolTimer) { pfCloseThreadpoolTimer(pti); @@ -316,7 +318,7 @@ extern "C" VOID __cdecl __crtCloseThreadpoolTimer(PTP_TIMER const pti) { } extern "C" PTP_WAIT __cdecl __crtCreateThreadpoolWait( - PTP_WAIT_CALLBACK const pfnwa, PVOID const pv, PTP_CALLBACK_ENVIRON const pcbe) { + __in PTP_WAIT_CALLBACK const pfnwa, __inout_opt PVOID const pv, __in_opt PTP_CALLBACK_ENVIRON const pcbe) { // use CreateThreadpoolWait if it is available (only on Windows Vista+)... IFDYNAMICGETCACHEDFUNCTION(PFNCREATETHREADPOOLWAIT, CreateThreadpoolWait, pfCreateThreadpoolWait) { return pfCreateThreadpoolWait(pfnwa, pv, pcbe); @@ -326,7 +328,8 @@ extern "C" PTP_WAIT __cdecl __crtCreateThreadpoolWait( return nullptr; } -extern "C" VOID __cdecl __crtSetThreadpoolWait(PTP_WAIT const pwa, HANDLE const h, PFILETIME const pftTimeout) { +extern "C" VOID __cdecl __crtSetThreadpoolWait( + __inout PTP_WAIT const pwa, __in_opt HANDLE const h, __in_opt PFILETIME const pftTimeout) { // use SetThreadpoolWait if it is available (only on Windows Vista+)... IFDYNAMICGETCACHEDFUNCTION(PFNSETTHREADPOOLWAIT, SetThreadpoolWait, pfSetThreadpoolWait) { pfSetThreadpoolWait(pwa, h, pftTimeout); @@ -335,7 +338,7 @@ extern "C" VOID __cdecl __crtSetThreadpoolWait(PTP_WAIT const pwa, HANDLE const // ...otherwise there is no fall back. } -extern "C" VOID __cdecl __crtCloseThreadpoolWait(PTP_WAIT const pwa) { +extern "C" VOID __cdecl __crtCloseThreadpoolWait(__inout PTP_WAIT const pwa) { // use CloseThreadpoolWait if it is available (only on Windows Vista+)... IFDYNAMICGETCACHEDFUNCTION(PFNCLOSETHREADPOOLWAIT, CloseThreadpoolWait, pfCloseThreadpoolWait) { pfCloseThreadpoolWait(pwa); @@ -353,7 +356,8 @@ extern "C" VOID __cdecl __crtFlushProcessWriteBuffers() { // ...otherwise there is no fall back. } -extern "C" VOID __cdecl __crtFreeLibraryWhenCallbackReturns(PTP_CALLBACK_INSTANCE const pci, HMODULE const mod) { +extern "C" VOID __cdecl __crtFreeLibraryWhenCallbackReturns( + __inout PTP_CALLBACK_INSTANCE const pci, __in HMODULE const mod) { // use FreeLibraryWhenCallbackReturns if it is available (only on Windows Vista+)... IFDYNAMICGETCACHEDFUNCTION( PFNFREELIBRARYWHENCALLBACKRETURNS, FreeLibraryWhenCallbackReturns, pfFreeLibraryWhenCallbackReturns) { @@ -374,7 +378,7 @@ extern "C" DWORD __cdecl __crtGetCurrentProcessorNumber() { } extern "C" BOOLEAN __cdecl __crtCreateSymbolicLinkW( - LPCWSTR const lpSymlinkFileName, LPCWSTR const lpTargetFileName, DWORD const dwFlags) { + __in LPCWSTR const lpSymlinkFileName, __in LPCWSTR const lpTargetFileName, __in DWORD const dwFlags) { // use CreateSymbolicLink if it is available (only on Windows Vista+)... IFDYNAMICGETCACHEDFUNCTION(PFNCREATESYMBOLICLINKW, CreateSymbolicLinkW, pfCreateSymbolicLink) { return pfCreateSymbolicLink(lpSymlinkFileName, lpTargetFileName, dwFlags); @@ -385,8 +389,9 @@ extern "C" BOOLEAN __cdecl __crtCreateSymbolicLinkW( return 0; } -extern "C" BOOL __cdecl __crtGetFileInformationByHandleEx(HANDLE const hFile, - FILE_INFO_BY_HANDLE_CLASS const FileInformationClass, LPVOID const lpFileInformation, DWORD const dwBufferSize) { +extern "C" _Success_(return ) BOOL __cdecl __crtGetFileInformationByHandleEx(_In_ HANDLE const hFile, + _In_ FILE_INFO_BY_HANDLE_CLASS const FileInformationClass, _Out_ LPVOID const lpFileInformation, + _In_ DWORD const dwBufferSize) { // use GetFileInformationByHandleEx if it is available (only on Windows Vista+)... IFDYNAMICGETCACHEDFUNCTION( PFNGETFILEINFORMATIONBYHANDLEEX, GetFileInformationByHandleEx, pfGetFileInformationByHandleEx) { @@ -398,8 +403,9 @@ extern "C" BOOL __cdecl __crtGetFileInformationByHandleEx(HANDLE const hFile, return 0; } -extern "C" BOOL __cdecl __crtSetFileInformationByHandle(HANDLE const hFile, - FILE_INFO_BY_HANDLE_CLASS const FileInformationClass, LPVOID const lpFileInformation, DWORD const dwBufferSize) { +extern "C" BOOL __cdecl __crtSetFileInformationByHandle(_In_ HANDLE const hFile, + _In_ FILE_INFO_BY_HANDLE_CLASS const FileInformationClass, _In_ LPVOID const lpFileInformation, + _In_ DWORD const dwBufferSize) { // use SetFileInformationByHandle if it is available (only on Windows Vista+)... IFDYNAMICGETCACHEDFUNCTION( PFNSETFILEINFORMATIONBYHANDLE, SetFileInformationByHandle, pfSetFileInformationByHandle) { @@ -411,71 +417,71 @@ extern "C" BOOL __cdecl __crtSetFileInformationByHandle(HANDLE const hFile, return 0; } -extern "C" VOID __cdecl __crtInitializeConditionVariable(PCONDITION_VARIABLE const pCond) { +extern "C" VOID __cdecl __crtInitializeConditionVariable(__out PCONDITION_VARIABLE const pCond) { DYNAMICGETCACHEDFUNCTION( PFNINITIALIZECONDITIONVARIABLE, InitializeConditionVariable, pfInitializeConditionVariable); pfInitializeConditionVariable(pCond); // Don't have fallbacks because the only caller (in primitives.hpp) will check the existence before calling } -extern "C" VOID __cdecl __crtWakeConditionVariable(PCONDITION_VARIABLE const pCond) { +extern "C" VOID __cdecl __crtWakeConditionVariable(__inout PCONDITION_VARIABLE const pCond) { DYNAMICGETCACHEDFUNCTION(PFNWAKECONDITIONVARIABLE, WakeConditionVariable, pfWakeConditionVariable); pfWakeConditionVariable(pCond); // Don't have fallbacks because the only caller (in primitives.hpp) will check the existence before calling } -extern "C" VOID __cdecl __crtWakeAllConditionVariable(PCONDITION_VARIABLE const pCond) { +extern "C" VOID __cdecl __crtWakeAllConditionVariable(__inout PCONDITION_VARIABLE const pCond) { DYNAMICGETCACHEDFUNCTION(PFNWAKEALLCONDITIONVARIABLE, WakeAllConditionVariable, pfWakeAllConditionVariable); pfWakeAllConditionVariable(pCond); // Don't have fallbacks because the only caller (in primitives.hpp) will check the existence before calling } extern "C" BOOL __cdecl __crtSleepConditionVariableCS( - PCONDITION_VARIABLE const pCond, PCRITICAL_SECTION const pLock, DWORD const dwMs) { + __inout PCONDITION_VARIABLE const pCond, __inout PCRITICAL_SECTION const pLock, __in DWORD const dwMs) { DYNAMICGETCACHEDFUNCTION(PFNSLEEPCONDITIONVARIABLECS, SleepConditionVariableCS, pfSleepConditionVariableCS); return pfSleepConditionVariableCS(pCond, pLock, dwMs); // Don't have fallbacks because the only caller (in primitives.hpp) will check the existence before calling } -extern "C" VOID __cdecl __crtInitializeSRWLock(PSRWLOCK const pLock) { +extern "C" VOID __cdecl __crtInitializeSRWLock(__out PSRWLOCK const pLock) { DYNAMICGETCACHEDFUNCTION(PFNINITIALIZESRWLOCK, InitializeSRWLock, pfInitializeSRWLock); pfInitializeSRWLock(pLock); // Don't have fallbacks because the only caller (in primitives.hpp) will check the existence before calling } -extern "C" VOID __cdecl __crtAcquireSRWLockExclusive(PSRWLOCK const pLock) { +extern "C" VOID __cdecl __crtAcquireSRWLockExclusive(__inout PSRWLOCK const pLock) { DYNAMICGETCACHEDFUNCTION(PFNACQUIRESRWLOCKEXCLUSIVE, AcquireSRWLockExclusive, pfAcquireSRWLockExclusive); pfAcquireSRWLockExclusive(pLock); // Don't have fallbacks because the only caller (in primitives.hpp) will check the existence before calling } -extern "C" VOID __cdecl __crtReleaseSRWLockExclusive(PSRWLOCK const pLock) { +extern "C" VOID __cdecl __crtReleaseSRWLockExclusive(__inout PSRWLOCK const pLock) { DYNAMICGETCACHEDFUNCTION(PFNRELEASESRWLOCKEXCLUSIVE, ReleaseSRWLockExclusive, pfReleaseSRWLockExclusive); pfReleaseSRWLockExclusive(pLock); // Don't have fallbacks because the only caller (in primitives.hpp) will check the existence before calling } -extern "C" BOOL __cdecl __crtSleepConditionVariableSRW( - PCONDITION_VARIABLE const pCond, PSRWLOCK const pLock, DWORD const dwMs, ULONG const flags) { +extern "C" BOOL __cdecl __crtSleepConditionVariableSRW(__inout PCONDITION_VARIABLE const pCond, + __inout PSRWLOCK const pLock, __in DWORD const dwMs, __in ULONG const flags) { DYNAMICGETCACHEDFUNCTION(PFNSLEEPCONDITIONVARIABLESRW, SleepConditionVariableSRW, pfSleepConditionVariableSRW); return pfSleepConditionVariableSRW(pCond, pLock, dwMs, flags); // Don't have fallbacks because the only caller (in primitives.hpp) will check the existence before calling } extern "C" PTP_WORK __cdecl __crtCreateThreadpoolWork( - PTP_WORK_CALLBACK const pfnwk, PVOID const pv, PTP_CALLBACK_ENVIRON const pcbe) { + __in PTP_WORK_CALLBACK const pfnwk, __inout_opt PVOID const pv, __in_opt PTP_CALLBACK_ENVIRON const pcbe) { DYNAMICGETCACHEDFUNCTION(PFNCREATETHREADPOOLWORK, CreateThreadpoolWork, pfCreateThreadpoolWork); return pfCreateThreadpoolWork(pfnwk, pv, pcbe); // Don't have fallbacks because the only caller (in taskscheduler.cpp) will check the existence before calling } -extern "C" VOID __cdecl __crtSubmitThreadpoolWork(PTP_WORK const pwk) { +extern "C" VOID __cdecl __crtSubmitThreadpoolWork(__inout PTP_WORK const pwk) { DYNAMICGETCACHEDFUNCTION(PFNSUBMITTHREADPOOLWORK, SubmitThreadpoolWork, pfSubmitThreadpoolWork); return pfSubmitThreadpoolWork(pwk); // Don't have fallbacks because the only caller (in taskscheduler.cpp) will check the existence before calling } -extern "C" VOID __cdecl __crtCloseThreadpoolWork(PTP_WORK const pwk) { +extern "C" VOID __cdecl __crtCloseThreadpoolWork(__inout PTP_WORK const pwk) { DYNAMICGETCACHEDFUNCTION(PFNCLOSETHREADPOOLWORK, CloseThreadpoolWork, pfCloseThreadpoolWork); return pfCloseThreadpoolWork(pwk); // Don't have fallbacks because the only caller (in taskscheduler.cpp) will check the existence before calling @@ -491,7 +497,7 @@ extern "C" BOOL __cdecl __crtQueueUserWorkItem(LPTHREAD_START_ROUTINE, PVOID, UL #if _STL_WIN32_WINNT < _WIN32_WINNT_WIN7 -extern "C" BOOLEAN __cdecl __crtTryAcquireSRWLockExclusive(PSRWLOCK const pLock) { +extern "C" BOOLEAN __cdecl __crtTryAcquireSRWLockExclusive(__inout PSRWLOCK const pLock) { DYNAMICGETCACHEDFUNCTION(PFNTRYACQUIRESRWLOCKEXCLUSIVE, TryAcquireSRWLockExclusive, pfTryAcquireSRWLockExclusive); return pfTryAcquireSRWLockExclusive(pLock); // Don't have fallbacks because the only caller (in primitives.hpp) will check the existence before calling diff --git a/stl/src/xmbtowc.cpp b/stl/src/xmbtowc.cpp index 0983f451519..5bc58a872cf 100644 --- a/stl/src/xmbtowc.cpp +++ b/stl/src/xmbtowc.cpp @@ -66,7 +66,8 @@ static int _Decode_utf8_trailing_byte(unsigned long* partialCh, unsigned char ch // -1 (if the next n or fewer bytes not valid mbc) // -2 (if partial conversion) // number of bytes comprising converted mbc -_MRTIMP2 int __cdecl _Mbrtowc(wchar_t* pwc, const char* s, size_t n, mbstate_t* pst, const _Cvtvec* ploc) { +_MRTIMP2 _Success_(return >= 0) int __cdecl _Mbrtowc( + _When_(n != 0, _Out_) wchar_t* pwc, const char* s, size_t n, mbstate_t* pst, const _Cvtvec* ploc) { (void) pst; if (n == 0) { // indicate do not have state-dependent encodings, handle zero length string return 0; diff --git a/stl/src/xstrxfrm.cpp b/stl/src/xstrxfrm.cpp index 3348cf0957c..e7988a747ab 100644 --- a/stl/src/xstrxfrm.cpp +++ b/stl/src/xstrxfrm.cpp @@ -52,8 +52,9 @@ _EXTERN_C_UNLESS_PURE // // Exceptions: // Non-standard: if OM/API error, return INT_MAX. -_CRTIMP2_PURE size_t __CLRCALL_PURE_OR_CDECL _Strxfrm( - char* string1, char* end1, const char* string2, const char* end2, const _Collvec* ploc) { +_CRTIMP2_PURE size_t __CLRCALL_PURE_OR_CDECL _Strxfrm(_Out_writes_(end1 - string1) + _Post_readable_size_(return ) char* string1, + _In_z_ char* end1, const char* string2, const char* end2, const _Collvec* ploc) { size_t n1 = end1 - string1; size_t n2 = end2 - string2; size_t retval = static_cast(-1); // NON-ANSI: default if OM or API error diff --git a/stl/src/xwcsxfrm.cpp b/stl/src/xwcsxfrm.cpp index 31fc90a6b28..cd3706dd3a3 100644 --- a/stl/src/xwcsxfrm.cpp +++ b/stl/src/xwcsxfrm.cpp @@ -44,8 +44,9 @@ _EXTERN_C_UNLESS_PURE // // Exceptions: // Non-standard: if OM/API error, return INT_MAX. -_CRTIMP2_PURE size_t __CLRCALL_PURE_OR_CDECL _Wcsxfrm( - wchar_t* string1, wchar_t* end1, const wchar_t* string2, const wchar_t* end2, const _Collvec* ploc) { +_CRTIMP2_PURE size_t __CLRCALL_PURE_OR_CDECL _Wcsxfrm(_Out_writes_(end1 - string1) _Post_readable_size_(return ) + wchar_t* string1, + _In_z_ wchar_t* end1, const wchar_t* string2, const wchar_t* end2, const _Collvec* ploc) { size_t n1 = end1 - string1; size_t n2 = end2 - string2; size_t size = static_cast(-1); diff --git a/stl/src/xwctomb.cpp b/stl/src/xwctomb.cpp index 2c94e37da6a..d82f8a5bdaa 100644 --- a/stl/src/xwctomb.cpp +++ b/stl/src/xwctomb.cpp @@ -41,7 +41,8 @@ _CRTIMP2_PURE int __CLRCALL_PURE_OR_CDECL __Wcrtomb_lk(char* s, wchar_t wchar, m return _Wcrtomb(s, wchar, pst, ploc); } -_CRTIMP2_PURE int __CLRCALL_PURE_OR_CDECL _Wcrtomb(char* s, wchar_t wchar, mbstate_t* pst, const _Cvtvec* ploc) { +_CRTIMP2_PURE _Success_(return != -1) int __CLRCALL_PURE_OR_CDECL + _Wcrtomb(_Out_ char* s, wchar_t wchar, mbstate_t* pst, const _Cvtvec* ploc) { _CRT_UNUSED(pst); if (ploc->_Isclocale) { if (wchar > 255) { // validate high byte From 02c7021feb90f622c6135e958056b866d9c25d80 Mon Sep 17 00:00:00 2001 From: Billy Robert O'Neal III Date: Tue, 7 Jul 2020 02:06:29 -0700 Subject: [PATCH 08/17] Rename _Inf to _Infinity due to shadowing. --- stl/src/special_math.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stl/src/special_math.cpp b/stl/src/special_math.cpp index 105b54b268a..239aca52dcc 100644 --- a/stl/src/special_math.cpp +++ b/stl/src/special_math.cpp @@ -472,9 +472,9 @@ namespace { _Dy = _STD abs(_Dy); _Dz = _STD abs(_Dz); - constexpr _Ty _Inf = _STD numeric_limits<_Ty>::infinity(); - if (_Dx == _Inf || _Dy == _Inf || _Dz == _Inf) { - return _Inf; + constexpr _Ty _Infinity = _STD numeric_limits<_Ty>::infinity(); + if (_Dx == _Infinity || _Dy == _Infinity || _Dz == _Infinity) { + return _Infinity; } if (_Dy > _Dx) { From 8413970a207bac0b92678ece5f51506895fc0802 Mon Sep 17 00:00:00 2001 From: Billy Robert O'Neal III Date: Tue, 7 Jul 2020 02:07:32 -0700 Subject: [PATCH 09/17] Remove branch and casts for __crtLCMapStringW call. --- stl/src/xwcsxfrm.cpp | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/stl/src/xwcsxfrm.cpp b/stl/src/xwcsxfrm.cpp index cd3706dd3a3..1af77699741 100644 --- a/stl/src/xwcsxfrm.cpp +++ b/stl/src/xwcsxfrm.cpp @@ -50,7 +50,6 @@ _CRTIMP2_PURE size_t __CLRCALL_PURE_OR_CDECL _Wcsxfrm(_Out_writes_(end1 - string size_t n1 = end1 - string1; size_t n2 = end2 - string2; size_t size = static_cast(-1); - unsigned char* bbuffer = nullptr; const wchar_t* locale_name; if (ploc == nullptr) { @@ -72,11 +71,12 @@ _CRTIMP2_PURE size_t __CLRCALL_PURE_OR_CDECL _Wcsxfrm(_Out_writes_(end1 - string // compared using wcscmp(). User's buffer is n1 wide chars, so // use an internal buffer of n1 bytes. - bbuffer = static_cast(_malloc_crt(n1)); + auto bbuffer = _malloc_crt_t(unsigned char, n1); - if (bbuffer != nullptr) { + if (bbuffer) { +#pragma warning(suppress : 6386) // PREfast doesn't understand LCMAP_SORTKEY size = __crtLCMapStringW(locale_name, LCMAP_SORTKEY, string2, static_cast(n2), - reinterpret_cast(bbuffer), static_cast(n1)); + reinterpret_cast(bbuffer.get()), static_cast(n1)); if (size == 0) { // buffer not big enough, get size required. @@ -89,16 +89,12 @@ _CRTIMP2_PURE size_t __CLRCALL_PURE_OR_CDECL _Wcsxfrm(_Out_writes_(end1 - string // string successfully mapped, convert to wide char for (size_t i = 0; i < size; ++i) { - string1[i] = static_cast(bbuffer[i]); + string1[i] = static_cast(bbuffer.get()[i]); } } } } - if (bbuffer) { - _free_crt(bbuffer); - } - return size; } From 5d40f067348bcbcab90bb7162ddf6196322405fe Mon Sep 17 00:00:00 2001 From: Billy Robert O'Neal III Date: Tue, 7 Jul 2020 02:07:45 -0700 Subject: [PATCH 10/17] Suppress some /analyze warnings. --- stl/src/locale.cpp | 1 + stl/src/multprec.cpp | 6 ++++++ stl/src/parallel_algorithms.cpp | 1 + stl/src/primitives.hpp | 3 +++ stl/src/special_math.cpp | 1 + stl/src/winapisupp.cpp | 4 ++-- 6 files changed, 14 insertions(+), 2 deletions(-) diff --git a/stl/src/locale.cpp b/stl/src/locale.cpp index 75e6250b402..f2969d61d01 100644 --- a/stl/src/locale.cpp +++ b/stl/src/locale.cpp @@ -128,6 +128,7 @@ void __CLRCALL_PURE_OR_CDECL locale::_Locimp::_Locimp_Addfac( } } ptrfac->_Incref(); +#pragma warning(suppress : 6001) // PREfast isn't following through _realloc_crt here if (_This->_Facetvec[id] != nullptr) { delete _This->_Facetvec[id]->_Decref(); } diff --git a/stl/src/multprec.cpp b/stl/src/multprec.cpp index e81d0156c18..0fb8c9d7c25 100644 --- a/stl/src/multprec.cpp +++ b/stl/src/multprec.cpp @@ -112,7 +112,12 @@ void __CLRCALL_PURE_OR_CDECL _MP_Rem( v[0] = v0 & mask; v[1] = v0 >> shift; const int n = limit(v, 2); + _Analysis_assume_(n > 0); + _Analysis_assume_(n <= 2); const int m = limit(u, _MP_len) - n; + _Analysis_assume_(m > 0); + _Analysis_assume_(m <= _MP_len - n); + // Knuth, vol. 2, p. 272, Algorithm D // D1: [Normalize.] @@ -130,6 +135,7 @@ void __CLRCALL_PURE_OR_CDECL _MP_Rem( unsigned long long rh = ((u[j + n] << shift) + u[j + n - 1]) % v[n - 1]; for (;;) { +#pragma warning(suppress : 6385) // TRANSITION, GH-1008 if (qh < maxVal && qh * v[n - 2] <= (rh << shift) + u[j + n - 2]) { break; } else { // reduce tentative value and retry diff --git a/stl/src/parallel_algorithms.cpp b/stl/src/parallel_algorithms.cpp index c59577b7d53..7d3d067994e 100644 --- a/stl/src/parallel_algorithms.cpp +++ b/stl/src/parallel_algorithms.cpp @@ -94,6 +94,7 @@ namespace { #endif // !(defined(_M_IX86) || defined(_M_X64) || defined(_M_ARM) || defined(_M_ARM64)) HMODULE _Kernel32 = GetModuleHandleW(L"kernel32.dll"); + _Analysis_assume_(_Kernel32); #if _STL_WIN32_WINNT < _WIN32_WINNT_VISTA _Parallel_info._Pfn_CreateThreadpoolWork = reinterpret_cast(GetProcAddress(_Kernel32, "CreateThreadpoolWork")); diff --git a/stl/src/primitives.hpp b/stl/src/primitives.hpp index 85eabcfb821..38a18de9ef8 100644 --- a/stl/src/primitives.hpp +++ b/stl/src/primitives.hpp @@ -16,8 +16,11 @@ #include "awint.hpp" #ifdef _STL_CONCRT_SUPPORT +#pragma warning(push) +#pragma warning(disable : 6385 6386 6504 28204) #include #include +#pragma warning(pop) #endif enum class __stl_sync_api_modes_enum { normal, win7, vista, concrt }; diff --git a/stl/src/special_math.cpp b/stl/src/special_math.cpp index 239aca52dcc..e824c10b2e1 100644 --- a/stl/src/special_math.cpp +++ b/stl/src/special_math.cpp @@ -12,6 +12,7 @@ #pragma warning(disable : 4643) // Forward declaring '%s' in namespace std is not permitted by the C++ Standard #pragma warning(disable : 4702) // unreachable code #pragma warning(disable : 5219) // implicit conversion from '%s' to '%s', possible loss of data +#pragma warning(disable : 6326) // potential comparison of a constant with another constant #define BOOST_CHRONO_HEADER_ONLY #define BOOST_CONFIG_SUPPRESS_OUTDATED_MESSAGE diff --git a/stl/src/winapisupp.cpp b/stl/src/winapisupp.cpp index 84b9e8ab9aa..e1c66684505 100644 --- a/stl/src/winapisupp.cpp +++ b/stl/src/winapisupp.cpp @@ -196,8 +196,7 @@ extern "C" BOOL __cdecl __crtInitializeCriticalSectionEx( } // ...otherwise fall back to using InitializeCriticalSectionAndSpinCount. - InitializeCriticalSectionAndSpinCount(lpCriticalSection, dwSpinCount); - return TRUE; + return InitializeCriticalSectionAndSpinCount(lpCriticalSection, dwSpinCount); } extern "C" BOOL __cdecl __crtInitOnceExecuteOnce(_Inout_ PINIT_ONCE const InitOnce, _In_ PINIT_ONCE_FN const InitFn, @@ -535,6 +534,7 @@ extern "C" PVOID __KERNEL32Functions[eMaxKernel32Function] = {0}; static int __cdecl initialize_pointers() { HINSTANCE hKernel32 = GetModuleHandleW(L"kernel32.dll"); + _Analysis_assume_(hKernel32); STOREFUNCTIONPOINTER(hKernel32, FlsAlloc); STOREFUNCTIONPOINTER(hKernel32, FlsFree); From eea4db361bc6ed5ba8c9a3bf20a2dbe189b7621a Mon Sep 17 00:00:00 2001 From: Billy Robert O'Neal III Date: Tue, 7 Jul 2020 02:15:23 -0700 Subject: [PATCH 11/17] Fix more /analyze warnings found building x64. --- stl/src/excptptr.cpp | 3 ++- stl/src/primitives.hpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/stl/src/excptptr.cpp b/stl/src/excptptr.cpp index c1a828083d5..c87b6236918 100644 --- a/stl/src/excptptr.cpp +++ b/stl/src/excptptr.cpp @@ -84,7 +84,8 @@ namespace { #if _EH_RELATIVE_TYPEINFO void* _ThrowImageBase = - RtlPcToFileHeader(const_cast(static_cast(_PThrow)), &_ThrowImageBase); + _PThrow ? RtlPcToFileHeader(const_cast(static_cast(_PThrow)), &_ThrowImageBase) + : nullptr; _Record.ExceptionInformation[3] = reinterpret_cast(_ThrowImageBase); // params.pThrowImageBase #endif // _EH_RELATIVE_TYPEINFO diff --git a/stl/src/primitives.hpp b/stl/src/primitives.hpp index 38a18de9ef8..2f335143af1 100644 --- a/stl/src/primitives.hpp +++ b/stl/src/primitives.hpp @@ -17,7 +17,7 @@ #ifdef _STL_CONCRT_SUPPORT #pragma warning(push) -#pragma warning(disable : 6385 6386 6504 28204) +#pragma warning(disable : 6297 6385 6386 6504 28204) #include #include #pragma warning(pop) From 4a5e0db7b40941d59922a540c86691bc5d675b28 Mon Sep 17 00:00:00 2001 From: Billy Robert O'Neal III Date: Tue, 7 Jul 2020 02:32:12 -0700 Subject: [PATCH 12/17] clang-format --- stl/inc/xfilesystem_abi.h | 2 +- stl/src/filesystem.cpp | 2 +- stl/src/xmath.hpp | 3 ++- stl/src/xwcsxfrm.cpp | 6 +++--- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/stl/inc/xfilesystem_abi.h b/stl/inc/xfilesystem_abi.h index 60b4800ec21..defdbe38c46 100644 --- a/stl/inc/xfilesystem_abi.h +++ b/stl/inc/xfilesystem_abi.h @@ -261,7 +261,7 @@ _NODISCARD __std_win_error __stdcall __std_fs_directory_iterator_open(_In_z_ con void __stdcall __std_fs_directory_iterator_close(_In_ __std_fs_dir_handle _Handle) noexcept; _NODISCARD _Success_(return == __std_win_error::_Success) __std_win_error __stdcall __std_fs_get_stats( - _In_z_ const wchar_t* _Path, _Out_ __std_fs_stats* _Stats, _In_ __std_fs_stats_flags _Flags, + _In_z_ const wchar_t* _Path, __std_fs_stats* _Stats, _In_ __std_fs_stats_flags _Flags, _In_ __std_fs_file_attr _Symlink_attribute_hint = __std_fs_file_attr::_Invalid) noexcept; _NODISCARD __std_win_error __stdcall __std_fs_directory_iterator_advance( diff --git a/stl/src/filesystem.cpp b/stl/src/filesystem.cpp index bc9f40abe4e..92a66e6f624 100644 --- a/stl/src/filesystem.cpp +++ b/stl/src/filesystem.cpp @@ -891,7 +891,7 @@ struct alignas(long long) _Aligned_file_attrs { }; [[nodiscard]] _Success_(return == __std_win_error::_Success) __std_win_error - __stdcall __std_fs_get_stats(_In_z_ const wchar_t* const _Path, _Out_ __std_fs_stats* const _Stats, + __stdcall __std_fs_get_stats(_In_z_ const wchar_t* const _Path, __std_fs_stats* const _Stats, _In_ __std_fs_stats_flags _Flags, _In_ const __std_fs_file_attr _Symlink_attribute_hint) noexcept { static_assert((offsetof(_Aligned_file_attrs, _Data._Last_write_time) % 8) == 0, "_Last_write_time not aligned"); static_assert(sizeof(_File_attr_data) == sizeof(WIN32_FILE_ATTRIBUTE_DATA)); diff --git a/stl/src/xmath.hpp b/stl/src/xmath.hpp index d3967ab9ae2..200d7a9d981 100644 --- a/stl/src/xmath.hpp +++ b/stl/src/xmath.hpp @@ -49,7 +49,8 @@ _EXTERN_C_UNLESS_PURE int _Stopfx(const char**, char**); -_In_range_(0, maxsig) int _Stoflt(const char*, const char*, char**, _Out_writes_(maxsig) long[], _In_range_(1, 4) int maxsig); +_In_range_(0, maxsig) int _Stoflt( + const char*, const char*, char**, _Out_writes_(maxsig) long[], _In_range_(1, 4) int maxsig); _In_range_(0, maxsig) int _Stoxflt( const char*, const char*, char**, _Out_writes_(maxsig) long[], _In_range_(1, 4) int maxsig); int _WStopfx(const wchar_t**, wchar_t**); diff --git a/stl/src/xwcsxfrm.cpp b/stl/src/xwcsxfrm.cpp index 1af77699741..ab3692be410 100644 --- a/stl/src/xwcsxfrm.cpp +++ b/stl/src/xwcsxfrm.cpp @@ -47,9 +47,9 @@ _EXTERN_C_UNLESS_PURE _CRTIMP2_PURE size_t __CLRCALL_PURE_OR_CDECL _Wcsxfrm(_Out_writes_(end1 - string1) _Post_readable_size_(return ) wchar_t* string1, _In_z_ wchar_t* end1, const wchar_t* string2, const wchar_t* end2, const _Collvec* ploc) { - size_t n1 = end1 - string1; - size_t n2 = end2 - string2; - size_t size = static_cast(-1); + size_t n1 = end1 - string1; + size_t n2 = end2 - string2; + size_t size = static_cast(-1); const wchar_t* locale_name; if (ploc == nullptr) { From 4a5c8a6dc299b89d16c94255d9e03564d8d087af Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Wed, 8 Jul 2020 21:24:34 -0700 Subject: [PATCH 13/17] clang-format xfilesystem_abi.h. --- stl/inc/xfilesystem_abi.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stl/inc/xfilesystem_abi.h b/stl/inc/xfilesystem_abi.h index defdbe38c46..3a43fea8240 100644 --- a/stl/inc/xfilesystem_abi.h +++ b/stl/inc/xfilesystem_abi.h @@ -260,9 +260,9 @@ _NODISCARD __std_win_error __stdcall __std_fs_directory_iterator_open(_In_z_ con void __stdcall __std_fs_directory_iterator_close(_In_ __std_fs_dir_handle _Handle) noexcept; -_NODISCARD _Success_(return == __std_win_error::_Success) __std_win_error __stdcall __std_fs_get_stats( - _In_z_ const wchar_t* _Path, __std_fs_stats* _Stats, _In_ __std_fs_stats_flags _Flags, - _In_ __std_fs_file_attr _Symlink_attribute_hint = __std_fs_file_attr::_Invalid) noexcept; +_NODISCARD _Success_(return == __std_win_error::_Success) __std_win_error + __stdcall __std_fs_get_stats(_In_z_ const wchar_t* _Path, __std_fs_stats* _Stats, _In_ __std_fs_stats_flags _Flags, + _In_ __std_fs_file_attr _Symlink_attribute_hint = __std_fs_file_attr::_Invalid) noexcept; _NODISCARD __std_win_error __stdcall __std_fs_directory_iterator_advance( _In_ __std_fs_dir_handle _Handle, _Out_ __std_fs_find_data* _Results) noexcept; From 0ab6312d4c92add8c11c915ad1f10e381e141111 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Tue, 14 Jul 2020 20:10:00 -0700 Subject: [PATCH 14/17] Define __crtQueueUserWorkItem with SAL. And follow the style in threadpoollegacyapiset.h. --- stl/src/awint.hpp | 2 +- stl/src/winapisupp.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/stl/src/awint.hpp b/stl/src/awint.hpp index aad3ccbd768..27fa3637279 100644 --- a/stl/src/awint.hpp +++ b/stl/src/awint.hpp @@ -229,7 +229,7 @@ _CRTIMP2 void __cdecl __crtGetSystemTimePreciseAsFileTime(_Out_ LPFILETIME lpSys #else // _STL_WIN32_WINNT < _WIN32_WINNT_VISTA -BOOL __cdecl __crtQueueUserWorkItem(__in LPTHREAD_START_ROUTINE function, __in_opt PVOID context, __in ULONG flags); +BOOL __cdecl __crtQueueUserWorkItem(_In_ LPTHREAD_START_ROUTINE function, _In_opt_ PVOID context, _In_ ULONG flags); #endif // _STL_WIN32_WINNT < _WIN32_WINNT_VISTA diff --git a/stl/src/winapisupp.cpp b/stl/src/winapisupp.cpp index e1c66684505..22fa1bab35d 100644 --- a/stl/src/winapisupp.cpp +++ b/stl/src/winapisupp.cpp @@ -487,7 +487,7 @@ extern "C" VOID __cdecl __crtCloseThreadpoolWork(__inout PTP_WORK const pwk) { } #else // _STL_WIN32_WINNT < _WIN32_WINNT_VISTA -extern "C" BOOL __cdecl __crtQueueUserWorkItem(LPTHREAD_START_ROUTINE, PVOID, ULONG) { +extern "C" BOOL __cdecl __crtQueueUserWorkItem(_In_ LPTHREAD_START_ROUTINE, _In_opt_ PVOID, _In_ ULONG) { // This function doesn't have an implementation as it is only used on Windows XP return 0; } From f6ef56e2829ab5349cf5c973309df80855d60b00 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Tue, 14 Jul 2020 21:09:14 -0700 Subject: [PATCH 15/17] Update SAL. The functional changes are: * `__crtFlsAlloc`: Change `lpCallback` from `__in` to `_In_opt_` as declared in `fibersapi.h` * `__crtCreateEventExW`: Change `dwFlags` from `__reserved` to `_In_` as declared in `synchapi.h` * `__crtGetFileInformationByHandleEx`: Change `lpFileInformation` from `_Out_` to `_Out_writes_bytes_(dwBufferSize)` as declared in `WinBase.h` * `__crtSetFileInformationByHandle`: Change `lpFileInformation` from `_In_` to `_In_reads_bytes_(dwBufferSize)` as declared in `fileapi.h` * `__crtGetLocaleInfoEx`: Change `lpLCData` from `_Out_opt_` to `_Out_writes_opt_(cchData)` as declared in `WinNls.h` --- stl/src/awint.hpp | 72 ++++++++++++++++++++-------------------- stl/src/winapinls.cpp | 2 +- stl/src/winapisupp.cpp | 74 +++++++++++++++++++++--------------------- 3 files changed, 75 insertions(+), 73 deletions(-) diff --git a/stl/src/awint.hpp b/stl/src/awint.hpp index 27fa3637279..c52f3ce746f 100644 --- a/stl/src/awint.hpp +++ b/stl/src/awint.hpp @@ -28,13 +28,13 @@ _CRTIMP2 BOOL __cdecl __crtIsPackagedApp(); #else // _STL_WIN32_WINNT >= _WIN32_WINNT_WS03 -DWORD __cdecl __crtFlsAlloc(__in PFLS_CALLBACK_FUNCTION lpCallback); +DWORD __cdecl __crtFlsAlloc(_In_opt_ PFLS_CALLBACK_FUNCTION lpCallback); -BOOL __cdecl __crtFlsFree(__in DWORD dwFlsIndex); +BOOL __cdecl __crtFlsFree(_In_ DWORD dwFlsIndex); -PVOID __cdecl __crtFlsGetValue(__in DWORD dwFlsIndex); +PVOID __cdecl __crtFlsGetValue(_In_ DWORD dwFlsIndex); -BOOL __cdecl __crtFlsSetValue(__in DWORD dwFlsIndex, __in_opt PVOID lpFlsData); +BOOL __cdecl __crtFlsSetValue(_In_ DWORD dwFlsIndex, _In_opt_ PVOID lpFlsData); #endif // _STL_WIN32_WINNT >= _WIN32_WINNT_WS03 @@ -120,75 +120,77 @@ BOOL __cdecl __crtFlsSetValue(__in DWORD dwFlsIndex, __in_opt PVOID lpFlsData); #else // _STL_WIN32_WINNT >= _WIN32_WINNT_VISTA _CRTIMP2 BOOL __cdecl __crtInitializeCriticalSectionEx( - __out LPCRITICAL_SECTION lpCriticalSection, __in DWORD dwSpinCount, __in DWORD Flags); + _Out_ LPCRITICAL_SECTION lpCriticalSection, _In_ DWORD dwSpinCount, _In_ DWORD Flags); // N.B. Context is not used _CRTIMP2 BOOL __cdecl __crtInitOnceExecuteOnce( _Inout_ PINIT_ONCE InitOnce, _In_ PINIT_ONCE_FN InitFn, _Inout_opt_ PVOID Parameter, LPVOID* Context); -_CRTIMP2 HANDLE __cdecl __crtCreateEventExW(__in_opt LPSECURITY_ATTRIBUTES lpEventAttributes, __in_opt LPCWSTR lpName, - __reserved DWORD dwFlags, __in DWORD dwDesiredAccess); +_CRTIMP2 HANDLE __cdecl __crtCreateEventExW(_In_opt_ LPSECURITY_ATTRIBUTES lpEventAttributes, _In_opt_ LPCWSTR lpName, + _In_ DWORD dwFlags, _In_ DWORD dwDesiredAccess); -_CRTIMP2 HANDLE __cdecl __crtCreateSemaphoreExW(__in_opt LPSECURITY_ATTRIBUTES lpSemaphoreAttributes, - __in LONG lInitialCount, __in LONG lMaximumCount, __in_opt LPCWSTR lpName, __reserved DWORD dwFlags, - __in DWORD dwDesiredAccess); +_CRTIMP2 HANDLE __cdecl __crtCreateSemaphoreExW(_In_opt_ LPSECURITY_ATTRIBUTES lpSemaphoreAttributes, + _In_ LONG lInitialCount, _In_ LONG lMaximumCount, _In_opt_ LPCWSTR lpName, _Reserved_ DWORD dwFlags, + _In_ DWORD dwDesiredAccess); _CRTIMP2 PTP_TIMER __cdecl __crtCreateThreadpoolTimer( - __in PTP_TIMER_CALLBACK pfnti, __inout_opt PVOID pv, __in_opt PTP_CALLBACK_ENVIRON pcbe); + _In_ PTP_TIMER_CALLBACK pfnti, _Inout_opt_ PVOID pv, _In_opt_ PTP_CALLBACK_ENVIRON pcbe); _CRTIMP2 VOID __cdecl __crtSetThreadpoolTimer( - __inout PTP_TIMER pti, __in_opt PFILETIME pftDueTime, __in DWORD msPeriod, __in_opt DWORD msWindowLength); + _Inout_ PTP_TIMER pti, _In_opt_ PFILETIME pftDueTime, _In_ DWORD msPeriod, _In_opt_ DWORD msWindowLength); -_CRTIMP2 VOID __cdecl __crtWaitForThreadpoolTimerCallbacks(__inout PTP_TIMER pti, __in BOOL fCancelPendingCallbacks); +_CRTIMP2 VOID __cdecl __crtWaitForThreadpoolTimerCallbacks(_Inout_ PTP_TIMER pti, _In_ BOOL fCancelPendingCallbacks); -_CRTIMP2 VOID __cdecl __crtCloseThreadpoolTimer(__inout PTP_TIMER pti); +_CRTIMP2 VOID __cdecl __crtCloseThreadpoolTimer(_Inout_ PTP_TIMER pti); _CRTIMP2 PTP_WAIT __cdecl __crtCreateThreadpoolWait( - __in PTP_WAIT_CALLBACK pfnwa, __inout_opt PVOID pv, __in_opt PTP_CALLBACK_ENVIRON pcbe); + _In_ PTP_WAIT_CALLBACK pfnwa, _Inout_opt_ PVOID pv, _In_opt_ PTP_CALLBACK_ENVIRON pcbe); -_CRTIMP2 VOID __cdecl __crtSetThreadpoolWait(__inout PTP_WAIT pwa, __in_opt HANDLE h, __in_opt PFILETIME pftTimeout); +_CRTIMP2 VOID __cdecl __crtSetThreadpoolWait(_Inout_ PTP_WAIT pwa, _In_opt_ HANDLE h, _In_opt_ PFILETIME pftTimeout); -_CRTIMP2 VOID __cdecl __crtCloseThreadpoolWait(__inout PTP_WAIT pwa); +_CRTIMP2 VOID __cdecl __crtCloseThreadpoolWait(_Inout_ PTP_WAIT pwa); _CRTIMP2 VOID __cdecl __crtFlushProcessWriteBuffers(); -_CRTIMP2 VOID __cdecl __crtFreeLibraryWhenCallbackReturns(__inout PTP_CALLBACK_INSTANCE pci, __in HMODULE mod); +_CRTIMP2 VOID __cdecl __crtFreeLibraryWhenCallbackReturns(_Inout_ PTP_CALLBACK_INSTANCE pci, _In_ HMODULE mod); _CRTIMP2 DWORD __cdecl __crtGetCurrentProcessorNumber(); _CRTIMP2 BOOLEAN __cdecl __crtCreateSymbolicLinkW( - __in LPCWSTR lpSymlinkFileName, __in LPCWSTR lpTargetFileName, __in DWORD dwFlags); + _In_ LPCWSTR lpSymlinkFileName, _In_ LPCWSTR lpTargetFileName, _In_ DWORD dwFlags); -_CRTIMP2 _Success_(return ) BOOL __cdecl __crtGetFileInformationByHandleEx(_In_ HANDLE hFile, - _In_ FILE_INFO_BY_HANDLE_CLASS FileInformationClass, _Out_ LPVOID lpFileInformation, _In_ DWORD dwBufferSize); +_CRTIMP2 _Success_(return ) BOOL + __cdecl __crtGetFileInformationByHandleEx(_In_ HANDLE hFile, _In_ FILE_INFO_BY_HANDLE_CLASS FileInformationClass, + _Out_writes_bytes_(dwBufferSize) LPVOID lpFileInformation, _In_ DWORD dwBufferSize); _CRTIMP2 BOOL __cdecl __crtSetFileInformationByHandle(_In_ HANDLE hFile, - _In_ FILE_INFO_BY_HANDLE_CLASS FileInformationClass, _In_ LPVOID lpFileInformation, _In_ DWORD dwBufferSize); + _In_ FILE_INFO_BY_HANDLE_CLASS FileInformationClass, _In_reads_bytes_(dwBufferSize) LPVOID lpFileInformation, + _In_ DWORD dwBufferSize); _CRTIMP2 ULONGLONG __cdecl __crtGetTickCount64(); -VOID __cdecl __crtInitializeConditionVariable(__out PCONDITION_VARIABLE); +VOID __cdecl __crtInitializeConditionVariable(_Out_ PCONDITION_VARIABLE); -VOID __cdecl __crtWakeConditionVariable(__inout PCONDITION_VARIABLE); +VOID __cdecl __crtWakeConditionVariable(_Inout_ PCONDITION_VARIABLE); -VOID __cdecl __crtWakeAllConditionVariable(__inout PCONDITION_VARIABLE); +VOID __cdecl __crtWakeAllConditionVariable(_Inout_ PCONDITION_VARIABLE); -BOOL __cdecl __crtSleepConditionVariableCS(__inout PCONDITION_VARIABLE, __inout PCRITICAL_SECTION, __in DWORD); +BOOL __cdecl __crtSleepConditionVariableCS(_Inout_ PCONDITION_VARIABLE, _Inout_ PCRITICAL_SECTION, _In_ DWORD); -VOID __cdecl __crtInitializeSRWLock(__out PSRWLOCK); +VOID __cdecl __crtInitializeSRWLock(_Out_ PSRWLOCK); -VOID __cdecl __crtAcquireSRWLockExclusive(__inout PSRWLOCK); +VOID __cdecl __crtAcquireSRWLockExclusive(_Inout_ PSRWLOCK); -VOID __cdecl __crtReleaseSRWLockExclusive(__inout PSRWLOCK); +VOID __cdecl __crtReleaseSRWLockExclusive(_Inout_ PSRWLOCK); -BOOL __cdecl __crtSleepConditionVariableSRW(__inout PCONDITION_VARIABLE, __inout PSRWLOCK, __in DWORD, __in ULONG); +BOOL __cdecl __crtSleepConditionVariableSRW(_Inout_ PCONDITION_VARIABLE, _Inout_ PSRWLOCK, _In_ DWORD, _In_ ULONG); PTP_WORK __cdecl __crtCreateThreadpoolWork( - __in PTP_WORK_CALLBACK pfnwk, __inout_opt PVOID pv, __in_opt PTP_CALLBACK_ENVIRON pcbe); + _In_ PTP_WORK_CALLBACK pfnwk, _Inout_opt_ PVOID pv, _In_opt_ PTP_CALLBACK_ENVIRON pcbe); -VOID __cdecl __crtSubmitThreadpoolWork(__inout PTP_WORK pwk); +VOID __cdecl __crtSubmitThreadpoolWork(_Inout_ PTP_WORK pwk); -VOID __cdecl __crtCloseThreadpoolWork(__inout PTP_WORK pwk); +VOID __cdecl __crtCloseThreadpoolWork(_Inout_ PTP_WORK pwk); _CRTIMP2 int __cdecl __crtCompareStringEx(_In_opt_ LPCWSTR lpLocaleName, _In_ DWORD dwCmpFlags, _In_NLS_string_(cchCount1) LPCWCH lpString1, _In_ int cchCount1, _In_NLS_string_(cchCount2) LPCWCH lpString2, @@ -198,7 +200,7 @@ _CRTIMP2 int __cdecl __crtLCMapStringEx(_In_opt_ LPCWSTR lpLocaleName, _In_ DWOR _In_reads_(cchSrc) LPCWSTR lpSrcStr, _In_ int cchSrc, _Out_writes_opt_(cchDest) LPWSTR lpDestStr, _In_ int cchDest); _CRTIMP2 int __cdecl __crtGetLocaleInfoEx( - _In_opt_ LPCWSTR lpLocaleName, _In_ LCTYPE LCType, _Out_opt_ LPWSTR lpLCData, _In_ int cchData); + _In_opt_ LPCWSTR lpLocaleName, _In_ LCTYPE LCType, _Out_writes_opt_(cchData) LPWSTR lpLCData, _In_ int cchData); #endif // _STL_WIN32_WINNT >= _WIN32_WINNT_VISTA @@ -208,7 +210,7 @@ _CRTIMP2 int __cdecl __crtGetLocaleInfoEx( #else // _STL_WIN32_WINNT >= _WIN32_WINNT_WIN7 -BOOLEAN __cdecl __crtTryAcquireSRWLockExclusive(__inout PSRWLOCK); +BOOLEAN __cdecl __crtTryAcquireSRWLockExclusive(_Inout_ PSRWLOCK); #endif // _STL_WIN32_WINNT >= _WIN32_WINNT_WIN7 diff --git a/stl/src/winapinls.cpp b/stl/src/winapinls.cpp index bf71f4479b7..a7a47a51348 100644 --- a/stl/src/winapinls.cpp +++ b/stl/src/winapinls.cpp @@ -652,7 +652,7 @@ extern "C" int __cdecl __crtLCMapStringEx(_In_opt_ LPCWSTR lpLocaleName, _In_ DW // __crtGetLocaleInfoEx() - Wrapper for GetLocaleInfoEx(). extern "C" int __cdecl __crtGetLocaleInfoEx(_In_opt_ LPCWSTR const lpLocaleName, _In_ LCTYPE const LCType, - _Out_opt_ LPWSTR const lpLCData, _In_ int const cchData) { + _Out_writes_opt_(cchData) LPWSTR const lpLCData, _In_ int const cchData) { IFDYNAMICGETCACHEDFUNCTION(PFNGETLOCALEINFOEX, GetLocaleInfoEx, pfGetLocaleInfoEx) { return pfGetLocaleInfoEx(lpLocaleName, LCType, lpLCData, cchData); } diff --git a/stl/src/winapisupp.cpp b/stl/src/winapisupp.cpp index 22fa1bab35d..9e51805873c 100644 --- a/stl/src/winapisupp.cpp +++ b/stl/src/winapisupp.cpp @@ -131,7 +131,7 @@ extern "C" BOOL __cdecl __crtIsPackagedApp() { #if _STL_WIN32_WINNT < _WIN32_WINNT_WS03 -extern "C" DWORD __cdecl __crtFlsAlloc(__in PFLS_CALLBACK_FUNCTION const lpCallback) { +extern "C" DWORD __cdecl __crtFlsAlloc(_In_opt_ PFLS_CALLBACK_FUNCTION const lpCallback) { // use FlsAlloc if it is available (only on Windows Server 2003+)... IFDYNAMICGETCACHEDFUNCTION(PFNFLSALLOC, FlsAlloc, pfFlsAlloc) { return pfFlsAlloc(lpCallback); @@ -141,7 +141,7 @@ extern "C" DWORD __cdecl __crtFlsAlloc(__in PFLS_CALLBACK_FUNCTION const lpCallb return TlsAlloc(); } -extern "C" BOOL __cdecl __crtFlsFree(__in DWORD const dwFlsIndex) { +extern "C" BOOL __cdecl __crtFlsFree(_In_ DWORD const dwFlsIndex) { // use FlsFree if it is available (only on Windows Server 2003+)... IFDYNAMICGETCACHEDFUNCTION(PFNFLSFREE, FlsFree, pfFlsFree) { return pfFlsFree(dwFlsIndex); @@ -151,7 +151,7 @@ extern "C" BOOL __cdecl __crtFlsFree(__in DWORD const dwFlsIndex) { return TlsFree(dwFlsIndex); } -extern "C" PVOID __cdecl __crtFlsGetValue(__in DWORD const dwFlsIndex) { +extern "C" PVOID __cdecl __crtFlsGetValue(_In_ DWORD const dwFlsIndex) { // use FlsGetValue if it is available (only on Windows Server 2003+)... IFDYNAMICGETCACHEDFUNCTION(PFNFLSGETVALUE, FlsGetValue, pfFlsGetValue) { return pfFlsGetValue(dwFlsIndex); @@ -161,7 +161,7 @@ extern "C" PVOID __cdecl __crtFlsGetValue(__in DWORD const dwFlsIndex) { return TlsGetValue(dwFlsIndex); } -extern "C" BOOL __cdecl __crtFlsSetValue(__in DWORD const dwFlsIndex, __in_opt PVOID const lpFlsData) { +extern "C" BOOL __cdecl __crtFlsSetValue(_In_ DWORD const dwFlsIndex, _In_opt_ PVOID const lpFlsData) { // use FlsSetValue if it is available (only on Windows Server 2003+)... IFDYNAMICGETCACHEDFUNCTION(PFNFLSSETVALUE, FlsSetValue, pfFlsSetValue) { return pfFlsSetValue(dwFlsIndex, lpFlsData); @@ -188,7 +188,7 @@ extern "C" ULONGLONG __cdecl __crtGetTickCount64() { } extern "C" BOOL __cdecl __crtInitializeCriticalSectionEx( - __out LPCRITICAL_SECTION const lpCriticalSection, __in DWORD const dwSpinCount, __in DWORD const Flags) { + _Out_ LPCRITICAL_SECTION const lpCriticalSection, _In_ DWORD const dwSpinCount, _In_ DWORD const Flags) { // use InitializeCriticalSectionEx if it is available (only on Windows Vista+)... IFDYNAMICGETCACHEDFUNCTION( PFNINITIALIZECRITICALSECTIONEX, InitializeCriticalSectionEx, pfInitializeCriticalSectionEx) { @@ -242,8 +242,8 @@ extern "C" BOOL __cdecl __crtInitOnceExecuteOnce(_Inout_ PINIT_ONCE const InitOn } } -extern "C" HANDLE __cdecl __crtCreateEventExW(__in_opt LPSECURITY_ATTRIBUTES const lpEventAttributes, - __in_opt LPCWSTR const lpName, __reserved DWORD const dwFlags, __in DWORD const dwDesiredAccess) { +extern "C" HANDLE __cdecl __crtCreateEventExW(_In_opt_ LPSECURITY_ATTRIBUTES const lpEventAttributes, + _In_opt_ LPCWSTR const lpName, _In_ DWORD const dwFlags, _In_ DWORD const dwDesiredAccess) { // use CreateEventEx if it is available (only on Windows Vista+)... IFDYNAMICGETCACHEDFUNCTION(PFNCREATEEVENTEXW, CreateEventExW, pfCreateEventExW) { return pfCreateEventExW(lpEventAttributes, lpName, dwFlags, dwDesiredAccess); @@ -254,9 +254,9 @@ extern "C" HANDLE __cdecl __crtCreateEventExW(__in_opt LPSECURITY_ATTRIBUTES con lpEventAttributes, dwFlags & CREATE_EVENT_MANUAL_RESET, dwFlags & CREATE_EVENT_INITIAL_SET, lpName); } -extern "C" HANDLE __cdecl __crtCreateSemaphoreExW(__in_opt LPSECURITY_ATTRIBUTES const lpSemaphoreAttributes, - __in LONG const lInitialCount, __in LONG const lMaximumCount, __in_opt LPCWSTR const lpName, - __reserved DWORD const dwFlags, __in DWORD const dwDesiredAccess) { +extern "C" HANDLE __cdecl __crtCreateSemaphoreExW(_In_opt_ LPSECURITY_ATTRIBUTES const lpSemaphoreAttributes, + _In_ LONG const lInitialCount, _In_ LONG const lMaximumCount, _In_opt_ LPCWSTR const lpName, + _Reserved_ DWORD const dwFlags, _In_ DWORD const dwDesiredAccess) { // use CreateSemaphoreEx if it is available (only on Windows Vista+)... IFDYNAMICGETCACHEDFUNCTION(PFNCREATESEMAPHOREEXW, CreateSemaphoreExW, pfCreateSemaphoreExW) { return pfCreateSemaphoreExW( @@ -273,7 +273,7 @@ extern "C" HANDLE __cdecl __crtCreateSemaphoreExW(__in_opt LPSECURITY_ATTRIBUTES } extern "C" PTP_TIMER __cdecl __crtCreateThreadpoolTimer( - __in PTP_TIMER_CALLBACK const pfnti, __inout_opt PVOID const pv, __in_opt PTP_CALLBACK_ENVIRON const pcbe) { + _In_ PTP_TIMER_CALLBACK const pfnti, _Inout_opt_ PVOID const pv, _In_opt_ PTP_CALLBACK_ENVIRON const pcbe) { // use CreateThreadpoolTimer if it is available (only on Windows Vista+)... IFDYNAMICGETCACHEDFUNCTION(PFNCREATETHREADPOOLTIMER, CreateThreadpoolTimer, pfCreateThreadpoolTimer) { return pfCreateThreadpoolTimer(pfnti, pv, pcbe); @@ -283,8 +283,8 @@ extern "C" PTP_TIMER __cdecl __crtCreateThreadpoolTimer( return nullptr; } -extern "C" VOID __cdecl __crtSetThreadpoolTimer(__inout PTP_TIMER const pti, __in_opt PFILETIME const pftDueTime, - __in DWORD const msPeriod, __in_opt DWORD const msWindowLength) { +extern "C" VOID __cdecl __crtSetThreadpoolTimer(_Inout_ PTP_TIMER const pti, _In_opt_ PFILETIME const pftDueTime, + _In_ DWORD const msPeriod, _In_opt_ DWORD const msWindowLength) { // use SetThreadpoolTimer if it is available (only on Windows Vista+)... IFDYNAMICGETCACHEDFUNCTION(PFNSETTHREADPOOLTIMER, SetThreadpoolTimer, pfSetThreadpoolTimer) { pfSetThreadpoolTimer(pti, pftDueTime, msPeriod, msWindowLength); @@ -295,7 +295,7 @@ extern "C" VOID __cdecl __crtSetThreadpoolTimer(__inout PTP_TIMER const pti, __i } extern "C" VOID __cdecl __crtWaitForThreadpoolTimerCallbacks( - __inout PTP_TIMER const pti, __in BOOL const fCancelPendingCallbacks) { + _Inout_ PTP_TIMER const pti, _In_ BOOL const fCancelPendingCallbacks) { // use WaitForThreadpoolTimerCallbacks if it is available (only on Windows Vista+)... IFDYNAMICGETCACHEDFUNCTION( PFNWAITFORTHREADPOOLTIMERCALLBACKS, WaitForThreadpoolTimerCallbacks, pfWaitForThreadpoolTimerCallbacks) { @@ -306,7 +306,7 @@ extern "C" VOID __cdecl __crtWaitForThreadpoolTimerCallbacks( return; } -extern "C" VOID __cdecl __crtCloseThreadpoolTimer(__inout PTP_TIMER const pti) { +extern "C" VOID __cdecl __crtCloseThreadpoolTimer(_Inout_ PTP_TIMER const pti) { // use CloseThreadpoolTimer if it is available (only on Windows Vista+)... IFDYNAMICGETCACHEDFUNCTION(PFNCLOSETHREADPOOLTIMER, CloseThreadpoolTimer, pfCloseThreadpoolTimer) { pfCloseThreadpoolTimer(pti); @@ -317,7 +317,7 @@ extern "C" VOID __cdecl __crtCloseThreadpoolTimer(__inout PTP_TIMER const pti) { } extern "C" PTP_WAIT __cdecl __crtCreateThreadpoolWait( - __in PTP_WAIT_CALLBACK const pfnwa, __inout_opt PVOID const pv, __in_opt PTP_CALLBACK_ENVIRON const pcbe) { + _In_ PTP_WAIT_CALLBACK const pfnwa, _Inout_opt_ PVOID const pv, _In_opt_ PTP_CALLBACK_ENVIRON const pcbe) { // use CreateThreadpoolWait if it is available (only on Windows Vista+)... IFDYNAMICGETCACHEDFUNCTION(PFNCREATETHREADPOOLWAIT, CreateThreadpoolWait, pfCreateThreadpoolWait) { return pfCreateThreadpoolWait(pfnwa, pv, pcbe); @@ -328,7 +328,7 @@ extern "C" PTP_WAIT __cdecl __crtCreateThreadpoolWait( } extern "C" VOID __cdecl __crtSetThreadpoolWait( - __inout PTP_WAIT const pwa, __in_opt HANDLE const h, __in_opt PFILETIME const pftTimeout) { + _Inout_ PTP_WAIT const pwa, _In_opt_ HANDLE const h, _In_opt_ PFILETIME const pftTimeout) { // use SetThreadpoolWait if it is available (only on Windows Vista+)... IFDYNAMICGETCACHEDFUNCTION(PFNSETTHREADPOOLWAIT, SetThreadpoolWait, pfSetThreadpoolWait) { pfSetThreadpoolWait(pwa, h, pftTimeout); @@ -337,7 +337,7 @@ extern "C" VOID __cdecl __crtSetThreadpoolWait( // ...otherwise there is no fall back. } -extern "C" VOID __cdecl __crtCloseThreadpoolWait(__inout PTP_WAIT const pwa) { +extern "C" VOID __cdecl __crtCloseThreadpoolWait(_Inout_ PTP_WAIT const pwa) { // use CloseThreadpoolWait if it is available (only on Windows Vista+)... IFDYNAMICGETCACHEDFUNCTION(PFNCLOSETHREADPOOLWAIT, CloseThreadpoolWait, pfCloseThreadpoolWait) { pfCloseThreadpoolWait(pwa); @@ -356,7 +356,7 @@ extern "C" VOID __cdecl __crtFlushProcessWriteBuffers() { } extern "C" VOID __cdecl __crtFreeLibraryWhenCallbackReturns( - __inout PTP_CALLBACK_INSTANCE const pci, __in HMODULE const mod) { + _Inout_ PTP_CALLBACK_INSTANCE const pci, _In_ HMODULE const mod) { // use FreeLibraryWhenCallbackReturns if it is available (only on Windows Vista+)... IFDYNAMICGETCACHEDFUNCTION( PFNFREELIBRARYWHENCALLBACKRETURNS, FreeLibraryWhenCallbackReturns, pfFreeLibraryWhenCallbackReturns) { @@ -377,7 +377,7 @@ extern "C" DWORD __cdecl __crtGetCurrentProcessorNumber() { } extern "C" BOOLEAN __cdecl __crtCreateSymbolicLinkW( - __in LPCWSTR const lpSymlinkFileName, __in LPCWSTR const lpTargetFileName, __in DWORD const dwFlags) { + _In_ LPCWSTR const lpSymlinkFileName, _In_ LPCWSTR const lpTargetFileName, _In_ DWORD const dwFlags) { // use CreateSymbolicLink if it is available (only on Windows Vista+)... IFDYNAMICGETCACHEDFUNCTION(PFNCREATESYMBOLICLINKW, CreateSymbolicLinkW, pfCreateSymbolicLink) { return pfCreateSymbolicLink(lpSymlinkFileName, lpTargetFileName, dwFlags); @@ -389,8 +389,8 @@ extern "C" BOOLEAN __cdecl __crtCreateSymbolicLinkW( } extern "C" _Success_(return ) BOOL __cdecl __crtGetFileInformationByHandleEx(_In_ HANDLE const hFile, - _In_ FILE_INFO_BY_HANDLE_CLASS const FileInformationClass, _Out_ LPVOID const lpFileInformation, - _In_ DWORD const dwBufferSize) { + _In_ FILE_INFO_BY_HANDLE_CLASS const FileInformationClass, + _Out_writes_bytes_(dwBufferSize) LPVOID const lpFileInformation, _In_ DWORD const dwBufferSize) { // use GetFileInformationByHandleEx if it is available (only on Windows Vista+)... IFDYNAMICGETCACHEDFUNCTION( PFNGETFILEINFORMATIONBYHANDLEEX, GetFileInformationByHandleEx, pfGetFileInformationByHandleEx) { @@ -403,8 +403,8 @@ extern "C" _Success_(return ) BOOL __cdecl __crtGetFileInformationByHandleEx(_In } extern "C" BOOL __cdecl __crtSetFileInformationByHandle(_In_ HANDLE const hFile, - _In_ FILE_INFO_BY_HANDLE_CLASS const FileInformationClass, _In_ LPVOID const lpFileInformation, - _In_ DWORD const dwBufferSize) { + _In_ FILE_INFO_BY_HANDLE_CLASS const FileInformationClass, + _In_reads_bytes_(dwBufferSize) LPVOID const lpFileInformation, _In_ DWORD const dwBufferSize) { // use SetFileInformationByHandle if it is available (only on Windows Vista+)... IFDYNAMICGETCACHEDFUNCTION( PFNSETFILEINFORMATIONBYHANDLE, SetFileInformationByHandle, pfSetFileInformationByHandle) { @@ -416,71 +416,71 @@ extern "C" BOOL __cdecl __crtSetFileInformationByHandle(_In_ HANDLE const hFile, return 0; } -extern "C" VOID __cdecl __crtInitializeConditionVariable(__out PCONDITION_VARIABLE const pCond) { +extern "C" VOID __cdecl __crtInitializeConditionVariable(_Out_ PCONDITION_VARIABLE const pCond) { DYNAMICGETCACHEDFUNCTION( PFNINITIALIZECONDITIONVARIABLE, InitializeConditionVariable, pfInitializeConditionVariable); pfInitializeConditionVariable(pCond); // Don't have fallbacks because the only caller (in primitives.hpp) will check the existence before calling } -extern "C" VOID __cdecl __crtWakeConditionVariable(__inout PCONDITION_VARIABLE const pCond) { +extern "C" VOID __cdecl __crtWakeConditionVariable(_Inout_ PCONDITION_VARIABLE const pCond) { DYNAMICGETCACHEDFUNCTION(PFNWAKECONDITIONVARIABLE, WakeConditionVariable, pfWakeConditionVariable); pfWakeConditionVariable(pCond); // Don't have fallbacks because the only caller (in primitives.hpp) will check the existence before calling } -extern "C" VOID __cdecl __crtWakeAllConditionVariable(__inout PCONDITION_VARIABLE const pCond) { +extern "C" VOID __cdecl __crtWakeAllConditionVariable(_Inout_ PCONDITION_VARIABLE const pCond) { DYNAMICGETCACHEDFUNCTION(PFNWAKEALLCONDITIONVARIABLE, WakeAllConditionVariable, pfWakeAllConditionVariable); pfWakeAllConditionVariable(pCond); // Don't have fallbacks because the only caller (in primitives.hpp) will check the existence before calling } extern "C" BOOL __cdecl __crtSleepConditionVariableCS( - __inout PCONDITION_VARIABLE const pCond, __inout PCRITICAL_SECTION const pLock, __in DWORD const dwMs) { + _Inout_ PCONDITION_VARIABLE const pCond, _Inout_ PCRITICAL_SECTION const pLock, _In_ DWORD const dwMs) { DYNAMICGETCACHEDFUNCTION(PFNSLEEPCONDITIONVARIABLECS, SleepConditionVariableCS, pfSleepConditionVariableCS); return pfSleepConditionVariableCS(pCond, pLock, dwMs); // Don't have fallbacks because the only caller (in primitives.hpp) will check the existence before calling } -extern "C" VOID __cdecl __crtInitializeSRWLock(__out PSRWLOCK const pLock) { +extern "C" VOID __cdecl __crtInitializeSRWLock(_Out_ PSRWLOCK const pLock) { DYNAMICGETCACHEDFUNCTION(PFNINITIALIZESRWLOCK, InitializeSRWLock, pfInitializeSRWLock); pfInitializeSRWLock(pLock); // Don't have fallbacks because the only caller (in primitives.hpp) will check the existence before calling } -extern "C" VOID __cdecl __crtAcquireSRWLockExclusive(__inout PSRWLOCK const pLock) { +extern "C" VOID __cdecl __crtAcquireSRWLockExclusive(_Inout_ PSRWLOCK const pLock) { DYNAMICGETCACHEDFUNCTION(PFNACQUIRESRWLOCKEXCLUSIVE, AcquireSRWLockExclusive, pfAcquireSRWLockExclusive); pfAcquireSRWLockExclusive(pLock); // Don't have fallbacks because the only caller (in primitives.hpp) will check the existence before calling } -extern "C" VOID __cdecl __crtReleaseSRWLockExclusive(__inout PSRWLOCK const pLock) { +extern "C" VOID __cdecl __crtReleaseSRWLockExclusive(_Inout_ PSRWLOCK const pLock) { DYNAMICGETCACHEDFUNCTION(PFNRELEASESRWLOCKEXCLUSIVE, ReleaseSRWLockExclusive, pfReleaseSRWLockExclusive); pfReleaseSRWLockExclusive(pLock); // Don't have fallbacks because the only caller (in primitives.hpp) will check the existence before calling } -extern "C" BOOL __cdecl __crtSleepConditionVariableSRW(__inout PCONDITION_VARIABLE const pCond, - __inout PSRWLOCK const pLock, __in DWORD const dwMs, __in ULONG const flags) { +extern "C" BOOL __cdecl __crtSleepConditionVariableSRW(_Inout_ PCONDITION_VARIABLE const pCond, + _Inout_ PSRWLOCK const pLock, _In_ DWORD const dwMs, _In_ ULONG const flags) { DYNAMICGETCACHEDFUNCTION(PFNSLEEPCONDITIONVARIABLESRW, SleepConditionVariableSRW, pfSleepConditionVariableSRW); return pfSleepConditionVariableSRW(pCond, pLock, dwMs, flags); // Don't have fallbacks because the only caller (in primitives.hpp) will check the existence before calling } extern "C" PTP_WORK __cdecl __crtCreateThreadpoolWork( - __in PTP_WORK_CALLBACK const pfnwk, __inout_opt PVOID const pv, __in_opt PTP_CALLBACK_ENVIRON const pcbe) { + _In_ PTP_WORK_CALLBACK const pfnwk, _Inout_opt_ PVOID const pv, _In_opt_ PTP_CALLBACK_ENVIRON const pcbe) { DYNAMICGETCACHEDFUNCTION(PFNCREATETHREADPOOLWORK, CreateThreadpoolWork, pfCreateThreadpoolWork); return pfCreateThreadpoolWork(pfnwk, pv, pcbe); // Don't have fallbacks because the only caller (in taskscheduler.cpp) will check the existence before calling } -extern "C" VOID __cdecl __crtSubmitThreadpoolWork(__inout PTP_WORK const pwk) { +extern "C" VOID __cdecl __crtSubmitThreadpoolWork(_Inout_ PTP_WORK const pwk) { DYNAMICGETCACHEDFUNCTION(PFNSUBMITTHREADPOOLWORK, SubmitThreadpoolWork, pfSubmitThreadpoolWork); return pfSubmitThreadpoolWork(pwk); // Don't have fallbacks because the only caller (in taskscheduler.cpp) will check the existence before calling } -extern "C" VOID __cdecl __crtCloseThreadpoolWork(__inout PTP_WORK const pwk) { +extern "C" VOID __cdecl __crtCloseThreadpoolWork(_Inout_ PTP_WORK const pwk) { DYNAMICGETCACHEDFUNCTION(PFNCLOSETHREADPOOLWORK, CloseThreadpoolWork, pfCloseThreadpoolWork); return pfCloseThreadpoolWork(pwk); // Don't have fallbacks because the only caller (in taskscheduler.cpp) will check the existence before calling @@ -496,7 +496,7 @@ extern "C" BOOL __cdecl __crtQueueUserWorkItem(_In_ LPTHREAD_START_ROUTINE, _In_ #if _STL_WIN32_WINNT < _WIN32_WINNT_WIN7 -extern "C" BOOLEAN __cdecl __crtTryAcquireSRWLockExclusive(__inout PSRWLOCK const pLock) { +extern "C" BOOLEAN __cdecl __crtTryAcquireSRWLockExclusive(_Inout_ PSRWLOCK const pLock) { DYNAMICGETCACHEDFUNCTION(PFNTRYACQUIRESRWLOCKEXCLUSIVE, TryAcquireSRWLockExclusive, pfTryAcquireSRWLockExclusive); return pfTryAcquireSRWLockExclusive(pLock); // Don't have fallbacks because the only caller (in primitives.hpp) will check the existence before calling From 36c1268daafa2ac6712ff9424ee278ce67fe9243 Mon Sep 17 00:00:00 2001 From: Curtis Jacques Bezault Date: Mon, 24 Aug 2020 09:50:48 -0700 Subject: [PATCH 16/17] Only /analyze during CI --- CMakeLists.txt | 2 +- azure-devops/run-build.yml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e5ba8bfbe3d..15fde682ba6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -67,7 +67,7 @@ add_compile_definitions( _ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH WIN32_LEAN_AND_MEAN STRICT _CRT_STDIO_ARBITRARY_WIDE_SPECIFIERS _CRT_DECLARE_NONSTDC_NAMES=1 ) -add_compile_options(/diagnostics:caret /analyze /W4 /WX /w14265 /w15038 /d1FastFail /guard:cf /Z7 /d2Zi+ /Gm- /Gy /Zp8 /std:c++latest /permissive- /Zc:threadSafeInit- /Zl) +add_compile_options(/diagnostics:caret /W4 /WX /w14265 /w15038 /d1FastFail /guard:cf /Z7 /d2Zi+ /Gm- /Gy /Zp8 /std:c++latest /permissive- /Zc:threadSafeInit- /Zl) set(VCLIBS_DEBUG_OPTIONS "/Od") set(VCLIBS_RELEASE_OPTIONS "/O2;/Os") # TRANSITION: Potentially remove /Os diff --git a/azure-devops/run-build.yml b/azure-devops/run-build.yml index 35e2f959607..0a517388607 100644 --- a/azure-devops/run-build.yml +++ b/azure-devops/run-build.yml @@ -65,6 +65,7 @@ jobs: cmake -G Ninja -DCMAKE_TOOLCHAIN_FILE=$(vcpkgLocation)\scripts\buildsystems\vcpkg.cmake ^ -DVCPKG_TARGET_TRIPLET=${{ parameters.targetPlatform }}-windows -DCMAKE_CXX_COMPILER=cl ^ -DCMAKE_BUILD_TYPE=Release -DLIT_FLAGS=$(litFlags) ^ + -DCMAKE_CXX_FLAGS=/analyze ^ -S $(Build.SourcesDirectory) -B $(buildOutputLocation) cmake --build $(buildOutputLocation) displayName: 'Build the STL' From c42d5ebf515eba01d31f8e1a98e5e6fb9d2649ea Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Tue, 25 Aug 2020 18:03:23 -0700 Subject: [PATCH 17/17] Fix /clr:pure build break. --- stl/src/xxxprec.hpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/stl/src/xxxprec.hpp b/stl/src/xxxprec.hpp index e708ffbf059..929bbc5aea3 100644 --- a/stl/src/xxxprec.hpp +++ b/stl/src/xxxprec.hpp @@ -6,6 +6,10 @@ #include #include "xmath.hpp" + +#pragma warning(push) +#pragma warning(disable : _STL_DISABLED_WARNINGS) + #if !defined(MRTDLL) _EXTERN_C #endif // defined(MRTDLL) @@ -425,3 +429,5 @@ FTYPE* FNAME(Xp_sqrtx)(FTYPE* p, int n, FTYPE* ptemp4) { #if !defined(MRTDLL) _END_EXTERN_C #endif // !defined(MRTDLL) + +#pragma warning(pop)