Skip to content

Commit

Permalink
wrote generalized Text_WriteToStackBuffer invalid
Browse files Browse the repository at this point in the history
... `subitem` handler
  • Loading branch information
ariccio committed Feb 6, 2015
1 parent 922381b commit 632d73f
Show file tree
Hide file tree
Showing 8 changed files with 162 additions and 137 deletions.
2 changes: 1 addition & 1 deletion WinDirStat/windirstat/SelectDrivesDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ HRESULT CDriveItem::Text_WriteToStackBuffer( RANGE_ENUM_COL const column::ENUM_C
case column::COL_FILES_TYPEVIEW:
case column::COL_ATTRIBUTES:
default:
return WriteToStackBuffer_default( psz_text, strSize, sizeBuffNeed, chars_written );
return WriteToStackBuffer_default( subitem, psz_text, strSize, sizeBuffNeed, chars_written, L"CDriveItem::" );
}
}
CDriveInformationThread::CDriveInformationThread( _In_ std::wstring path, LPARAM driveItem, HWND dialog, UINT serial, rsize_t thread_num ) : m_path( std::move( path ) ), m_driveItem( driveItem ), m_serial( serial ), m_threadNum( thread_num ), m_dialog( dialog ), m_totalBytes( 0 ), m_freeBytes( 0 ), m_success( false ) {
Expand Down
20 changes: 10 additions & 10 deletions WinDirStat/windirstat/SelectDrivesDlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,16 @@ class CDriveItem final : public COwnerDrawnListItem {
//_Must_inspect_result_ _Success_( SUCCEEDED( return ) )
// HRESULT Text_WriteToStackBuffer_COL_TOTAL( 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;

_Must_inspect_result_ _Success_( SUCCEEDED( return ) )
HRESULT WriteToStackBuffer_default( WDS_WRITES_TO_STACK( strSize, chars_written ) PWSTR psz_text, _In_ const rsize_t strSize, rsize_t& sizeBuffNeed, _Out_ rsize_t& chars_written ) const {
ASSERT( false );
if ( strSize > 41 ) {
wds_fmt::write_bad_fmt_msg( psz_text, chars_written );
return S_OK;
}
sizeBuffNeed = 64;
return STRSAFE_E_INSUFFICIENT_BUFFER;
}
//_Must_inspect_result_ _Success_( SUCCEEDED( return ) )
//HRESULT WriteToStackBuffer_default( WDS_WRITES_TO_STACK( strSize, chars_written ) PWSTR psz_text, _In_ const rsize_t strSize, rsize_t& sizeBuffNeed, _Out_ rsize_t& chars_written ) const {
// ASSERT( false );
// if ( strSize > 41 ) {
// wds_fmt::write_bad_fmt_msg( psz_text, chars_written );
// return S_OK;
// }
// sizeBuffNeed = 64;
// return STRSAFE_E_INSUFFICIENT_BUFFER;
// }


_Must_inspect_result_ _Success_( SUCCEEDED( return ) )
Expand Down
60 changes: 30 additions & 30 deletions WinDirStat/windirstat/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,35 +140,35 @@ HRESULT CItemBranch::WriteToStackBuffer_COL_ATTRIBUTES( RANGE_ENUM_COL const col
return res;
}

_Success_( SUCCEEDED( return ) )
HRESULT CItemBranch::WriteToStackBuffer_default( WDS_WRITES_TO_STACK( strSize, chars_written ) PWSTR psz_text, _In_ const rsize_t strSize, rsize_t& sizeBuffNeed, _Out_ rsize_t& chars_written ) const {
ASSERT( strSize > 8 );
sizeBuffNeed = SIZE_T_ERROR;
//auto res = StringCchPrintfW( psz_text, strSize, L"BAD GetText_WriteToStackBuffer - subitem" );
size_t chars_remaining = 0;
const HRESULT res = StringCchPrintfExW( psz_text, strSize, NULL, &chars_remaining, 0, L"BAD GetText_WriteToStackBuffer - subitem" );
if ( res == STRSAFE_E_INSUFFICIENT_BUFFER ) {
if ( strSize > 8 ) {
wds_fmt::write_BAD_FMT( psz_text, chars_written );
}
else {
chars_written = strSize;
displayWindowsMsgBoxWithMessage( std::wstring( L"CItemBranch::" ) + std::wstring( global_strings::write_to_stackbuffer_err ) );
}
}
else if ( ( res != STRSAFE_E_INSUFFICIENT_BUFFER ) && ( FAILED( res ) ) ) {
chars_written = 0;
}

if ( SUCCEEDED( res ) ) {
chars_written = ( strSize - chars_remaining );
}


ASSERT( SUCCEEDED( res ) );
ASSERT( chars_written == wcslen( psz_text ) );
return res;
}
//_Success_( SUCCEEDED( return ) )
//HRESULT CItemBranch::WriteToStackBuffer_default( WDS_WRITES_TO_STACK( strSize, chars_written ) PWSTR psz_text, _In_ const rsize_t strSize, rsize_t& sizeBuffNeed, _Out_ rsize_t& chars_written ) const {
// ASSERT( strSize > 8 );
// sizeBuffNeed = SIZE_T_ERROR;
// //auto res = StringCchPrintfW( psz_text, strSize, L"BAD GetText_WriteToStackBuffer - subitem" );
// size_t chars_remaining = 0;
// const HRESULT res = StringCchPrintfExW( psz_text, strSize, NULL, &chars_remaining, 0, L"BAD GetText_WriteToStackBuffer - subitem" );
// if ( res == STRSAFE_E_INSUFFICIENT_BUFFER ) {
// if ( strSize > 8 ) {
// wds_fmt::write_BAD_FMT( psz_text, chars_written );
// }
// else {
// chars_written = strSize;
// displayWindowsMsgBoxWithMessage( std::wstring( L"CItemBranch::" ) + std::wstring( global_strings::write_to_stackbuffer_err ) );
// }
// }
// else if ( ( res != STRSAFE_E_INSUFFICIENT_BUFFER ) && ( FAILED( res ) ) ) {
// chars_written = 0;
// }
//
// if ( SUCCEEDED( res ) ) {
// chars_written = ( strSize - chars_remaining );
// }
//
//
// ASSERT( SUCCEEDED( res ) );
// ASSERT( chars_written == wcslen( psz_text ) );
// return res;
// }


_Must_inspect_result_ _Success_( SUCCEEDED( return ) )
Expand All @@ -189,7 +189,7 @@ HRESULT CItemBranch::Text_WriteToStackBuffer( RANGE_ENUM_COL const column::ENUM_
return WriteToStackBuffer_COL_ATTRIBUTES( subitem, psz_text, strSize, sizeBuffNeed, chars_written );
case column::COL_NAME:
default:
return WriteToStackBuffer_default( psz_text, strSize, sizeBuffNeed, chars_written );
return WriteToStackBuffer_default( subitem, psz_text, strSize, sizeBuffNeed, chars_written, L"CItemBranch::" );
}
}

Expand Down
4 changes: 2 additions & 2 deletions WinDirStat/windirstat/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ class CItemBranch final : public CTreeListItem {
_Pre_satisfies_( subitem == column::COL_ATTRIBUTES ) _Success_( SUCCEEDED( return ) )
inline HRESULT WriteToStackBuffer_COL_ATTRIBUTES( 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;

_Success_( SUCCEEDED( return ) )
HRESULT WriteToStackBuffer_default( WDS_WRITES_TO_STACK( strSize, chars_written ) PWSTR psz_text, _In_ const rsize_t strSize, rsize_t& sizeBuffNeed, _Out_ rsize_t& chars_written ) const;
// _Success_( SUCCEEDED( return ) )
//HRESULT WriteToStackBuffer_default( WDS_WRITES_TO_STACK( strSize, chars_written ) PWSTR psz_text, _In_ const rsize_t strSize, rsize_t& sizeBuffNeed, _Out_ rsize_t& chars_written ) const;

INT CompareSibling ( _In_ const CTreeListItem* const tlib, _In_ _In_range_( 0, INT32_MAX ) const column::ENUM_COL subitem ) const;

Expand Down
34 changes: 33 additions & 1 deletion WinDirStat/windirstat/ownerdrawnlistcontrol.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,37 @@ class COwnerDrawnListItem {
//_Pre_satisfies_( subitem == column::COL_NAME ) _Success_( SUCCEEDED( return ) )
//HRESULT WriteToStackBuffer_COL_NAME ( 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;

_Success_( SUCCEEDED( return ) )
HRESULT WriteToStackBuffer_default( 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, _In_z_ const PCWSTR instantiation_type_of_COwnerDrawnListItem ) const {
sizeBuffNeed = SIZE_T_ERROR;
size_t chars_remaining = 0;
ASSERT( strSize > 8 );
const auto res = StringCchPrintfExW( psz_text, strSize, NULL, &chars_remaining, 0, L"BAD GetText_WriteToStackBuffer - subitem" );
if ( res == STRSAFE_E_INSUFFICIENT_BUFFER ) {
if ( strSize > 8 ) {
wds_fmt::write_BAD_FMT( psz_text, chars_written );
}
else {
chars_written = strSize;
displayWindowsMsgBoxWithMessage( std::wstring( instantiation_type_of_COwnerDrawnListItem ) + std::wstring( global_strings::write_to_stackbuffer_err ) + L", subitem:" + std::to_wstring( static_cast<int>( subitem ) ) );
}
}
else if ( ( res != STRSAFE_E_INSUFFICIENT_BUFFER ) && ( FAILED( res ) ) ) {
chars_written = 0;
}
else {
ASSERT( SUCCEEDED( res ) );
if ( SUCCEEDED( res ) ) {
chars_written = ( strSize - chars_remaining );
}
}
ASSERT( SUCCEEDED( res ) );
ASSERT( chars_written == wcslen( psz_text ) );
return res;
}




INT default_compare ( _In_ const COwnerDrawnListItem* const baseOther ) const {
return signum( wcscmp( m_name.get( ), baseOther->m_name.get( ) ) );
Expand Down Expand Up @@ -1116,10 +1147,11 @@ class COwnerDrawnListCtrl : public CListCtrl {
}

return GetWidth_not_ownerdrawn( item, subitem, rc, dc );

}

public:


CMainFrame* const m_frameptr;
bool m_showGrid : 1; // Whether to draw a grid
bool m_showStripes : 1; // Whether to show stripes
Expand Down
16 changes: 6 additions & 10 deletions WinDirStat/windirstat/treemap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -720,19 +720,16 @@ void CTreemap::compensateForGrid( _Inout_ RECT& rc, _In_ CDC& pdc ) const {

//rc.NormalizeRect( );
pdc.FillSolidRect( &rc, m_options.gridColor );
rc.right--;
rc.bottom--;
ASSERT( !zero_size_rect( rc ) );
return;
}
else {
// We shrink the rectangle here, too. If we didn't do this, the layout of the treemap would change, when grid is switched on and off.
shrink_for_grid( pdc, rc );
}
// We shrink the rectangle here, too. If we didn't do this, the layout of the treemap would change, when grid is switched on and off.
shrink_for_grid( pdc, rc );
rc.right--;
rc.bottom--;
ASSERT( !zero_size_rect( rc ) );
if ( zero_size_rect( rc ) ) {

return;
}

}

void CTreemap::DrawTreemap( _In_ CDC& offscreen_buffer, _Inout_ RECT& rc, _In_ const CItemBranch* const root, _In_ const Treemap_Options& options ) {
Expand All @@ -751,7 +748,6 @@ void CTreemap::DrawTreemap( _In_ CDC& offscreen_buffer, _Inout_ RECT& rc, _In_ c

compensateForGrid( rc, offscreen_buffer );

ASSERT( !zero_size_rect( rc ) );
if ( zero_size_rect( rc ) ) {
return;
}
Expand Down
Loading

0 comments on commit 632d73f

Please sign in to comment.