diff --git a/CMakeLists.txt b/CMakeLists.txt index 3a3ca0e8f76..15fde682ba6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -67,7 +67,6 @@ 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) set(VCLIBS_DEBUG_OPTIONS "/Od") 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' 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 2e3fcddde59..7991c1d522e 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,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 __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 _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; @@ -280,8 +281,8 @@ _NODISCARD __std_fs_convert_result __stdcall __std_fs_convert_wide_to_narrow_rep _In_ __std_code_page _Code_page, _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; @@ -289,11 +290,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; @@ -309,8 +311,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/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..bb5651e3bce 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_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 // 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..d388a2a7770 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_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 // 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..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,74 +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, _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); +_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 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, @@ -197,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 @@ -207,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 @@ -228,7 +231,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 @@ -342,20 +345,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_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_ LPCWSTR _LocaleName, _In_ DWORD _DWMapFlag, - _In_reads_(_CchSrc) LPCWSTR _LpSrcStr, _In_ int _CchSrc, _Out_writes_opt_(_CchDest) LPWSTR _LpDestStr, +_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); _CRT_END_C_HEADER diff --git a/stl/src/excptptr.cpp b/stl/src/excptptr.cpp index b0e85953014..e790d750263 100644 --- a/stl/src/excptptr.cpp +++ b/stl/src/excptptr.cpp @@ -108,7 +108,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 @@ -340,7 +341,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; @@ -422,33 +424,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)); } @@ -470,7 +473,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) { @@ -512,6 +515,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 @@ -531,7 +536,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 063f5f9c7a6..c5f3232e377 100644 --- a/stl/src/filesystem.cpp +++ b/stl/src/filesystem.cpp @@ -260,15 +260,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); @@ -282,9 +282,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); @@ -311,9 +312,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}; @@ -322,8 +324,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))}; @@ -349,14 +351,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; } @@ -378,15 +380,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,9 @@ void __stdcall __std_fs_directory_iterator_close(const __std_fs_dir_handle _Hand } [[nodiscard]] __std_fs_convert_result __stdcall __std_fs_convert_wide_to_narrow_replace_chars( - 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 { + _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; _Result._Len = WideCharToMultiByte(static_cast(_Code_page), WC_NO_BEST_FIT_CHARS, _Input_str, @@ -441,8 +446,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 = @@ -506,7 +511,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); @@ -518,7 +524,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; } @@ -548,12 +555,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; @@ -568,12 +575,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 @@ -585,8 +592,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); @@ -606,7 +614,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); @@ -621,7 +629,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 @@ -695,7 +703,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()}; @@ -741,7 +749,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; } @@ -750,7 +758,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) { @@ -766,8 +774,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"); @@ -843,7 +852,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, @@ -901,8 +911,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, __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)); @@ -1054,7 +1065,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}; } @@ -1075,7 +1086,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); @@ -1093,8 +1104,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); @@ -1105,7 +1117,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/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/primitives.hpp b/stl/src/primitives.hpp index 85eabcfb821..2f335143af1 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 : 6297 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 105b54b268a..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 @@ -472,9 +473,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) { 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; diff --git a/stl/src/winapinls.cpp b/stl/src/winapinls.cpp index 55badb6a18b..a7a47a51348 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_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 202995a9e1f..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(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(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) { @@ -195,12 +196,11 @@ 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( - 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 +242,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, _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(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 +273,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 +283,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 +294,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 +306,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 +317,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 +327,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 +337,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 +355,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 +377,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 +388,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_writes_bytes_(dwBufferSize) LPVOID const lpFileInformation, _In_ DWORD const dwBufferSize) { // use GetFileInformationByHandleEx if it is available (only on Windows Vista+)... IFDYNAMICGETCACHEDFUNCTION( PFNGETFILEINFORMATIONBYHANDLEEX, GetFileInformationByHandleEx, pfGetFileInformationByHandleEx) { @@ -398,8 +402,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_reads_bytes_(dwBufferSize) LPVOID const lpFileInformation, _In_ DWORD const dwBufferSize) { // use SetFileInformationByHandle if it is available (only on Windows Vista+)... IFDYNAMICGETCACHEDFUNCTION( PFNSETFILEINFORMATIONBYHANDLE, SetFileInformationByHandle, pfSetFileInformationByHandle) { @@ -411,78 +416,78 @@ 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 } #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; } @@ -491,7 +496,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 @@ -529,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); diff --git a/stl/src/xmath.hpp b/stl/src/xmath.hpp index 32bd8b60f7b..200d7a9d981 100644 --- a/stl/src/xmath.hpp +++ b/stl/src/xmath.hpp @@ -49,11 +49,15 @@ _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/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/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/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..ab3692be410 100644 --- a/stl/src/xwcsxfrm.cpp +++ b/stl/src/xwcsxfrm.cpp @@ -44,12 +44,12 @@ _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) { - size_t n1 = end1 - string1; - size_t n2 = end2 - string2; - size_t size = static_cast(-1); - unsigned char* bbuffer = nullptr; +_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); const wchar_t* locale_name; if (ploc == nullptr) { @@ -71,11 +71,12 @@ _CRTIMP2_PURE size_t __CLRCALL_PURE_OR_CDECL _Wcsxfrm( // 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. @@ -88,16 +89,12 @@ _CRTIMP2_PURE size_t __CLRCALL_PURE_OR_CDECL _Wcsxfrm( // 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; } 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 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; diff --git a/stl/src/xxxprec.hpp b/stl/src/xxxprec.hpp index a5990e030d7..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) @@ -63,20 +67,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 -#pragma warning(suppress : 4127) - if ((FBITS & 1) != 0 && 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); @@ -85,10 +100,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; @@ -412,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)