From 85e3ac682ce2f5d86b09515bd9ef95f7bba68501 Mon Sep 17 00:00:00 2001 From: Alexander Riccio Date: Sun, 8 Feb 2015 03:56:49 -0500 Subject: [PATCH] hopefully fixed issue #3 In issue #3, GetDateFormat was bitching mysteriously. Of course, the default windows error message was useless. So I went ahead and added a crapload of diagnostics & error reporting to clarify what's going on. I also refactored some arrow code, here and there. --- WinDirStat/windirstat/PageGeneral.cpp | 27 +- WinDirStat/windirstat/SelectDrivesDlg.cpp | 4 +- WinDirStat/windirstat/SelectDrivesDlg.h | 2 +- WinDirStat/windirstat/datastructures.h | 2 + WinDirStat/windirstat/globalhelpers.cpp | 694 +++++++++++------- WinDirStat/windirstat/globalhelpers.h | 24 +- WinDirStat/windirstat/item.cpp | 6 +- WinDirStat/windirstat/item.h | 2 +- WinDirStat/windirstat/mainframe.cpp | 2 +- WinDirStat/windirstat/options.cpp | 90 ++- WinDirStat/windirstat/options.h | 18 +- WinDirStat/windirstat/ownerdrawnlistcontrol.h | 22 +- WinDirStat/windirstat/typeview.cpp | 6 +- WinDirStat/windirstat/typeview.h | 2 +- WinDirStat/windirstat/windirstat.cpp | 3 +- WinDirStat/windirstat/windirstat.vcxproj | 8 + 16 files changed, 538 insertions(+), 374 deletions(-) diff --git a/WinDirStat/windirstat/PageGeneral.cpp b/WinDirStat/windirstat/PageGeneral.cpp index 5dcd8e7..4a1e340 100644 --- a/WinDirStat/windirstat/PageGeneral.cpp +++ b/WinDirStat/windirstat/PageGeneral.cpp @@ -26,13 +26,13 @@ _Must_inspect_result_ COptionsPropertySheet* CPageGeneral::GetSheet( ) { } BEGIN_MESSAGE_MAP(CPageGeneral, CPropertyPage) - ON_BN_CLICKED(IDC_HUMANFORMAT, &( CPageGeneral::OnBnClickedAnyOption ) ) + ON_BN_CLICKED(IDC_HUMANFORMAT, &( CPageGeneral::OnBnClickedAnyOption ) ) ON_BN_CLICKED(IDC_FOLLOWMOUNTPOINTS, &( CPageGeneral::OnBnClickedAnyOption ) ) - ON_BN_CLICKED(IDC_FOLLOWJUNCTIONS, &( CPageGeneral::OnBnClickedAnyOption ) ) - ON_BN_CLICKED(IDC_SHOWGRID, &( CPageGeneral::OnBnClickedAnyOption ) ) - ON_BN_CLICKED(IDC_SHOWSTRIPES, &( CPageGeneral::OnBnClickedAnyOption ) ) - ON_BN_CLICKED(IDC_FULLROWSELECTION, &( CPageGeneral::OnBnClickedAnyOption ) ) - ON_BN_CLICKED(IDC_SHOWTIMESPENT, &( CPageGeneral::OnBnClickedAnyOption ) ) + ON_BN_CLICKED(IDC_FOLLOWJUNCTIONS, &( CPageGeneral::OnBnClickedAnyOption ) ) + ON_BN_CLICKED(IDC_SHOWGRID, &( CPageGeneral::OnBnClickedAnyOption ) ) + ON_BN_CLICKED(IDC_SHOWSTRIPES, &( CPageGeneral::OnBnClickedAnyOption ) ) + ON_BN_CLICKED(IDC_FULLROWSELECTION, &( CPageGeneral::OnBnClickedAnyOption ) ) + ON_BN_CLICKED(IDC_SHOWTIMESPENT, &( CPageGeneral::OnBnClickedAnyOption ) ) END_MESSAGE_MAP() @@ -62,14 +62,13 @@ void CPageGeneral::OnOK( ) { VERIFY( UpdateData( ) ); const auto Options = GetOptions( ); //Compare with TRUE to prevent int->bool coercion - Options->SetHumanFormat ( ( ( m_humanFormat == TRUE ) ? true : false ) ); - Options->m_followMountPoints = ( ( m_followMountPoints == TRUE ) ? true : false ); - Options->m_followJunctionPoints = ( ( m_followJunctionPoints == TRUE ) ? true : false ); - Options->SetListGrid ( ( ( m_listGrid == TRUE ) ? true : false ) ); - Options->SetListStripes ( ( ( m_listStripes == TRUE ) ? true : false ) ); - Options->SetListFullRowSelection ( ( ( m_listFullRowSelection == TRUE ) ? true : false ) ); - Options->m_showTimeSpent = ( ( m_showTimeSpent == TRUE ) ? true : false ); - + Options->m_followMountPoints = ( ( m_followMountPoints == TRUE ) ? true : false ); + Options->m_followJunctionPoints = ( ( m_followJunctionPoints == TRUE ) ? true : false ); + Options->m_showTimeSpent = ( ( m_showTimeSpent == TRUE ) ? true : false ); + Options->SetHumanFormat ( ( ( m_humanFormat == TRUE ) ? true : false ) ); + Options->SetListGrid ( ( ( m_listGrid == TRUE ) ? true : false ) ); + Options->SetListStripes ( ( ( m_listStripes == TRUE ) ? true : false ) ); + Options->SetListFullRowSelection( ( ( m_listFullRowSelection == TRUE ) ? true : false ) ); CPropertyPage::OnOK( ); } diff --git a/WinDirStat/windirstat/SelectDrivesDlg.cpp b/WinDirStat/windirstat/SelectDrivesDlg.cpp index 0a781aa..08379c3 100644 --- a/WinDirStat/windirstat/SelectDrivesDlg.cpp +++ b/WinDirStat/windirstat/SelectDrivesDlg.cpp @@ -209,13 +209,13 @@ INT CDriveItem::Compare( _In_ const COwnerDrawnListItem* const baseOther, RANGE_ } _Must_inspect_result_ _Success_( SUCCEEDED( return ) ) -HRESULT CDriveItem::Text_WriteToStackBuffer( RANGE_ENUM_COL const column::ENUM_COL subitem, WDS_WRITES_TO_STACK( strSize, chars_written ) PWSTR psz_text, _In_ const rsize_t strSize, _Out_ _On_failure_( _Post_valid_ ) rsize_t& sizeBuffNeed, _Out_ rsize_t& chars_written ) const { +HRESULT CDriveItem::Text_WriteToStackBuffer( RANGE_ENUM_COL const column::ENUM_COL subitem, WDS_WRITES_TO_STACK( strSize, chars_written ) PWSTR psz_text, _In_ const rsize_t strSize, _On_failure_( _Post_valid_ ) rsize_t& sizeBuffNeed, _Out_ rsize_t& chars_written ) const { switch ( subitem ) { case column::COL_TOTAL: case column::COL_FREE: //return Text_WriteToStackBuffer_COL_TOTAL( subitem, psz_text, strSize, sizeBuffNeed, chars_written ); - return wds_fmt::FormatBytes( ( ( subitem == column::COL_TOTAL ) ? m_totalBytes : m_freeBytes ), psz_text, strSize, chars_written ); + return wds_fmt::FormatBytes( ( ( subitem == column::COL_TOTAL ) ? m_totalBytes : m_freeBytes ), psz_text, strSize, chars_written, sizeBuffNeed ); case column::COL_NAME: case column::COL_ITEMS: case column::COL_BYTESPERCENT: diff --git a/WinDirStat/windirstat/SelectDrivesDlg.h b/WinDirStat/windirstat/SelectDrivesDlg.h index 6dadf8f..886e509 100644 --- a/WinDirStat/windirstat/SelectDrivesDlg.h +++ b/WinDirStat/windirstat/SelectDrivesDlg.h @@ -48,7 +48,7 @@ class CDriveItem final : public COwnerDrawnListItem { } _Must_inspect_result_ _Success_( SUCCEEDED( return ) ) - virtual HRESULT Text_WriteToStackBuffer( RANGE_ENUM_COL const column::ENUM_COL subitem, WDS_WRITES_TO_STACK( strSize, chars_written ) PWSTR psz_text, _In_ const rsize_t strSize, _Out_ _On_failure_( _Post_valid_ ) rsize_t& sizeBuffNeed, _Out_ rsize_t& chars_written ) const override final; + virtual HRESULT Text_WriteToStackBuffer( RANGE_ENUM_COL const column::ENUM_COL subitem, WDS_WRITES_TO_STACK( strSize, chars_written ) PWSTR psz_text, _In_ const rsize_t strSize, _On_failure_( _Post_valid_ ) rsize_t& sizeBuffNeed, _Out_ rsize_t& chars_written ) const override final; public: const std::wstring m_path; // e.g. "C:\" diff --git a/WinDirStat/windirstat/datastructures.h b/WinDirStat/windirstat/datastructures.h index 4ef30f3..24e166d 100644 --- a/WinDirStat/windirstat/datastructures.h +++ b/WinDirStat/windirstat/datastructures.h @@ -494,6 +494,8 @@ namespace global_strings { _Null_terminated_ const wchar_t get_date_format_param_err[ ] = { L"Any of the parameter values ( for GetDateFormatW ) was invalid." }; _Null_terminated_ const wchar_t get_time_format_param_err[ ] = { L"Any of the parameter values ( for GetTimeFormatW ) was invalid." }; + _Null_terminated_ const wchar_t get_time_format_err_OUTOFMEMORY[ ] = { L"GetTimeFormatW failed because not enough memory was available to complete this operation! (unrecoverable)" }; + _Null_terminated_ const wchar_t write_to_stackbuffer_file[ ] = { L"Not implemented yet. Try normal GetText." }; _Null_terminated_ const wchar_t global_alloc_failed[ ] = { L"GlobalAlloc failed! Cannot copy to clipboard!" }; diff --git a/WinDirStat/windirstat/globalhelpers.cpp b/WinDirStat/windirstat/globalhelpers.cpp index baaad90..c79a881 100644 --- a/WinDirStat/windirstat/globalhelpers.cpp +++ b/WinDirStat/windirstat/globalhelpers.cpp @@ -17,6 +17,12 @@ #define BASE 1024 #define HALF_BASE BASE/2 namespace { + + const PCWSTR date_time_format_locale_name_str = LOCALE_NAME_INVARIANT; + const DWORD GetDateFormatEx_flags = DATE_SHORTDATE; + const DWORD GetTimeFormatEx_flags = 0; + + std::wstring Format_uint64_t_Normal( _In_ std::uint64_t n ) { // Returns formatted number like "123.456.789". // 18446744073709551615 is max @@ -24,82 +30,193 @@ namespace { // 18,446,744,073,709,551,615 // ^26 characters // 26 + null terminator = 27 - //const rsize_t bufSize = 28; - //wchar_t buffer[ bufSize ] = { 0 }; + //const rsize_t number_formatted_buffer_size = 28; + //wchar_t buffer[ number_formatted_buffer_size ] = { 0 }; std::wstring all_ws; all_ws.reserve( 27 ); do { - auto rest = INT( n % 1000 ); + const auto rest = static_cast( n % 1000 ); n /= 1000; - const rsize_t tempBuf_size = 10; + const rsize_t tempBuf_size = 10u; _Null_terminated_ wchar_t tempBuf[ tempBuf_size ] = { 0 }; if ( n > 0 ) { - //wprintf( ); const HRESULT fmt_res = StringCchPrintfW( tempBuf, tempBuf_size, L",%03d", rest ); ASSERT( SUCCEEDED( fmt_res ) ); if ( !SUCCEEDED( fmt_res ) ) { return L"FORMATTING FAILED!"; } - - //const auto pf_res = _snwprintf_s( tempBuf, 9, _TRUNCATE, L",%03d", rest ); - //ASSERT( pf_res != -1 ); + all_ws += tempBuf; } else { - const HRESULT fmt_res = StringCchPrintfW( tempBuf, tempBuf_size, L"%d", rest ); - ASSERT( SUCCEEDED( fmt_res ) ); - if ( !SUCCEEDED( fmt_res ) ) { - return L"FORMATTING FAILED!"; - } - - //const auto pf_res = _snwprintf_s( tempBuf, 9, _TRUNCATE, L"%d", rest ); - //ASSERT( pf_res != -1 ); + all_ws += std::to_wstring( rest ); + //const HRESULT fmt_res = StringCchPrintfW( tempBuf, tempBuf_size, L"%d", rest ); + //ASSERT( SUCCEEDED( fmt_res ) ); + //if ( !SUCCEEDED( fmt_res ) ) { + // return L"FORMATTING FAILED!"; + // } } - all_ws += tempBuf; - //wcscat_s( buffer, tempBuf ); - } - while ( n > 0 ); + //all_ws += tempBuf; + } while ( n > 0 ); return all_ws; } - void get_date_format_err( ) { + //void get_date_format_err_double_fault( _In_ const SYSTEMTIME system_time, _In_ const HRESULT failed_fmt_res ) { + // displayWindowsMsgBoxWithMessage( L"GetDateFormatEx/get_date_format_err double faulted!!!" ); + // std::terminate( ); + // } + + void display_SYSTEMTIME_debugging_info( _In_ const SYSTEMTIME system_time ) { + std::wstring fmt_str( L"WDS: GetDateFormatEx failed, given this SYSTEMTIME:\r\n\t" ); + fmt_str += L"year: "; + fmt_str += std::to_wstring( static_cast< unsigned int >( system_time.wYear ) ); + fmt_str += L"\r\n\t"; + fmt_str += L"month: "; + fmt_str += std::to_wstring( static_cast< unsigned int >( system_time.wMonth ) ); + fmt_str += L"\r\n\t"; + fmt_str += L"day of week: "; + fmt_str += std::to_wstring( static_cast< unsigned int >( system_time.wDayOfWeek ) ); + fmt_str += L"\r\n\t"; + fmt_str += L"day: "; + fmt_str += std::to_wstring( static_cast< unsigned int >( system_time.wDay ) ); + fmt_str += L"\r\n\t"; + fmt_str += L"hour: "; + fmt_str += std::to_wstring( static_cast< unsigned int >( system_time.wHour ) ); + fmt_str += L"\r\n\t"; + fmt_str += L"minute: "; + fmt_str += std::to_wstring( static_cast< unsigned int >( system_time.wMinute ) ); + fmt_str += L"\r\n\t"; + fmt_str += L"second: "; + fmt_str += std::to_wstring( static_cast< unsigned int >( system_time.wSecond ) ); + fmt_str += L"\r\n\t"; + fmt_str += L"millisecond: "; + fmt_str += std::to_wstring( static_cast< unsigned int >( system_time.wMilliseconds ) ); + fmt_str += L"\r\n"; + const std::wstring& fmt_str_finished = fmt_str; + OutputDebugStringW( fmt_str_finished.c_str( ) ); + displayWindowsMsgBoxWithMessage( fmt_str_finished ); + } + + _Must_inspect_result_ + const bool display_GetDateFormatEx_flags( _In_ const DWORD flags ) { + if ( ( flags bitand DATE_LONGDATE ) ) { + displayWindowsMsgBoxWithMessage( L"GetDateFormatEx passed DATE_LONGDATE" ); + return true; + } + if ( ( flags bitand DATE_LTRREADING ) ) { + displayWindowsMsgBoxWithMessage( L"GetDateFormatEx passed DATE_LTRREADING" ); + return true; + } + if ( ( flags bitand DATE_RTLREADING ) ) { + displayWindowsMsgBoxWithMessage( L"GetDateFormatEx passed DATE_RTLREADING" ); + return true; + } + if ( ( flags bitand DATE_SHORTDATE ) ) { + displayWindowsMsgBoxWithMessage( L"GetDateFormatEx passed DATE_SHORTDATE" ); + return true; + } + if ( ( flags bitand DATE_USE_ALT_CALENDAR ) ) { + displayWindowsMsgBoxWithMessage( L"GetDateFormatEx passed DATE_USE_ALT_CALENDAR" ); + return true; + } + if ( ( flags bitand DATE_YEARMONTH ) ) { + displayWindowsMsgBoxWithMessage( L"GetDateFormatEx passed DATE_YEARMONTH" ); + return true; + } + return false; + } + + _Must_inspect_result_ + const bool display_GetTimeFormatEx_flags( _In_ const DWORD flags ) { + if ( ( flags bitand TIME_NOMINUTESORSECONDS ) ) { + displayWindowsMsgBoxWithMessage( L"GetTimeFormatEx passed TIME_NOMINUTESORSECONDS" ); + return true; + } + if ( ( flags bitand TIME_NOSECONDS ) ) { + displayWindowsMsgBoxWithMessage( L"GetTimeFormatEx passed TIME_NOSECONDS" ); + return true; + } + if ( ( flags bitand TIME_NOTIMEMARKER ) ) { + displayWindowsMsgBoxWithMessage( L"GetTimeFormatEx passed TIME_NOTIMEMARKER" ); + return true; + } + if ( ( flags bitand TIME_FORCE24HOURFORMAT ) ) { + displayWindowsMsgBoxWithMessage( L"GetTimeFormatEx passed TIME_FORCE24HOURFORMAT" ); + return true; + } + return false; + } + + //continue if returns true? + _Must_inspect_result_ _Success_( return == true ) //_In_range_ upper bound is totally arbitrary! Lower bound is enough for WRITE_BAD_FMT + const bool get_date_format_err( _In_ const SYSTEMTIME system_time, _In_ _In_range_( 24, 2048 ) const rsize_t str_size, _In_ const DWORD flags ) { const auto err = GetLastError( ); + + //sorry, this is ugly, isn't it? + display_SYSTEMTIME_debugging_info( system_time ); + if ( err == ERROR_INSUFFICIENT_BUFFER ) { TRACE( _T( "%s\r\n" ), global_strings::get_date_format_buffer_err ); displayWindowsMsgBoxWithMessage( global_strings::get_date_format_buffer_err ); - std::terminate( ); + const std::wstring buffer_size( L"size of (the insufficient) buffer: " + std::to_wstring( str_size ) ); + displayWindowsMsgBoxWithMessage( buffer_size ); + //std::terminate( ); + return true; } if ( err == ERROR_INVALID_FLAGS ) { TRACE( _T( "%s\r\n" ), global_strings::get_date_format_flags_err ); displayWindowsMsgBoxWithMessage( global_strings::get_date_format_flags_err ); - std::terminate( ); + return display_GetDateFormatEx_flags( flags ); } if ( err == ERROR_INVALID_PARAMETER ) { TRACE( _T( "%s\r\n" ), global_strings::get_date_format_param_err ); displayWindowsMsgBoxWithMessage( global_strings::get_date_format_param_err ); - std::terminate( ); + return display_GetDateFormatEx_flags( flags ); + //std::terminate( ); } + ASSERT( ( err == ERROR_INSUFFICIENT_BUFFER ) || ( err == ERROR_INVALID_FLAGS ) || ( err == ERROR_INVALID_PARAMETER ) ); + displayWindowsMsgBoxWithMessage( L"GetDateFormat failed, and GetLastError returned an unexpected error code!" ); + std::terminate( ); + return false; } - void get_time_format_err( ) { + //continue if returns true? + _Must_inspect_result_ _Success_( return == true ) + const bool get_time_format_err( _In_ const rsize_t str_size, _In_ const DWORD flags ) { const auto err = GetLastError( ); if ( err == ERROR_INSUFFICIENT_BUFFER ) { TRACE( _T( "%s\r\n" ), global_strings::get_time_format_buffer_err ); displayWindowsMsgBoxWithMessage( global_strings::get_time_format_buffer_err ); - std::terminate( ); + const std::wstring buffer_size( L"size of (the insufficient) buffer: " + std::to_wstring( str_size ) ); + displayWindowsMsgBoxWithMessage( buffer_size ); + return true; } if ( err == ERROR_INVALID_FLAGS ) { TRACE( _T( "%s\r\n" ), global_strings::get_time_format_flags_err ); displayWindowsMsgBoxWithMessage( global_strings::get_time_format_flags_err ); - std::terminate( ); + return display_GetTimeFormatEx_flags( flags ); + + //std::terminate( ); } if ( err == ERROR_INVALID_PARAMETER ) { TRACE( _T( "%s\r\n" ), global_strings::get_time_format_param_err ); displayWindowsMsgBoxWithMessage( global_strings::get_time_format_param_err ); + return true; + } + + if ( err == ERROR_OUTOFMEMORY ) { + TRACE( _T( "%s\r\n" ), global_strings::get_time_format_err_OUTOFMEMORY ); + displayWindowsMsgBoxWithMessage( global_strings::get_time_format_err_OUTOFMEMORY ); std::terminate( ); + return false; } + + ASSERT( ( err == ERROR_INSUFFICIENT_BUFFER ) || ( err == ERROR_INVALID_FLAGS ) || ( err == ERROR_INVALID_PARAMETER ) || ( err == ERROR_OUTOFMEMORY ) ); + displayWindowsMsgBoxWithMessage( L"FileTimeToSystemTime failed, and GetLastError returned an unexpected error code!" ); + std::terminate( ); + return false; } _Success_( SUCCEEDED( return ) ) HRESULT file_time_to_system_time_err( _Out_writes_z_( strSize ) _Pre_writable_size_( strSize ) PWSTR psz_formatted_datetime, _In_range_( 128, 2048 ) const rsize_t strSize, _Out_ rsize_t& chars_written ) { @@ -112,7 +229,8 @@ namespace { return E_FAIL; } - void ensure_valid_return_date( const int gdfres, const rsize_t strSize ) { + //_In_range_ upper bound is totally arbitrary! Lower bound is enough for WRITE_BAD_FMT + void ensure_valid_return_date( _In_ const int gdfres, _In_ _In_ _In_range_( 24, 2048 ) const rsize_t strSize, _In_ const SYSTEMTIME system_time, _Inout_ PWSTR psz_formatted_datetime ) { if ( !( ( gdfres + 1 ) < static_cast< std::int64_t >( strSize ) ) ) { displayWindowsMsgBoxWithMessage( L"Error in ensure_valid_return_date!(aborting)" ); std::wstring err_str( L"DEBUGGING INFO: strSize: " ); @@ -124,11 +242,18 @@ namespace { std::terminate( ); } if ( gdfres == 0 ) { - get_date_format_err( ); + const bool we_continue = get_date_format_err( system_time, strSize, GetDateFormatEx_flags ); + if ( we_continue ) { + rsize_t dummy_var = 0; + wds_fmt::write_BAD_FMT( psz_formatted_datetime, dummy_var ); + return; + } + std::terminate( ); } + std::terminate( ); } - void ensure_valid_return_time( const int gtfres, const rsize_t strSize ) { + void ensure_valid_return_time( const int gtfres, const rsize_t strSize, _Inout_ PWSTR psz_formatted_datetime ) { if ( !( ( gtfres + 1 ) < static_cast< std::int64_t >( strSize ) ) ) { displayWindowsMsgBoxWithMessage( L"Error in ensure_valid_return_time!(aborting)" ); std::wstring err_str( L"DEBUGGING INFO: strSize: " ); @@ -140,8 +265,15 @@ namespace { std::terminate( ); } if ( gtfres == 0 ) { - get_time_format_err( ); + const bool we_continue = get_time_format_err( strSize, GetTimeFormatEx_flags ); + if ( we_continue ) { + rsize_t dummy_var = 0; + wds_fmt::write_BAD_FMT( psz_formatted_datetime, dummy_var ); + return; + } + std::terminate( ); } + std::terminate( ); } _Success_( SUCCEEDED( return ) ) inline HRESULT CStyle_FormatLongLongHuman_0( WDS_WRITES_TO_STACK( strSize, chars_written ) PWSTR psz_formatted_LONGLONG_HUMAN, _In_range_( 8, 64 ) const rsize_t strSize, _Out_ rsize_t& chars_written ) { @@ -170,117 +302,161 @@ namespace { _Success_( SUCCEEDED( return ) ) _Pre_satisfies_( chars_written == 0 ) HRESULT CStyle_FormatLongLongHuman_KB( WDS_WRITES_TO_STACK( strSize, chars_written ) PWSTR psz_formatted_LONGLONG_HUMAN, _In_range_( 23, 64 ) const rsize_t strSize, _Out_ rsize_t& chars_written, _In_ const DOUBLE B, _In_ const DOUBLE KB ) { - const rsize_t bufSize = 19; - _Null_terminated_ wchar_t buffer[ bufSize ] = { 0 }; + const rsize_t number_formatted_buffer_size = 19; + _Null_terminated_ wchar_t buffer[ number_formatted_buffer_size ] = { 0 }; rsize_t buffer_chars_written = 0; - const HRESULT res = wds_fmt::CStyle_FormatDouble( KB + B / BASE, buffer, bufSize, buffer_chars_written ); - if ( SUCCEEDED( res ) ) { - ASSERT( wcslen( buffer ) == buffer_chars_written ); - rsize_t chars_remaining = 0; - const HRESULT fmt_res = StringCchPrintfExW( psz_formatted_LONGLONG_HUMAN, strSize, NULL, &chars_remaining, 0, L"%s KB", buffer ); - if ( SUCCEEDED( fmt_res ) ) { - chars_written = ( strSize - chars_remaining ); - return fmt_res; - } - else if ( fmt_res == STRSAFE_E_INSUFFICIENT_BUFFER ) { - chars_written = strSize; - ASSERT( chars_written == strSize ); - return STRSAFE_E_INSUFFICIENT_BUFFER; - } - else if ( ( fmt_res != STRSAFE_E_INSUFFICIENT_BUFFER ) && ( FAILED( fmt_res ) ) ) { - chars_written = 0; - wds_fmt::write_BAD_FMT( psz_formatted_LONGLONG_HUMAN, chars_written ); - } + const HRESULT res = wds_fmt::CStyle_FormatDouble( KB + B / BASE, buffer, number_formatted_buffer_size, buffer_chars_written ); + if ( !SUCCEEDED( res ) ) { + wds_fmt::write_BAD_FMT( psz_formatted_LONGLONG_HUMAN, chars_written ); + return res; + } + ASSERT( SUCCEEDED( res ) ); + ASSERT( wcslen( buffer ) == buffer_chars_written ); + rsize_t chars_remaining = 0; + const HRESULT fmt_res = StringCchPrintfExW( psz_formatted_LONGLONG_HUMAN, strSize, NULL, &chars_remaining, 0, L"%s KB", buffer ); + if ( SUCCEEDED( fmt_res ) ) { + chars_written = ( strSize - chars_remaining ); return fmt_res; } - wds_fmt::write_BAD_FMT( psz_formatted_LONGLONG_HUMAN, chars_written ); - return res; + else if ( fmt_res == STRSAFE_E_INSUFFICIENT_BUFFER ) { + chars_written = strSize; + ASSERT( chars_written == strSize ); + return STRSAFE_E_INSUFFICIENT_BUFFER; + } + else if ( ( fmt_res != STRSAFE_E_INSUFFICIENT_BUFFER ) && ( FAILED( fmt_res ) ) ) { + chars_written = 0; + wds_fmt::write_BAD_FMT( psz_formatted_LONGLONG_HUMAN, chars_written ); + return fmt_res; + } + return fmt_res; } _Success_( SUCCEEDED( return ) ) HRESULT CStyle_FormatLongLongHuman_MB( WDS_WRITES_TO_STACK( strSize, chars_written ) PWSTR psz_formatted_LONGLONG_HUMAN, _In_range_( 23, 64 ) const rsize_t strSize, _Out_ rsize_t& chars_written, _In_ const DOUBLE KB, _In_ const DOUBLE MB ) { - const rsize_t bufSize = 19; - _Null_terminated_ wchar_t buffer[ bufSize ] = { 0 }; + const rsize_t number_formatted_buffer_size = 19; + _Null_terminated_ wchar_t buffer[ number_formatted_buffer_size ] = { 0 }; rsize_t buffer_chars_written = 0; - const HRESULT res = wds_fmt::CStyle_FormatDouble( MB + KB / BASE, buffer, bufSize, buffer_chars_written ); - if ( SUCCEEDED( res ) ) { - ASSERT( wcslen( buffer ) == buffer_chars_written ); - rsize_t chars_remaining = 0; - const HRESULT fmt_res = StringCchPrintfExW( psz_formatted_LONGLONG_HUMAN, strSize, NULL, &chars_remaining, 0, L"%s MB", buffer ); - if ( SUCCEEDED( fmt_res ) ) { - chars_written = ( strSize - chars_remaining ); - return fmt_res; - } - else if ( fmt_res == STRSAFE_E_INSUFFICIENT_BUFFER ) { - chars_written = strSize; - ASSERT( chars_written == strSize ); - return STRSAFE_E_INSUFFICIENT_BUFFER; - } - else if ( ( fmt_res != STRSAFE_E_INSUFFICIENT_BUFFER ) && ( FAILED( fmt_res ) ) ) { - chars_written = 0; - wds_fmt::write_BAD_FMT( psz_formatted_LONGLONG_HUMAN, chars_written ); - } + const HRESULT res = wds_fmt::CStyle_FormatDouble( MB + KB / BASE, buffer, number_formatted_buffer_size, buffer_chars_written ); + if ( !SUCCEEDED( res ) ) { + wds_fmt::write_BAD_FMT( psz_formatted_LONGLONG_HUMAN, chars_written ); + return res; + } + ASSERT( SUCCEEDED( res ) ); + ASSERT( wcslen( buffer ) == buffer_chars_written ); + rsize_t chars_remaining = 0; + const HRESULT fmt_res = StringCchPrintfExW( psz_formatted_LONGLONG_HUMAN, strSize, NULL, &chars_remaining, 0, L"%s MB", buffer ); + if ( SUCCEEDED( fmt_res ) ) { + chars_written = ( strSize - chars_remaining ); return fmt_res; } - wds_fmt::write_BAD_FMT( psz_formatted_LONGLONG_HUMAN, chars_written ); - return res; + else if ( fmt_res == STRSAFE_E_INSUFFICIENT_BUFFER ) { + chars_written = strSize; + ASSERT( chars_written == strSize ); + return STRSAFE_E_INSUFFICIENT_BUFFER; + } + else if ( ( fmt_res != STRSAFE_E_INSUFFICIENT_BUFFER ) && ( FAILED( fmt_res ) ) ) { + chars_written = 0; + wds_fmt::write_BAD_FMT( psz_formatted_LONGLONG_HUMAN, chars_written ); + return fmt_res; + } + return fmt_res; } _Success_( SUCCEEDED( return ) ) HRESULT CStyle_FormatLongLongHuman_GB( WDS_WRITES_TO_STACK( strSize, chars_written ) PWSTR psz_formatted_LONGLONG_HUMAN, _In_range_( 8, 64 ) const rsize_t strSize, _Out_ rsize_t& chars_written, _In_ const DOUBLE MB, _In_ const DOUBLE GB ) { - const rsize_t bufSize = 19; - _Null_terminated_ wchar_t buffer[ bufSize ] = { 0 }; + const rsize_t number_formatted_buffer_size = 19; + _Null_terminated_ wchar_t buffer[ number_formatted_buffer_size ] = { 0 }; rsize_t buffer_chars_written = 0; - const HRESULT res = wds_fmt::CStyle_FormatDouble( GB + MB / BASE, buffer, bufSize, buffer_chars_written ); - if ( SUCCEEDED( res ) ) { - ASSERT( wcslen( buffer ) == buffer_chars_written ); - rsize_t chars_remaining = 0; - const HRESULT fmt_res = StringCchPrintfExW( psz_formatted_LONGLONG_HUMAN, strSize, NULL, &chars_remaining, 0, L"%s GB", buffer ); - if ( SUCCEEDED( fmt_res ) ) { - chars_written = ( strSize - chars_remaining ); - return fmt_res; - } - else if ( fmt_res == STRSAFE_E_INSUFFICIENT_BUFFER ) { - chars_written = strSize; - ASSERT( chars_written == strSize ); - return STRSAFE_E_INSUFFICIENT_BUFFER; - } - else if ( ( fmt_res != STRSAFE_E_INSUFFICIENT_BUFFER ) && ( FAILED( fmt_res ) ) ) { - chars_written = 0; - wds_fmt::write_BAD_FMT( psz_formatted_LONGLONG_HUMAN, chars_written ); - } + const HRESULT res = wds_fmt::CStyle_FormatDouble( GB + MB / BASE, buffer, number_formatted_buffer_size, buffer_chars_written ); + if ( !SUCCEEDED( res ) ) { + wds_fmt::write_BAD_FMT( psz_formatted_LONGLONG_HUMAN, chars_written ); + return res; + } + ASSERT( SUCCEEDED( res ) ); + ASSERT( wcslen( buffer ) == buffer_chars_written ); + rsize_t chars_remaining = 0; + const HRESULT fmt_res = StringCchPrintfExW( psz_formatted_LONGLONG_HUMAN, strSize, NULL, &chars_remaining, 0, L"%s GB", buffer ); + if ( SUCCEEDED( fmt_res ) ) { + chars_written = ( strSize - chars_remaining ); return fmt_res; } - wds_fmt::write_BAD_FMT( psz_formatted_LONGLONG_HUMAN, chars_written ); - return res; + else if ( fmt_res == STRSAFE_E_INSUFFICIENT_BUFFER ) { + chars_written = strSize; + ASSERT( chars_written == strSize ); + return STRSAFE_E_INSUFFICIENT_BUFFER; + } + else if ( ( fmt_res != STRSAFE_E_INSUFFICIENT_BUFFER ) && ( FAILED( fmt_res ) ) ) { + chars_written = 0; + wds_fmt::write_BAD_FMT( psz_formatted_LONGLONG_HUMAN, chars_written ); + return fmt_res; + } + return fmt_res; } _Success_( SUCCEEDED( return ) ) HRESULT CStyle_FormatLongLongHuman_TB( WDS_WRITES_TO_STACK( strSize, chars_written ) PWSTR psz_formatted_LONGLONG_HUMAN, _In_range_( 8, 64 ) const rsize_t strSize, _Out_ rsize_t& chars_written, _In_ const DOUBLE GB, _In_ const DOUBLE TB ) { - const rsize_t bufSize = 19; - _Null_terminated_ wchar_t buffer[ bufSize ] = { 0 }; + const rsize_t number_formatted_buffer_size = 19; + _Null_terminated_ wchar_t buffer[ number_formatted_buffer_size ] = { 0 }; rsize_t buffer_chars_written = 0; - const HRESULT res = wds_fmt::CStyle_FormatDouble( TB + GB / BASE, buffer, bufSize, buffer_chars_written ); - if ( SUCCEEDED( res ) ) { - ASSERT( wcslen( buffer ) == buffer_chars_written ); - rsize_t chars_remaining = 0; - const HRESULT fmt_res = StringCchPrintfExW( psz_formatted_LONGLONG_HUMAN, strSize, NULL, &chars_remaining, 0, L"%s TB", buffer ); - if ( SUCCEEDED( fmt_res ) ) { - chars_written = ( strSize - chars_remaining ); - return fmt_res; - } - else if ( fmt_res == STRSAFE_E_INSUFFICIENT_BUFFER ) { - chars_written = strSize; - ASSERT( chars_written == strSize ); - return STRSAFE_E_INSUFFICIENT_BUFFER; - } - else if ( ( fmt_res != STRSAFE_E_INSUFFICIENT_BUFFER ) && ( FAILED( fmt_res ) ) ) { - chars_written = 0; - wds_fmt::write_BAD_FMT( psz_formatted_LONGLONG_HUMAN, chars_written ); - } + const HRESULT res = wds_fmt::CStyle_FormatDouble( TB + GB / BASE, buffer, number_formatted_buffer_size, buffer_chars_written ); + if ( !SUCCEEDED( res ) ) { + wds_fmt::write_BAD_FMT( psz_formatted_LONGLONG_HUMAN, chars_written ); + return res; + } + ASSERT( SUCCEEDED( res ) ); + ASSERT( wcslen( buffer ) == buffer_chars_written ); + rsize_t chars_remaining = 0; + const HRESULT fmt_res = StringCchPrintfExW( psz_formatted_LONGLONG_HUMAN, strSize, NULL, &chars_remaining, 0, L"%s TB", buffer ); + if ( SUCCEEDED( fmt_res ) ) { + chars_written = ( strSize - chars_remaining ); return fmt_res; } - wds_fmt::write_BAD_FMT( psz_formatted_LONGLONG_HUMAN, chars_written ); - return res; + else if ( fmt_res == STRSAFE_E_INSUFFICIENT_BUFFER ) { + chars_written = strSize; + ASSERT( chars_written == strSize ); + return STRSAFE_E_INSUFFICIENT_BUFFER; + } + else if ( ( fmt_res != STRSAFE_E_INSUFFICIENT_BUFFER ) && ( FAILED( fmt_res ) ) ) { + chars_written = 0; + wds_fmt::write_BAD_FMT( psz_formatted_LONGLONG_HUMAN, chars_written ); + return fmt_res; + } + return fmt_res; + } + + void convert_number_to_string_failed_display_debugging_info( _In_range_( 19, 128 ) const rsize_t bufSize, _In_ const std::int64_t number ) { + const std::wstring err_str( L"DEBUGGING INFO: bufSize: " + std::to_wstring( bufSize ) + L", number: " + std::to_wstring( number ) ); + displayWindowsMsgBoxWithMessage( err_str.c_str( ) ); + std::terminate( ); + } + + void convert_number_to_string_failed( _In_range_( 19, 128 ) const rsize_t bufSize, _In_ const std::int64_t number, _In_ const HRESULT strsafe_printf_res ) { + if ( strsafe_printf_res == STRSAFE_E_INSUFFICIENT_BUFFER ) { + displayWindowsMsgBoxWithMessage( L"STRSAFE_E_INSUFFICIENT_BUFFER in CStyle_GetNumberFormatted!(aborting)" ); + return convert_number_to_string_failed_display_debugging_info( bufSize, number ); + } + if ( strsafe_printf_res == STRSAFE_E_END_OF_FILE ) { + displayWindowsMsgBoxWithMessage( L"STRSAFE_E_END_OF_FILE in CStyle_GetNumberFormatted!(aborting)" ); + return convert_number_to_string_failed_display_debugging_info( bufSize, number ); + } + if ( strsafe_printf_res == STRSAFE_E_INVALID_PARAMETER ) { + displayWindowsMsgBoxWithMessage( L"STRSAFE_E_INVALID_PARAMETER in CStyle_GetNumberFormatted!(aborting)" ); + return convert_number_to_string_failed_display_debugging_info( bufSize, number ); + } + displayWindowsMsgBoxWithMessage( L"Unknown error in CStyle_GetNumberFormatted!(aborting)" ); + return convert_number_to_string_failed_display_debugging_info( bufSize, number ); } + void convert_number_to_string( _In_range_( 19, 128 ) const rsize_t bufSize, _Pre_writable_size_( bufSize ) _Post_z_ PWSTR number_str_buffer, _In_ const std::int64_t number ) { + rsize_t chars_remaining = 0; + + const HRESULT strsafe_printf_res = StringCchPrintfExW( number_str_buffer, bufSize, NULL, &chars_remaining, 0, L"%I64d", number ); + if ( SUCCEEDED( strsafe_printf_res ) ) { + return; + } + ASSERT( !SUCCEEDED( strsafe_printf_res ) ); + + convert_number_to_string_failed( bufSize, number, strsafe_printf_res ); + } + + } @@ -339,17 +515,18 @@ void normalize_RECT( _Inout_ RECT& rect ) { } } -_Success_( SUCCEEDED( return ) ) HRESULT wds_fmt::FormatBytes( _In_ const std::uint64_t n, WDS_WRITES_TO_STACK( strSize, chars_written ) PWSTR psz_formatted_bytes, _In_range_( 38, 64 ) const rsize_t strSize, _Out_ rsize_t& chars_written ) { - auto res = wds_fmt::CStyle_FormatLongLongHuman( n, psz_formatted_bytes, strSize, chars_written ); +_Success_( SUCCEEDED( return ) ) HRESULT wds_fmt::FormatBytes( _In_ const std::uint64_t n, WDS_WRITES_TO_STACK( strSize, chars_written ) PWSTR psz_formatted_bytes, _In_range_( 38, 64 ) const rsize_t strSize, _Out_ rsize_t& chars_written, _On_failure_( _Post_valid_ ) rsize_t& size_needed ) { + const auto res = wds_fmt::CStyle_FormatLongLongHuman( n, psz_formatted_bytes, strSize, chars_written ); if ( !SUCCEEDED( res ) ) { wds_fmt::write_BAD_FMT( psz_formatted_bytes, chars_written ); + size_needed = ( strSize * 2 ); return res; } return res; } -_Success_( SUCCEEDED( return ) ) HRESULT wds_fmt::CStyle_FormatLongLongHuman( _In_ std::uint64_t n, WDS_WRITES_TO_STACK( strSize, chars_written ) PWSTR psz_formatted_LONGLONG_HUMAN, _In_range_( 8, 64 ) const rsize_t strSize, _Out_ rsize_t& chars_written ) { +_Success_( SUCCEEDED( return ) ) HRESULT wds_fmt::CStyle_FormatLongLongHuman( _In_ std::uint64_t n, WDS_WRITES_TO_STACK( strSize, chars_written ) PWSTR psz_formatted_LONGLONG_HUMAN, _In_range_( 19, 64 ) const rsize_t strSize, _Out_ rsize_t& chars_written ) { //MAX value of a LONGLONG is 19 digits const DOUBLE B = static_cast( n % BASE ); n /= BASE; @@ -402,10 +579,17 @@ _Success_( SUCCEEDED( return ) ) HRESULT wds_fmt::CStyle_FormatFileTime( _In_ co if ( !FileTimeToSystemTime( &t, &st ) ) { return file_time_to_system_time_err( psz_formatted_datetime, strSize, chars_written ); } - LCID lcid = MAKELCID( GetUserDefaultLangID( ), SORT_DEFAULT ); + + //const LCID lcid = MAKELCID( GetUserDefaultLangID( ), SORT_DEFAULT ); + + //const int gdfres = GetDateFormatW( lcid, DATE_SHORTDATE, &st, NULL, psz_formatted_datetime, static_cast( strSize ) ); + + //GRR DATE_AUTOLAYOUT doesn't work, because we're not targeting a Windows 7 minimum!! + //const int gdfres = GetDateFormatEx( LOCALE_NAME_INVARIANT, DATE_SHORTDATE bitor DATE_AUTOLAYOUT, ) - const int gdfres = GetDateFormatW( lcid, DATE_SHORTDATE, &st, NULL, psz_formatted_datetime, static_cast( strSize ) ); - ensure_valid_return_date( gdfres, strSize ); + const int gdfres = GetDateFormatEx( date_time_format_locale_name_str, GetDateFormatEx_flags, &st, NULL, psz_formatted_datetime, static_cast< int >( strSize ), NULL ); + + ensure_valid_return_date( gdfres, strSize, st, psz_formatted_datetime ); chars_written = static_cast( gdfres ); //if we have room for two spaces and a null: @@ -419,8 +603,10 @@ _Success_( SUCCEEDED( return ) ) HRESULT wds_fmt::CStyle_FormatFileTime( _In_ co return STRSAFE_E_INSUFFICIENT_BUFFER; } - const int gtfres = GetTimeFormatW( lcid, 0, &st, NULL, ( psz_formatted_datetime + chars_written ), static_cast( strSize - chars_written ) ); - ensure_valid_return_time( gtfres, strSize ); + //const int gtfres = GetTimeFormatW( lcid, 0, &st, NULL, ( psz_formatted_datetime + chars_written ), static_cast( static_cast( strSize ) - static_cast( chars_written ) ) ); + const int gtfres = GetTimeFormatEx( date_time_format_locale_name_str, GetTimeFormatEx_flags, &st, NULL, ( psz_formatted_datetime + chars_written ), static_cast( static_cast( strSize ) - static_cast( chars_written ) ) ); + + ensure_valid_return_time( gtfres, strSize, psz_formatted_datetime ); chars_written += gtfres; chars_written -= 1; @@ -432,29 +618,9 @@ _Success_( SUCCEEDED( return ) ) HRESULT wds_fmt::CStyle_FormatFileTime( _In_ co ERROR_INVALID_PARAMETER. Any of the parameter values was invalid. */ -#ifdef DEBUG - - const rsize_t psz_size = 36; - _Null_terminated_ wchar_t psz_date_wchar[ psz_size ] = { 0 }; - const auto gdfres_dbg = GetDateFormatW( lcid, DATE_SHORTDATE, &st, NULL, psz_date_wchar, psz_size ); - ensure_valid_return_date( gdfres_dbg, psz_size ); - - _Null_terminated_ wchar_t psz_time_wchar[ psz_size ] = { 0 }; - const auto gtfres_dbg = GetTimeFormatW( lcid, 0, &st, NULL, psz_time_wchar, psz_size ); - ensure_valid_return_time( gtfres_dbg, psz_size ); - - - _Null_terminated_ wchar_t psz_datetime_wchar[ psz_size ] = { 0 }; - rsize_t remaining_chars = 0; - const HRESULT fmt_res = StringCchPrintfExW( psz_datetime_wchar, psz_size, NULL, &remaining_chars, 0, L"%s %s", psz_date_wchar, psz_time_wchar ); - ASSERT( SUCCEEDED( fmt_res ) ); - ASSERT( wcscmp( psz_datetime_wchar, psz_formatted_datetime ) == 0 ); - return S_OK; -#else return S_OK; -#endif - //return fmt_res; } + _Success_( SUCCEEDED( return ) ) HRESULT wds_fmt::CStyle_FormatAttributes( _In_ const attribs& attr, _Out_writes_z_( strSize ) _Pre_writable_size_( strSize ) PWSTR psz_formatted_attributes, _In_range_( 6, 18 ) const rsize_t strSize, _Out_ rsize_t& chars_written ) { if ( attr.invalid ) { psz_formatted_attributes[ 0 ] = L'?'; @@ -497,76 +663,42 @@ _Success_( SUCCEEDED( return ) ) HRESULT wds_fmt::CStyle_GetNumberFormatted( con // Pass THAT string to GetNumberFormatEx const rsize_t bufSize = 66; - _Null_terminated_ wchar_t number_str_buffer[ bufSize ] = { 0 }; - //const auto sw_printf_s_res = swprintf_s( number_str_buffer, L"%I64d", number ); - rsize_t chars_remaining = 0; - - const HRESULT strsafe_printf_res = StringCchPrintfExW( number_str_buffer, bufSize, NULL, &chars_remaining, 0, L"%I64d", number ); - if ( !SUCCEEDED( strsafe_printf_res ) ) { - - if ( strsafe_printf_res == STRSAFE_E_INSUFFICIENT_BUFFER ) { - displayWindowsMsgBoxWithMessage( L"STRSAFE_E_INSUFFICIENT_BUFFER in CStyle_GetNumberFormatted!(aborting)" ); - } - if ( strsafe_printf_res == STRSAFE_E_END_OF_FILE ) { - displayWindowsMsgBoxWithMessage( L"STRSAFE_E_END_OF_FILE in CStyle_GetNumberFormatted!(aborting)" ); - } - if ( strsafe_printf_res == STRSAFE_E_INVALID_PARAMETER ) { - displayWindowsMsgBoxWithMessage( L"STRSAFE_E_INVALID_PARAMETER in CStyle_GetNumberFormatted!(aborting)" ); - } - else { - displayWindowsMsgBoxWithMessage( L"Unknown error in CStyle_GetNumberFormatted!(aborting)" ); - } - - - std::wstring err_str( L"DEBUGGING INFO: bufSize: " ); - err_str += std::to_wstring( bufSize ); - err_str += L", number: "; - err_str += std::to_wstring( number ); - displayWindowsMsgBoxWithMessage( err_str.c_str( ) ); - - - std::terminate( ); - } - - - NUMBERFMT format_struct; - format_struct.NumDigits = 0; - format_struct.LeadingZero = 0; - format_struct.Grouping = 3; - format_struct.lpDecimalSep = L"."; - format_struct.lpThousandSep = L","; - format_struct.NegativeOrder = 1; - + + convert_number_to_string( bufSize, number_str_buffer, number ); + NUMBERFMT format_struct = { 0, 0, 3, L".", L",", 1 }; //0 indicates failure! http://msdn.microsoft.com/en-us/library/windows/desktop/dd318113.aspx const auto get_number_fmt_ex_res = GetNumberFormatEx( NULL, 0, number_str_buffer, &format_struct, psz_formatted_number, static_cast( strSize ) ); - if ( get_number_fmt_ex_res == 0 ) { - const auto last_err = GetLastError( ); - ASSERT( ( last_err == ERROR_INSUFFICIENT_BUFFER ) || ( last_err == ERROR_INVALID_FLAGS ) || ( last_err == ERROR_INVALID_PARAMETER ) || ( last_err == ERROR_OUTOFMEMORY ) ); - switch ( last_err ) - { - case ERROR_INSUFFICIENT_BUFFER: - return STRSAFE_E_INSUFFICIENT_BUFFER; - case ERROR_INVALID_FLAGS: - case ERROR_INVALID_PARAMETER: - return STRSAFE_E_INVALID_PARAMETER; - case ERROR_OUTOFMEMORY: - return STRSAFE_E_END_OF_FILE; - default: - ASSERT( false ); - displayWindowsMsgBoxWithMessage( L"Unexpected error in CStyle_GetNumberFormatted, after GetNumberFormatEx!(aborting)" ); - displayWindowsMsgBoxWithError( last_err ); - std::terminate( ); - } - ASSERT( false ); - displayWindowsMsgBoxWithMessage( L"Unintended execution in CStyle_GetNumberFormatted, after GetNumberFormatEx!(aborting!)" ); - std::terminate( ); + if ( get_number_fmt_ex_res != 0 ) { + ASSERT( get_number_fmt_ex_res > 0 ); + chars_written = static_cast( get_number_fmt_ex_res - 1u ); + ASSERT( chars_written == wcslen( psz_formatted_number ) ); + return S_OK; } - ASSERT( get_number_fmt_ex_res > 0 ); - chars_written = static_cast( get_number_fmt_ex_res - 1u ); - ASSERT( chars_written == wcslen( psz_formatted_number ) ); - return S_OK; + ASSERT( get_number_fmt_ex_res == 0 ); + const DWORD last_err = GetLastError( ); + ASSERT( ( last_err == ERROR_INSUFFICIENT_BUFFER ) || ( last_err == ERROR_INVALID_FLAGS ) || ( last_err == ERROR_INVALID_PARAMETER ) || ( last_err == ERROR_OUTOFMEMORY ) ); + switch ( last_err ) + { + case ERROR_INSUFFICIENT_BUFFER: + return STRSAFE_E_INSUFFICIENT_BUFFER; + case ERROR_INVALID_FLAGS: + case ERROR_INVALID_PARAMETER: + return STRSAFE_E_INVALID_PARAMETER; + case ERROR_OUTOFMEMORY: + return STRSAFE_E_END_OF_FILE; + default: + ASSERT( false ); + displayWindowsMsgBoxWithMessage( L"Unexpected error in CStyle_GetNumberFormatted, after GetNumberFormatEx!(aborting)" ); + displayWindowsMsgBoxWithError( last_err ); + std::terminate( ); + } + ASSERT( false ); + displayWindowsMsgBoxWithMessage( L"Unintended execution in CStyle_GetNumberFormatted, after GetNumberFormatEx!(aborting!)" ); + std::terminate( ); + static_assert( !SUCCEEDED( E_FAIL ), "bad error return type!" ); + return E_FAIL; } _Success_( SUCCEEDED( return ) ) @@ -584,20 +716,11 @@ const HRESULT allocate_and_copy_name_str( _Pre_invalid_ _Post_z_ _Post_readable_ const auto da_ptrdiff = ( std::ptrdiff_t( pszend ) - std::ptrdiff_t( new_name_ptr ) ); ASSERT( ( da_ptrdiff / sizeof( wchar_t ) ) == new_name_length ); #endif + return res; } - else { - displayWindowsMsgBoxWithMessage( L"Copy of name_str failed!!!" ); - std::terminate( ); - } - ASSERT( SUCCEEDED( res ) ); + displayWindowsMsgBoxWithMessage( L"Copy of name_str failed!!!" ); + std::terminate( ); return res; - //const auto cpy_res = wcscpy_s( new_name_ptr, ( new_name_length + 1u ), name.c_str( ) ); - //if ( cpy_res != 0 ) { - //std::terminate( ); - //} - //ASSERT( wcslen( new_name_ptr ) == new_name_length ); - //ASSERT( wcscmp( new_name_ptr, name.c_str( ) ) == 0 ); - } @@ -643,6 +766,7 @@ void wds_fmt::FormatVolumeName( _In_ const std::wstring& rootPath, _In_z_ PCWSTR #pragma strict_gs_check(push, on) _Success_( SUCCEEDED( return ) ) HRESULT GetFullPathName_WriteToStackBuffer( _In_z_ PCWSTR relativePath, WDS_WRITES_TO_STACK( strSize, chars_written ) PWSTR psz_full_path, _In_range_( 128, 512 ) const DWORD strSize, _Out_ rsize_t& chars_written ) { + psz_full_path[ 0 ] = 0; const DWORD dw = GetFullPathNameW( relativePath, strSize, psz_full_path, NULL ); //ASSERT( dw >= 0 ); if ( dw == 0 ) { @@ -693,46 +817,49 @@ void MyGetDiskFreeSpace( _In_z_ const PCWSTR pszRootPath, _Out_ _Out_range_( 0, const BOOL b = GetDiskFreeSpaceExW( pszRootPath, &uavailable, &utotal, &ufree ); if ( !b ) { TRACE( _T( "\tGetDiskFreeSpaceEx(%s) failed.\r\n" ), pszRootPath ); + total = utotal.QuadPart; // will fail, when more than 2^63 Bytes free .... + unused = ufree.QuadPart; + ASSERT( unused <= total ); + return; } - else { - TRACE( _T( "stats:(%s) avail: %llu, total: %llu, free: %llu\r\n" ), pszRootPath, uavailable, utotal, ufree ); - ASSERT( uavailable.QuadPart <= utotal.QuadPart); - ASSERT( ufree.QuadPart <= utotal.QuadPart ); - ASSERT( uavailable.QuadPart != utotal.QuadPart ); - ASSERT( ufree.QuadPart != utotal.QuadPart ); - } + TRACE( _T( "stats:(%s) avail: %llu, total: %llu, free: %llu\r\n" ), pszRootPath, uavailable, utotal, ufree ); + ASSERT( uavailable.QuadPart <= utotal.QuadPart); + ASSERT( ufree.QuadPart <= utotal.QuadPart ); + ASSERT( uavailable.QuadPart != utotal.QuadPart ); + ASSERT( ufree.QuadPart != utotal.QuadPart ); total = utotal.QuadPart; // will fail, when more than 2^63 Bytes free .... unused = ufree.QuadPart; ASSERT( unused <= total ); + return; } -void MyGetDiskFreeSpace( _In_z_ const PCWSTR pszRootPath, _Inout_ LONGLONG& total, _Inout_ LONGLONG& unused, _Inout_ LONGLONG& available ) { - //ASSERT( pszRootPath != _T( "" ) ); - ULARGE_INTEGER uavailable = { { 0 } }; - ULARGE_INTEGER utotal = { { 0 } }; - ULARGE_INTEGER ufree = { { 0 } }; - uavailable.QuadPart = 0; - utotal.QuadPart = 0; - ufree.QuadPart = 0; - - // On NT 4.0, the 2nd Parameter to this function must NOT be NULL. - const BOOL b = GetDiskFreeSpaceExW( pszRootPath, &uavailable, &utotal, &ufree ); - if ( !b ) { - TRACE( _T( "\tGetDiskFreeSpaceEx(%s) failed.\r\n" ), pszRootPath ); - } - else { - TRACE( _T("\tGetDiskFreeSpaceEx(%s) successfully returned uavailable: %llu, utotal: %llu, ufree: %llu\r\n"), pszRootPath, uavailable, utotal, ufree); - ASSERT( uavailable.QuadPart <= utotal.QuadPart); - ASSERT( ufree.QuadPart <= utotal.QuadPart ); - ASSERT( uavailable.QuadPart != utotal.QuadPart ); - ASSERT( ufree.QuadPart != utotal.QuadPart ); - } - total = LONGLONG( utotal.QuadPart ); // will fail, when more than 2^63 Bytes free .... - unused = LONGLONG( ufree.QuadPart); - available = LONGLONG( uavailable.QuadPart ); - ASSERT( unused <= total ); - } +//void MyGetDiskFreeSpace( _In_z_ const PCWSTR pszRootPath, _Inout_ LONGLONG& total, _Inout_ LONGLONG& unused, _Inout_ LONGLONG& available ) { +// //ASSERT( pszRootPath != _T( "" ) ); +// ULARGE_INTEGER uavailable = { { 0 } }; +// ULARGE_INTEGER utotal = { { 0 } }; +// ULARGE_INTEGER ufree = { { 0 } }; +// uavailable.QuadPart = 0; +// utotal.QuadPart = 0; +// ufree.QuadPart = 0; +// +// // On NT 4.0, the 2nd Parameter to this function must NOT be NULL. +// const BOOL b = GetDiskFreeSpaceExW( pszRootPath, &uavailable, &utotal, &ufree ); +// if ( !b ) { +// TRACE( _T( "\tGetDiskFreeSpaceEx(%s) failed.\r\n" ), pszRootPath ); +// } +// else { +// TRACE( _T("\tGetDiskFreeSpaceEx(%s) successfully returned uavailable: %llu, utotal: %llu, ufree: %llu\r\n"), pszRootPath, uavailable, utotal, ufree); +// ASSERT( uavailable.QuadPart <= utotal.QuadPart); +// ASSERT( ufree.QuadPart <= utotal.QuadPart ); +// ASSERT( uavailable.QuadPart != utotal.QuadPart ); +// ASSERT( ufree.QuadPart != utotal.QuadPart ); +// } +// total = LONGLONG( utotal.QuadPart ); // will fail, when more than 2^63 Bytes free .... +// unused = LONGLONG( ufree.QuadPart); +// available = LONGLONG( uavailable.QuadPart ); +// ASSERT( unused <= total ); +// } bool DriveExists( _In_z_ _In_reads_( path_len ) const PCWSTR path, _In_ _In_range_( 0, 4 ) const rsize_t path_len ) { //const auto path_ws = std::wstring( path ); @@ -834,23 +961,21 @@ _Success_( return ) bool MyQueryDosDevice( _In_z_ const PCWSTR drive, _Out_ _Pos const auto dw = QueryDosDeviceW( left_two_chars_buffer, drive_info, 512u );//eek //info.ReleaseBuffer( ); - if ( dw == 0 ) { - const rsize_t error_buffer_size = 128; - _Null_terminated_ wchar_t error_buffer[ error_buffer_size ] = { 0 }; - rsize_t error_chars_written = 0; - const DWORD error_code = GetLastError( ); - const HRESULT fmt_res = CStyle_GetLastErrorAsFormattedMessage( error_buffer, error_buffer_size, error_chars_written, error_code ); - if ( SUCCEEDED( fmt_res ) ) { - TRACE( _T( "QueryDosDevice(%s) failed: %s\r\n" ), left_two_chars_buffer, error_buffer ); - } - else { - TRACE( _T( "QueryDosDevice(%s) failed. Couldn't get error message for code: %u\r\n" ), left_two_chars_buffer, error_code ); - } - - return false; + if ( dw != 0 ) { + return true; } - return true; + const rsize_t error_buffer_size = 128; + _Null_terminated_ wchar_t error_buffer[ error_buffer_size ] = { 0 }; + rsize_t error_chars_written = 0; + const DWORD error_code = GetLastError( ); + const HRESULT fmt_res = CStyle_GetLastErrorAsFormattedMessage( error_buffer, error_buffer_size, error_chars_written, error_code ); + if ( SUCCEEDED( fmt_res ) ) { + TRACE( _T( "QueryDosDevice(%s) failed: %s\r\n" ), left_two_chars_buffer, error_buffer ); + return false; + } + TRACE( _T( "QueryDosDevice(%s) failed. Couldn't get error message for code: %u\r\n" ), left_two_chars_buffer, error_code ); + return false; } @@ -1169,19 +1294,20 @@ INT Compare_FILETIME( const FILETIME& lhs, const FILETIME& rhs ) { } std::wstring wds_fmt::FormatBytes( _In_ const std::uint64_t n, bool humanFormat ) { - if ( humanFormat ) { - //MAX value of a std::uint64_t is 20 digits - const rsize_t strSize = 21; - _Null_terminated_ wchar_t psz_formatted_longlong[ strSize ] = { 0 }; - rsize_t chars_written = 0; - auto res = wds_fmt::CStyle_FormatLongLongHuman( n, psz_formatted_longlong, strSize, chars_written ); - if ( !SUCCEEDED( res ) ) { - wds_fmt::write_BAD_FMT( psz_formatted_longlong, chars_written ); - } + if ( !humanFormat ) { + return Format_uint64_t_Normal( n ); + } + ASSERT( humanFormat ); + //MAX value of a std::uint64_t is 20 digits + const rsize_t strSize = 21; + _Null_terminated_ wchar_t psz_formatted_longlong[ strSize ] = { 0 }; + rsize_t chars_written = 0; + auto res = wds_fmt::CStyle_FormatLongLongHuman( n, psz_formatted_longlong, strSize, chars_written ); + if ( SUCCEEDED( res ) ) { return psz_formatted_longlong; } - auto string = Format_uint64_t_Normal( n ); - return string; + wds_fmt::write_BAD_FMT( psz_formatted_longlong, chars_written ); + return psz_formatted_longlong; } diff --git a/WinDirStat/windirstat/globalhelpers.h b/WinDirStat/windirstat/globalhelpers.h index 1afbd54..ce327de 100644 --- a/WinDirStat/windirstat/globalhelpers.h +++ b/WinDirStat/windirstat/globalhelpers.h @@ -80,20 +80,13 @@ std::wstring dynamic_GetFullPathName( _In_z_ PCWSTR relativePath ); //WinDirStat string-formatting functions namespace wds_fmt { - void write_bad_fmt_msg( _Out_writes_z_( 41 ) _Pre_writable_size_( 42 ) _Post_readable_size_( chars_written ) PWSTR psz_fmt_msg, _Out_ rsize_t& chars_written ); - void FormatVolumeName( _In_ const std::wstring& rootPath, _In_z_ PCWSTR volumeName, _Out_ _Post_z_ _Pre_writable_size_( MAX_PATH + 1u ) PWSTR formatted_volume_name ); - - _Success_( SUCCEEDED( return ) ) HRESULT CStyle_FormatLongLongHuman ( _In_ std::uint64_t n, WDS_WRITES_TO_STACK( strSize, chars_written ) PWSTR psz_formatted_LONGLONG_HUMAN, _In_range_( 8, 64 ) const rsize_t strSize, _Out_ rsize_t& chars_written ); + _Success_( SUCCEEDED( return ) ) HRESULT CStyle_FormatLongLongHuman ( _In_ std::uint64_t n, WDS_WRITES_TO_STACK( strSize, chars_written ) PWSTR psz_formatted_LONGLONG_HUMAN, _In_range_( 19, 64 ) const rsize_t strSize, _Out_ rsize_t& chars_written ); //maximum representable integral component of a double SEEMS to be 15 characters long, so we need at least 17 _Success_( SUCCEEDED( return ) ) HRESULT CStyle_FormatDouble ( _In_ const DOUBLE d, WDS_WRITES_TO_STACK( strSize, chars_written ) PWSTR psz_formatted_double, _In_range_( 17, 64 ) const rsize_t strSize, _Out_ rsize_t& chars_written ); - - _Success_( SUCCEEDED( return ) ) HRESULT FormatBytes ( _In_ const std::uint64_t n, WDS_WRITES_TO_STACK( strSize, chars_written ) PWSTR psz_formatted_bytes, _In_range_( 38, 64 ) const rsize_t strSize, _Out_ rsize_t& chars_written ); - - std::wstring FormatBytes ( _In_ const std::uint64_t n, bool humanFormat ); - + _Success_( SUCCEEDED( return ) ) HRESULT FormatBytes ( _In_ const std::uint64_t n, WDS_WRITES_TO_STACK( strSize, chars_written ) PWSTR psz_formatted_bytes, _In_range_( 38, 64 ) const rsize_t strSize, _Out_ rsize_t& chars_written, _On_failure_( _Post_valid_ ) rsize_t& size_needed ); _Success_( SUCCEEDED( return ) ) HRESULT CStyle_FormatFileTime ( _In_ const FILETIME t, _Out_writes_z_( strSize ) _Pre_writable_size_( strSize ) PWSTR psz_formatted_datetime, _In_range_( 128, 2048 ) const rsize_t strSize, _Out_ rsize_t& chars_written ); @@ -101,11 +94,18 @@ namespace wds_fmt { _Success_( SUCCEEDED( return ) ) HRESULT CStyle_GetNumberFormatted( const std::int64_t number, _Pre_writable_size_( strSize ) PWSTR psz_formatted_number, _In_range_( 21, 64 ) const rsize_t strSize, _Out_ rsize_t& chars_written ); - void write_BAD_FMT ( _Out_writes_z_( 8 ) _Pre_writable_size_( 8 ) _Post_readable_size_( 8 ) PWSTR pszFMT, _Out_ rsize_t& chars_written ); + std::wstring FormatBytes( _In_ const std::uint64_t n, const bool humanFormat ); + - void write_MEM_INFO_ERR( _Out_writes_z_( 13 ) _Pre_writable_size_( 13 ) PWSTR psz_formatted_usage ); + void write_MEM_INFO_ERR ( _Out_writes_z_( 13 ) _Pre_writable_size_( 13 ) PWSTR psz_formatted_usage ); - void write_RAM_USAGE( _Out_writes_z_( 12 ) _Pre_writable_size_( 13 ) PWSTR psz_ram_usage ); + void write_RAM_USAGE ( _Out_writes_z_( 12 ) _Pre_writable_size_( 13 ) PWSTR psz_ram_usage ); + + void write_bad_fmt_msg ( _Out_writes_z_( 41 ) _Pre_writable_size_( 42 ) _Post_readable_size_( chars_written ) PWSTR psz_fmt_msg, _Out_ rsize_t& chars_written ); + + void write_BAD_FMT ( _Out_writes_z_( 8 ) _Pre_writable_size_( 8 ) _Post_readable_size_( 8 ) PWSTR pszFMT, _Out_ rsize_t& chars_written ); + + void FormatVolumeName ( _In_ const std::wstring& rootPath, _In_z_ PCWSTR volumeName, _Out_ _Post_z_ _Pre_writable_size_( MAX_PATH + 1u ) PWSTR formatted_volume_name ); } diff --git a/WinDirStat/windirstat/item.cpp b/WinDirStat/windirstat/item.cpp index ce75aa7..360d778 100644 --- a/WinDirStat/windirstat/item.cpp +++ b/WinDirStat/windirstat/item.cpp @@ -67,10 +67,10 @@ HRESULT CItemBranch::WriteToStackBuffer_COL_SUBTREETOTAL( RANGE_ENUM_COL const c UNREFERENCED_PARAMETER( subitem ); #endif ASSERT( subitem == column::COL_SUBTREETOTAL ); - const HRESULT res = wds_fmt::FormatBytes( size_recurse( ), psz_text, strSize, chars_written ); + const HRESULT res = wds_fmt::FormatBytes( size_recurse( ), psz_text, strSize, chars_written, sizeBuffNeed ); if ( res == STRSAFE_E_INSUFFICIENT_BUFFER ) { chars_written = strSize; - sizeBuffNeed = 64;//Generic size needed. + sizeBuffNeed = ( ( 64 > sizeBuffNeed ) ? 64 : sizeBuffNeed );//Generic size needed. return res; } else if ( ( res != STRSAFE_E_INSUFFICIENT_BUFFER ) && ( FAILED( res ) ) ) { @@ -136,7 +136,7 @@ HRESULT CItemBranch::WriteToStackBuffer_COL_ATTRIBUTES( RANGE_ENUM_COL const col } _Must_inspect_result_ _Success_( SUCCEEDED( return ) ) -HRESULT CItemBranch::Text_WriteToStackBuffer( RANGE_ENUM_COL const column::ENUM_COL subitem, WDS_WRITES_TO_STACK( strSize, chars_written ) PWSTR psz_text, _In_ const rsize_t strSize, _Out_ _On_failure_( _Post_valid_ ) rsize_t& sizeBuffNeed, _Out_ rsize_t& chars_written ) const { +HRESULT CItemBranch::Text_WriteToStackBuffer( RANGE_ENUM_COL const column::ENUM_COL subitem, WDS_WRITES_TO_STACK( strSize, chars_written ) PWSTR psz_text, _In_ const rsize_t strSize, _On_failure_( _Post_valid_ ) rsize_t& sizeBuffNeed, _Out_ rsize_t& chars_written ) const { switch ( subitem ) { diff --git a/WinDirStat/windirstat/item.h b/WinDirStat/windirstat/item.h index fc4c405..f0c0093 100644 --- a/WinDirStat/windirstat/item.h +++ b/WinDirStat/windirstat/item.h @@ -68,7 +68,7 @@ class CItemBranch final : public CTreeListItem { public: _Must_inspect_result_ _Success_( SUCCEEDED( return ) ) - virtual HRESULT Text_WriteToStackBuffer ( RANGE_ENUM_COL const column::ENUM_COL subitem, WDS_WRITES_TO_STACK( strSize, chars_written ) PWSTR psz_text, _In_ const rsize_t strSize, _Out_ _On_failure_( _Post_valid_) rsize_t& sizeBuffNeed, _Out_ rsize_t& chars_written ) const override final; + virtual HRESULT Text_WriteToStackBuffer ( RANGE_ENUM_COL const column::ENUM_COL subitem, WDS_WRITES_TO_STACK( strSize, chars_written ) PWSTR psz_text, _In_ const rsize_t strSize, _On_failure_( _Post_valid_) rsize_t& sizeBuffNeed, _Out_ rsize_t& chars_written ) const override final; _Pre_satisfies_( subitem == column::COL_PERCENTAGE ) _Success_( SUCCEEDED( return ) ) HRESULT WriteToStackBuffer_COL_PERCENTAGE( RANGE_ENUM_COL const column::ENUM_COL subitem, WDS_WRITES_TO_STACK( strSize, chars_written ) PWSTR psz_text, _In_ const rsize_t strSize, rsize_t& sizeBuffNeed, _Out_ rsize_t& chars_written ) const; diff --git a/WinDirStat/windirstat/mainframe.cpp b/WinDirStat/windirstat/mainframe.cpp index f9ed6e5..b42fdbb 100644 --- a/WinDirStat/windirstat/mainframe.cpp +++ b/WinDirStat/windirstat/mainframe.cpp @@ -296,7 +296,7 @@ INT CMainFrame::OnCreate( const LPCREATESTRUCT lpCreateStruct ) { } void CMainFrame::InitialShowWindow( ) { - WINDOWPLACEMENT wp; + auto wp = zero_init_struct( ); wp.length = sizeof( wp ); VERIFY( GetWindowPlacement( &wp ) ); CPersistence::GetMainWindowPlacement( wp ); diff --git a/WinDirStat/windirstat/options.cpp b/WinDirStat/windirstat/options.cpp index 3c770c2..634b952 100644 --- a/WinDirStat/windirstat/options.cpp +++ b/WinDirStat/windirstat/options.cpp @@ -150,8 +150,11 @@ namespace { void DecodeWindowPlacement( _In_ const std::wstring s, _Inout_ WINDOWPLACEMENT& rwp ) { TRACE( _T( "Decoding window placement! wp.flags, wp.showCmd, wp.ptMinPosition.x, wp.ptMinPosition.y, wp.ptMaxPosition.x, wp.ptMaxPosition.y, wp.rcNormalPosition.left, wp.rcNormalPosition.right, wp.rcNormalPosition.top, wp.rcNormalPosition.bottom: %s\r\n" ), s.c_str( ) ); - WINDOWPLACEMENT wp; + + auto wp = zero_init_struct( ); + wp.length = sizeof( wp ); + const INT r = swscanf_s( s.c_str( ), _T( "%u,%u," ) _T( "%ld,%ld,%ld,%ld," ) _T( "%ld,%ld,%ld,%ld" ), &wp.flags, &wp.showCmd, &wp.ptMinPosition.x, &wp.ptMinPosition.y, &wp.ptMaxPosition.x, &wp.ptMaxPosition.y, &wp.rcNormalPosition.left, &wp.rcNormalPosition.right, &wp.rcNormalPosition.top, &wp.rcNormalPosition.bottom ); TRACE( _T( "swscanf_s result: %i\r\n" ), r ); TRACE( _T( "WINDOWPLACEMENT:\r\n\twp.flags: %u,\r\n\twp.showCmd: %u,\r\n\twp.ptMinPosition.x: %ld,\r\n\twp.ptMinPosition.y: %ld,\r\n\twp.ptMaxPosition.x: %ld,\r\n\twp.ptMaxPosition.y: %ld,\r\n\twp.rcNormalPosition.left: %ld,\r\n\twp.rcNormalPosition.right: %ld,\r\n\twp.rcNormalPosition.top: %ld,\r\n\twp.rcNormalPosition.bottom: %ld\r\n" ), wp.flags, wp.showCmd, wp.ptMinPosition.x, wp.ptMinPosition.y, wp.ptMaxPosition.x, wp.ptMaxPosition.y, wp.rcNormalPosition.left, wp.rcNormalPosition.right, wp.rcNormalPosition.top, wp.rcNormalPosition.bottom ); @@ -254,8 +257,8 @@ void CPersistence::SetShowStatusbar( _In_ const bool show ) { CRegistryUser::SetProfileBool( sectionPersistence, entryShowStatusbar, show ); } -void CPersistence::GetMainWindowPlacement( _Inout_ WINDOWPLACEMENT& wp ) { - ASSERT( wp.length == sizeof( wp ) ); +void CPersistence::GetMainWindowPlacement( _Out_ WINDOWPLACEMENT& wp ) { + //ASSERT( wp.length == sizeof( wp ) ); //const DWORD prof_string_size = MAX_PATH; //wchar_t prof_string[ prof_string_size ] = { 0 }; @@ -286,21 +289,21 @@ void CPersistence::SetSplitterPos( _In_z_ const PCTSTR name, _In_ const bool val } void CPersistence::GetSplitterPos( _In_z_ const PCTSTR name, _Inout_ bool& valid, _Inout_ DOUBLE& userpos ) { - auto pos = CRegistryUser::GetProfileInt_( sectionPersistence, MakeSplitterPosEntry( name ).c_str( ), -1 ); + const auto pos = CRegistryUser::GetProfileInt_( sectionPersistence, MakeSplitterPosEntry( name ).c_str( ), -1 ); if ( pos > 100 ) { valid = false; userpos = 0.5; } else { valid = true; - userpos = ( DOUBLE ) pos / 100; + userpos = ( static_cast( pos ) / static_cast( 100 ) ); } } //void CPersistence::GetColumnOrder( _In_z_ const PCTSTR name, _Inout_ CArray& arr ) { // GetArray( MakeColumnOrderEntry( name ), arr ); // } -void CPersistence::GetDialogRectangle( _In_z_ const PCTSTR name, _Inout_ RECT& rc ) { +void CPersistence::GetDialogRectangle( _In_z_ const PCTSTR name, _Out_ RECT& rc ) { GetRect( MakeDialogRectangleEntry( name ).c_str( ), rc ); CRect temp( rc ); SanifyRect( temp ); @@ -316,7 +319,7 @@ void CPersistence::GetDialogRectangle( _In_z_ const PCTSTR name, _Inout_ RECT& r // } void CPersistence::SetColumnWidths( _In_z_ const PCTSTR name, _Inout_ _Pre_writable_size_( arrSize ) INT* arr, const rsize_t arrSize ) { - SetArray( MakeColumnWidthsEntry( name ).c_str( ), arr, arrSize ); + SetArray( MakeColumnWidthsEntry( name ), arr, arrSize ); } //void CPersistence::SetColumnOrder( _In_z_ const PCTSTR name, _In_ const CArray& arr ) { @@ -324,18 +327,18 @@ void CPersistence::SetColumnWidths( _In_z_ const PCTSTR name, _Inout_ _Pre_writa // } void CPersistence::SetColumnOrder( _In_z_ const PCTSTR name, _Inout_ _Pre_writable_size_( arrSize ) INT* arr, const rsize_t arrSize ) { - SetArray( MakeColumnOrderEntry( name ).c_str( ), arr, arrSize ); + SetArray( MakeColumnOrderEntry( name ), arr, arrSize ); } -void CPersistence::SetDialogRectangle( _In_z_ const PCTSTR name, _In_ const RECT& rc ) { +void CPersistence::SetDialogRectangle( _In_z_ const PCTSTR name, _In_ const RECT rc ) { SetRect( MakeDialogRectangleEntry( name ).c_str( ), rc ); } -void CPersistence::GetColumnOrder( _In_z_ const PCTSTR name, _Inout_ _Pre_writable_size_( arrSize ) INT* arr, const rsize_t arrSize ) { +void CPersistence::GetColumnOrder( _In_z_ const PCTSTR name, _Out_ _Pre_writable_size_( arrSize ) INT* arr, const rsize_t arrSize ) { GetArray( MakeColumnOrderEntry( name ), arr, arrSize ); } -void CPersistence::GetColumnWidths( _In_z_ const PCTSTR name, _Inout_ _Pre_writable_size_( arrSize ) INT* arr, const rsize_t arrSize ) { +void CPersistence::GetColumnWidths( _In_z_ const PCTSTR name, _Out_ _Pre_writable_size_( arrSize ) INT* arr, const rsize_t arrSize ) { GetArray( MakeColumnWidthsEntry( name ), arr, arrSize ); } @@ -419,6 +422,9 @@ void CPersistence::GetSelectDrivesDrives( _Inout_ std::vector& dri void CPersistence::SetSelectDrivesDrives( _In_ const std::vector& drives ) { std::wstring s; const auto sizeDrives = drives.size( ); + + //each drive is PROBABLY going to be more than one character in length, but we can reserve something anyways! + s.reserve( sizeDrives ); for ( size_t i = 0; i < sizeDrives; i++ ) { if ( i > 0 ) { s += _T( "|" ); @@ -437,32 +443,33 @@ void CPersistence::SetShowDeleteWarning( _In_ const bool show ) { } -void CPersistence::SetArray( _In_z_ const PCTSTR entry, _Inout_ _Pre_writable_size_( arrSize ) INT* arr, const rsize_t arrSize ) { - ASSERT( wcslen( entry ) != 0 ); +void CPersistence::SetArray( _In_z_ const std::wstring entry, _Inout_ _Pre_writable_size_( arrSize ) INT* arr, const rsize_t arrSize ) { + ASSERT( entry.length( ) != 0 ); //TODO: BUGBUG: do something here other than just returning - if ( wcslen( entry ) == 0 ) { + if ( entry.length( ) == 0 ) { return; } - + const rsize_t int_buf_size = 11u; + _Null_terminated_ wchar_t int_buf[ int_buf_size ] = { 0 }; std::wstring value; + + //reserve comma, plus arrSize * int_buf + value.reserve( ( arrSize ) + ( int_buf_size * arrSize ) ); for ( rsize_t i = 0; i < arrSize; i++ ) { - - const rsize_t int_buf_size = 11; - _Null_terminated_ wchar_t int_buf[ int_buf_size ] = { 0 }; + memset_zero_struct( int_buf ); const auto swp_res = swprintf_s( int_buf, int_buf_size, L"%d", arr[ i ] ); if ( swp_res == -1 ) { displayWindowsMsgBoxWithMessage( L"swprintf_s SERIOUS error!!" ); TRACE( _T( "swprintf_s SERIOUS error!!\r\n" ) ); std::terminate( ); } - //s.Format( _T( "%d" ), arr[ i ] ); if ( i > 0 ) { - value += L',' ; + value += L','; } value += int_buf; } - SetProfileString( sectionPersistence, entry, value.c_str( ) ); + SetProfileString( sectionPersistence, entry.c_str( ), value.c_str( ) ); } //void CPersistence::GetArray( _In_z_ const PCTSTR entry, _Inout_ CArray& rarr ) { @@ -489,9 +496,13 @@ void CPersistence::SetArray( _In_z_ const PCTSTR entry, _Inout_ _Pre_writable_si // } // } -void CPersistence::GetArray( _In_ const std::wstring entry, _Inout_ _Pre_writable_size_( arrSize ) INT* arr_, const rsize_t arrSize ) { + +_Pre_satisfies_( arrSize > 0 ) +void CPersistence::GetArray( _In_ const std::wstring entry, _Out_ _Pre_writable_size_( arrSize ) INT* arr_, const rsize_t arrSize ) { ASSERT( entry.length( ) != 0 ); - + for ( rsize_t i = 0; i < arrSize; ++i ) { + arr_[ i ] = 0; + } //TODO: BUGBUG: do something here other than just returning if ( entry.length( ) == 0 ) { return; @@ -499,30 +510,41 @@ void CPersistence::GetArray( _In_ const std::wstring entry, _Inout_ _Pre_writabl const auto s_temp = CRegistryUser::GetProfileString_( sectionPersistence, entry.c_str( ), _T( "" ) ); //const DWORD arr_buf_size = MAX_PATH; + rsize_t current_arr_index = 0; const std::wstring s( s_temp ); - std::vector arr; + //std::vector arr; rsize_t i = 0; - while ( i < s.length( ) ) { + + const auto string_length = s.length( ); + + while ( i < string_length ) { INT n = 0; - while ( i < s.length( ) && iswdigit( s[ i ] ) ) { + while ( i < string_length && iswdigit( s[ i ] ) ) { + ASSERT( s[ i ] != L',' ); n *= 10; n += s[ i ] - _T( '0' ); i++; } - arr.emplace_back( n ); - if ( i >= s.length( ) || s[ i ] != _T( ',' ) ) { + ASSERT( current_arr_index < arrSize ); + arr_[ current_arr_index ] = n; + ++current_arr_index; + //arr.emplace_back( n ); + + if ( i >= string_length || s[ i ] != _T( ',' ) ) { break; } i++; } - if ( i >= s.length( ) && arr.size( ) == arrSize ) { - for ( rsize_t j = 0; j < arrSize; ++j ) { - arr_[ j ] = arr[ j ]; - } - } + //if ( i >= s.length( ) && arr.size( ) == arrSize ) { + // for ( rsize_t j = 0; j < arrSize; ++j ) { + // ASSERT( j <= current_arr_index ); + // ASSERT( arr_[ j ] == arr[ j ] ); + // //arr_[ j ] = arr[ j ]; + // } + // } } void CPersistence::SetRect( _In_z_ const PCTSTR entry, _In_ const RECT rc ) { @@ -652,7 +674,7 @@ void COptions::SaveToRegistry( ) { CRegistryUser::SetProfileBool( sectionOptions, entryListFullRowSelection, m_listFullRowSelection ); CRegistryUser::SetProfileInt( sectionOptions, entryTreelistColorCount, static_cast( m_treelistColorCount ) ); - for ( INT i = 0; i < TREELISTCOLORCOUNT; i++ ) { + for ( INT i = 0; i < static_cast( TREELISTCOLORCOUNT ); i++ ) { //CString entry; //entry.Format( entryTreelistColorN, i ); std::wstring dyn_fmt_str( std::wstring( L"treelistColor" + std::to_wstring( i ) ) ); diff --git a/WinDirStat/windirstat/options.h b/WinDirStat/windirstat/options.h index 04718ee..b2051b1 100644 --- a/WinDirStat/windirstat/options.h +++ b/WinDirStat/windirstat/options.h @@ -34,7 +34,7 @@ class CPersistence { public: static void SetConfigPage ( _In_ const INT page ); static void SetConfigPosition ( _In_ const WTL::CPoint pt ); - static void SetDialogRectangle ( _In_z_ const PCTSTR name, _In_ const RECT& rc ); + static void SetDialogRectangle ( _In_z_ const PCTSTR name, _In_ const RECT rc ); static void SetMainWindowPlacement ( _In_ const WINDOWPLACEMENT& wp ); static void SetSelectDrivesDrives ( _In_ const std::vector& drives ); static void SetSelectDrivesFolder ( _In_z_ const PCTSTR folder ); @@ -46,9 +46,9 @@ class CPersistence { static void SetSplitterPos ( _In_z_ const PCTSTR name, _In_ const bool valid, _In_ const DOUBLE userpos ); static void GetConfigPosition ( _Inout_ WTL::CPoint& pt ); - static void GetDialogRectangle ( _In_z_ const PCTSTR name, _Inout_ RECT& rc ); + static void GetDialogRectangle ( _In_z_ const PCTSTR name, _Out_ RECT& rc ); static void GetSplitterPos ( _In_z_ const PCTSTR name, _Inout_ bool& valid, _Inout_ DOUBLE& userpos ); - static void GetMainWindowPlacement ( _Inout_ WINDOWPLACEMENT& wp ); + static void GetMainWindowPlacement ( _Out_ WINDOWPLACEMENT& wp ); static void GetSelectDrivesDrives ( _Inout_ std::vector& drives ); static INT GetConfigPage ( _In_ const INT max ); static bool GetShowDeleteWarning ( ); @@ -66,14 +66,18 @@ class CPersistence { static void SetColumnWidths ( _In_z_ const PCTSTR name, _Inout_ _Pre_writable_size_( arrSize ) INT* arr, const rsize_t arrSize ); static void SetColumnOrder ( _In_z_ const PCTSTR name, _Inout_ _Pre_writable_size_( arrSize ) INT* arr, const rsize_t arrSize ); - static void GetColumnOrder ( _In_z_ const PCTSTR name, _Inout_ _Pre_writable_size_( arrSize ) INT* arr, const rsize_t arrSize ); - static void GetColumnWidths ( _In_z_ const PCTSTR name, _Inout_ _Pre_writable_size_( arrSize ) INT* arr, const rsize_t arrSize ); + static void GetColumnOrder ( _In_z_ const PCTSTR name, _Out_ _Pre_writable_size_( arrSize ) INT* arr, const rsize_t arrSize ); + static void GetColumnWidths ( _In_z_ const PCTSTR name, _Out_ _Pre_writable_size_( arrSize ) INT* arr, const rsize_t arrSize ); private: - static void GetArray ( _In_ const std::wstring entry, _Inout_ _Pre_writable_size_( arrSize ) INT* arr_, const rsize_t arrSize ); + + _Pre_satisfies_( arrSize > 0 ) + static void GetArray ( _In_ const std::wstring entry, _Out_ _Pre_writable_size_( arrSize ) INT* arr_, const rsize_t arrSize ); + static void GetRect ( _In_z_ const PCTSTR entry, _Inout_ RECT& rc ); + static void SetRect ( _In_z_ const PCTSTR entry, _In_ const RECT rc ); - static void SetArray ( _In_z_ const PCTSTR name, _Inout_ _Pre_writable_size_( arrSize ) INT* arr, const rsize_t arrSize ); + static void SetArray ( _In_z_ const std::wstring name, _Inout_ _Pre_writable_size_( arrSize ) INT* arr, const rsize_t arrSize ); }; diff --git a/WinDirStat/windirstat/ownerdrawnlistcontrol.h b/WinDirStat/windirstat/ownerdrawnlistcontrol.h index 0ce2b05..a9e0649 100644 --- a/WinDirStat/windirstat/ownerdrawnlistcontrol.h +++ b/WinDirStat/windirstat/ownerdrawnlistcontrol.h @@ -45,7 +45,7 @@ class COwnerDrawnListItem { virtual INT Compare( _In_ const COwnerDrawnListItem* const other, RANGE_ENUM_COL const column::ENUM_COL subitem ) const = 0; _Must_inspect_result_ _Success_( SUCCEEDED( return ) ) - virtual HRESULT Text_WriteToStackBuffer( RANGE_ENUM_COL const column::ENUM_COL subitem, WDS_WRITES_TO_STACK( strSize, chars_written ) PWSTR psz_text, _In_ const rsize_t strSize, _Out_ _On_failure_( _Post_valid_ ) rsize_t& sizeBuffNeed, _Out_ rsize_t& chars_written ) const = 0; + virtual HRESULT Text_WriteToStackBuffer( RANGE_ENUM_COL const column::ENUM_COL subitem, WDS_WRITES_TO_STACK( strSize, chars_written ) PWSTR psz_text, _In_ const rsize_t strSize, _On_failure_( _Post_valid_ ) rsize_t& sizeBuffNeed, _Out_ rsize_t& chars_written ) const = 0; //CItemBranch is the only non-default behavior here! virtual COLORREF ItemTextColor( ) const = 0; @@ -54,7 +54,7 @@ class COwnerDrawnListItem { virtual bool DrawSubitem ( RANGE_ENUM_COL const column::ENUM_COL subitem, _In_ CDC& pdc, _In_ RECT rc, _In_ const UINT state, _Out_opt_ INT* const width, _Inout_ INT* const focusLeft, _In_ const COwnerDrawnListCtrl* const list ) const = 0; //defined at the BOTTOM of this file! - COLORREF draw_if_selected_return_text_color( _Out_opt_ INT* const width, _In_ const UINT state, _In_ const COwnerDrawnListCtrl* const list, const RECT rcLabel, const RECT rc, _In_ CDC& pdc ) const; + COLORREF draw_if_selected_return_text_color( _In_ const UINT state, _In_ const COwnerDrawnListCtrl* const list, _In_ const RECT rcLabel, _In_ const RECT rc, _In_ CDC& pdc ) const; public: @@ -110,7 +110,7 @@ class COwnerDrawnListItem { } _Must_inspect_result_ _Success_( SUCCEEDED( return ) ) _Pre_satisfies_( subitem != column::COL_NAME ) - HRESULT GetText_WriteToStackBuffer ( _In_range_( 1, 6 ) const column::ENUM_COL subitem, WDS_WRITES_TO_STACK( strSize, chars_written ) PWSTR psz_text, _In_ const rsize_t strSize, _Out_ _On_failure_( _Post_valid_ )rsize_t& sizeBuffNeed, _Out_ rsize_t& chars_written ) const { + HRESULT GetText_WriteToStackBuffer ( _In_range_( 1, 6 ) const column::ENUM_COL subitem, WDS_WRITES_TO_STACK( strSize, chars_written ) PWSTR psz_text, _In_ const rsize_t strSize, _On_failure_( _Post_valid_ ) rsize_t& sizeBuffNeed, _Out_ rsize_t& chars_written ) const { ASSERT( subitem != column::COL_NAME ); if ( subitem == column::COL_NAME ) { displayWindowsMsgBoxWithMessage( L"GetText_WriteToStackBuffer was called for column::COL_NAME!!! This should never happen!!!!" ); @@ -978,6 +978,10 @@ class COwnerDrawnListCtrl : public CListCtrl { const HRESULT res_2 = item->GetText_WriteToStackBuffer( subitem, psz_subitem_formatted_text_2, subitem_text_size_2, sizeNeeded, chars_written_2 ); if ( SUCCEEDED( res_2 ) ) { dcmem.DrawTextW( psz_subitem_formatted_text_2, static_cast( chars_written_2 ), &rcText, DT_SINGLELINE | DT_VCENTER | DT_WORD_ELLIPSIS | DT_NOPREFIX | DT_NOCLIP | static_cast( align ) ); + + //shut analyze up! + sizeNeeded = 0; + return res; } return res; @@ -1597,15 +1601,13 @@ inline void COwnerDrawnListItem::DrawHighlightSelectBackground( _In_ const RECT& } -inline COLORREF COwnerDrawnListItem::draw_if_selected_return_text_color( _Out_opt_ INT* const width, _In_ const UINT state, _In_ const COwnerDrawnListCtrl* const list, const RECT rcLabel, const RECT rc, _In_ CDC& pdc ) const { +inline COLORREF COwnerDrawnListItem::draw_if_selected_return_text_color( _In_ const UINT state, _In_ const COwnerDrawnListCtrl* const list, _In_ const RECT rcLabel, _In_ const RECT rc, _In_ CDC& pdc ) const { auto textColor = GetSysColor( COLOR_WINDOWTEXT ); - if ( width == NULL && ( state bitand ODS_SELECTED ) != 0 && ( list->HasFocus( ) || list->IsShowSelectionAlways( ) ) ) { + if ( ( ( state bitand ODS_SELECTED ) != 0 ) && ( list->HasFocus( ) || list->IsShowSelectionAlways( ) ) ) { DrawHighlightSelectBackground( rcLabel, rc, list, pdc, textColor ); + return textColor; } - else { - textColor = item_text_color( ); // Use the color designated for this item. This is currently only for encrypted and compressed items - } - return textColor; + return item_text_color( ); // Use the color designated for this item. This is currently only for encrypted and compressed items } @@ -1632,7 +1634,7 @@ inline void COwnerDrawnListItem::DrawLabel( _In_ const COwnerDrawnListCtrl* cons CSetBkMode bk( pdc, TRANSPARENT ); //auto textColor = GetSysColor( COLOR_WINDOWTEXT ); - const auto textColor = draw_if_selected_return_text_color( width, state, list, rcLabel, rc, pdc ); + const auto textColor = draw_if_selected_return_text_color( state, list, rcLabel, rc, pdc ); //COLORREF draw_if_selected_return_text_color( width, state, list, rcLabel, rc, pdc ) //if ( width == NULL && ( state bitand ODS_SELECTED ) != 0 && ( list->HasFocus( ) || list->IsShowSelectionAlways( ) ) ) { diff --git a/WinDirStat/windirstat/typeview.cpp b/WinDirStat/windirstat/typeview.cpp index ee5f79b..51b97d9 100644 --- a/WinDirStat/windirstat/typeview.cpp +++ b/WinDirStat/windirstat/typeview.cpp @@ -93,10 +93,10 @@ HRESULT CListItem::Text_WriteToStackBuffer_COL_BYTES( RANGE_ENUM_COL const colum UNREFERENCED_PARAMETER( subitem ); #endif ASSERT( subitem == column::COL_BYTES ); - const auto res = wds_fmt::FormatBytes( m_record.bytes, psz_text, strSize, chars_written ); + const auto res = wds_fmt::FormatBytes( m_record.bytes, psz_text, strSize, chars_written, sizeBuffNeed ); if ( res == STRSAFE_E_INSUFFICIENT_BUFFER ) { chars_written = strSize; - sizeBuffNeed = 64;//Generic size needed. + sizeBuffNeed = ( ( 64 > sizeBuffNeed ) ? 64 : sizeBuffNeed );//Generic size needed. } return res; } @@ -178,7 +178,7 @@ HRESULT CListItem::Text_WriteToStackBuffer_COL_BYTESPERCENT( RANGE_ENUM_COL cons } _Must_inspect_result_ _Success_( SUCCEEDED( return ) ) -HRESULT CListItem::Text_WriteToStackBuffer( RANGE_ENUM_COL const column::ENUM_COL subitem, WDS_WRITES_TO_STACK( strSize, chars_written ) PWSTR psz_text, _In_ const rsize_t strSize, _Out_ _On_failure_( _Post_valid_ ) rsize_t& sizeBuffNeed, _Out_ rsize_t& chars_written ) const { +HRESULT CListItem::Text_WriteToStackBuffer( RANGE_ENUM_COL const column::ENUM_COL subitem, WDS_WRITES_TO_STACK( strSize, chars_written ) PWSTR psz_text, _In_ const rsize_t strSize, _On_failure_( _Post_valid_ ) rsize_t& sizeBuffNeed, _Out_ rsize_t& chars_written ) const { switch ( subitem ) { diff --git a/WinDirStat/windirstat/typeview.h b/WinDirStat/windirstat/typeview.h index 9b7dfe1..3f0af63 100644 --- a/WinDirStat/windirstat/typeview.h +++ b/WinDirStat/windirstat/typeview.h @@ -41,7 +41,7 @@ class CListItem final : public COwnerDrawnListItem { virtual bool DrawSubitem ( RANGE_ENUM_COL const column::ENUM_COL subitem, _In_ CDC& pdc, _In_ RECT rc, _In_ const UINT state, _Out_opt_ INT* const width, _Inout_ INT* const focusLeft, _In_ const COwnerDrawnListCtrl* const list ) const override final; _Must_inspect_result_ _Success_( SUCCEEDED( return ) ) - virtual HRESULT Text_WriteToStackBuffer( RANGE_ENUM_COL const column::ENUM_COL subitem, WDS_WRITES_TO_STACK( strSize, chars_written ) PWSTR psz_text, _In_ const rsize_t strSize, _Out_ _On_failure_( _Post_valid_ ) rsize_t& sizeBuffNeed, _Out_ rsize_t& chars_written ) const override final; + virtual HRESULT Text_WriteToStackBuffer( RANGE_ENUM_COL const column::ENUM_COL subitem, WDS_WRITES_TO_STACK( strSize, chars_written ) PWSTR psz_text, _In_ const rsize_t strSize, _On_failure_( _Post_valid_ ) rsize_t& sizeBuffNeed, _Out_ rsize_t& chars_written ) const override final; //_Pre_satisfies_( subitem == column::COL_EXTENSION ) _Success_( SUCCEEDED( return ) ) // HRESULT Text_WriteToStackBuffer_COL_EXTENSION( RANGE_ENUM_COL const column::ENUM_COL subitem, WDS_WRITES_TO_STACK( strSize, chars_written ) PWSTR psz_text, _In_ const rsize_t strSize, _Out_ _On_failure_( _Post_valid_ ) rsize_t& sizeBuffNeed, _Out_ rsize_t& chars_written ) const; diff --git a/WinDirStat/windirstat/windirstat.cpp b/WinDirStat/windirstat/windirstat.cpp index b31782f..a3080ec 100644 --- a/WinDirStat/windirstat/windirstat.cpp +++ b/WinDirStat/windirstat/windirstat.cpp @@ -270,7 +270,8 @@ _Success_( SUCCEEDED( return ) ) HRESULT CDirstatApp::GetCurrentProcessMemoryInf } wds_fmt::write_RAM_USAGE( psz_formatted_usage ); rsize_t chars_written = 0; - const HRESULT res = wds_fmt::FormatBytes( m_workingSet, &( psz_formatted_usage[ 11 ] ), ( strSize - 12 ), chars_written ); + rsize_t size_buff_needed = 0; + const HRESULT res = wds_fmt::FormatBytes( m_workingSet, &( psz_formatted_usage[ 11 ] ), ( strSize - 12 ), chars_written, size_buff_needed ); if ( !SUCCEEDED( res ) ) { return StringCchPrintfW( psz_formatted_usage, strSize, L"RAM Usage: %s", wds_fmt::FormatBytes( m_workingSet, GetOptions( )->m_humanFormat ).c_str( ) ); } diff --git a/WinDirStat/windirstat/windirstat.vcxproj b/WinDirStat/windirstat/windirstat.vcxproj index e4e539e..8847342 100644 --- a/WinDirStat/windirstat/windirstat.vcxproj +++ b/WinDirStat/windirstat/windirstat.vcxproj @@ -228,6 +228,7 @@ /time Default true + 64000 _DEBUG;%(PreprocessorDefinitions) @@ -273,6 +274,7 @@ Default true true + 64000 _DEBUG;%(PreprocessorDefinitions) @@ -338,6 +340,7 @@ + 64000 NDEBUG;%(PreprocessorDefinitions) @@ -421,6 +424,7 @@ true true Asm_and_Source + 64000 NDEBUG;%(PreprocessorDefinitions) @@ -508,6 +512,7 @@ NoListing false true + 64000 NDEBUG;%(PreprocessorDefinitions) @@ -570,6 +575,7 @@ true SendErrorReport true + 64000 NDEBUG;%(PreprocessorDefinitions) @@ -631,6 +637,7 @@ UseLinkTimeCodeGeneration true true + 64000 NDEBUG;%(PreprocessorDefinitions) @@ -692,6 +699,7 @@ UseLinkTimeCodeGeneration true true + 64000 NDEBUG;%(PreprocessorDefinitions)