Skip to content

Commit

Permalink
Turn on /analyze (for PR/CI builds) and fix resulting warnings (micro…
Browse files Browse the repository at this point in the history
…soft#1009)

Co-authored-by: Stephan T. Lavavej <[email protected]>
Co-authored-by: Curtis Jacques Bezault <[email protected]>
  • Loading branch information
3 people authored Aug 26, 2020
1 parent 484fbc9 commit 5bf2826
Show file tree
Hide file tree
Showing 30 changed files with 303 additions and 224 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
1 change: 1 addition & 0 deletions azure-devops/run-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion stl/inc/exception
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
29 changes: 16 additions & 13 deletions stl/inc/xfilesystem_abi.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand All @@ -280,20 +281,21 @@ _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;

_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;

Expand All @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions stl/inc/xlocinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 )
Expand Down
6 changes: 4 additions & 2 deletions stl/src/StlCompareStringA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(__strncnt(lpString1, cchCount1));
Expand Down Expand Up @@ -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<wchar_t> wbuffer2(_malloca_crt_t(wchar_t, buff_size2));
if (wbuffer2.get() == nullptr) {
return 0;
Expand Down
5 changes: 3 additions & 2 deletions stl/src/StlCompareStringW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 4 additions & 2 deletions stl/src/StlLCMapStringA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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<wchar_t> outwbuffer(_malloca_crt_t(wchar_t, outbuff_size));
if (!outwbuffer) {
return retval;
Expand Down
5 changes: 3 additions & 2 deletions stl/src/StlLCMapStringW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading

0 comments on commit 5bf2826

Please sign in to comment.