Skip to content

Commit

Permalink
C26429, symbols not tested for nullness.
Browse files Browse the repository at this point in the history
  • Loading branch information
miniksa committed Sep 3, 2019
1 parent 4f1157c commit 30e8e7f
Show file tree
Hide file tree
Showing 9 changed files with 167 additions and 66 deletions.
8 changes: 4 additions & 4 deletions src/buffer/out/textBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -584,20 +584,20 @@ COORD TextBuffer::GetLastNonSpaceCharacter(const Microsoft::Console::Types::View
// Search the given viewport by starting at the bottom.
coordEndOfText.Y = viewport.BottomInclusive();

const ROW* pCurrRow = &GetRowByOffset(coordEndOfText.Y);
const auto& currRow = GetRowByOffset(coordEndOfText.Y);
// The X position of the end of the valid text is the Right draw boundary (which is one beyond the final valid character)
coordEndOfText.X = gsl::narrow<short>(pCurrRow->GetCharRow().MeasureRight()) - 1;
coordEndOfText.X = gsl::narrow<short>(currRow.GetCharRow().MeasureRight()) - 1;

// If the X coordinate turns out to be -1, the row was empty, we need to search backwards for the real end of text.
const auto viewportTop = viewport.Top();
bool fDoBackUp = (coordEndOfText.X < 0 && coordEndOfText.Y > viewportTop); // this row is empty, and we're not at the top
while (fDoBackUp)
{
coordEndOfText.Y--;
pCurrRow = &GetRowByOffset(coordEndOfText.Y);
const auto& backupRow = GetRowByOffset(coordEndOfText.Y);
// We need to back up to the previous row if this line is empty, AND there are more rows

coordEndOfText.X = gsl::narrow<short>(pCurrRow->GetCharRow().MeasureRight()) - 1;
coordEndOfText.X = gsl::narrow<short>(backupRow.GetCharRow().MeasureRight()) - 1;
fDoBackUp = (coordEndOfText.X < 0 && coordEndOfText.Y > viewportTop);
}

Expand Down
17 changes: 17 additions & 0 deletions src/renderer/dx/CustomTextLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ CustomTextLayout::CustomTextLayout(IDWriteFactory1* const factory,
_runIndex{ 0 },
_width{ width }
{
THROW_HR_IF_NULL(E_INVALIDARG, format);

// Fetch the locale name out once now from the format
_localeName.resize(gsl::narrow_cast<size_t>(format->GetLocaleNameLength()) + 1); // +1 for null
THROW_IF_FAILED(format->GetLocaleName(_localeName.data(), gsl::narrow<UINT32>(_localeName.size())));
Expand All @@ -58,6 +60,7 @@ CustomTextLayout::CustomTextLayout(IDWriteFactory1* const factory,
// - S_OK or suitable DirectX/DirectWrite/Direct2D result code.
[[nodiscard]] HRESULT STDMETHODCALLTYPE CustomTextLayout::GetColumns(_Out_ UINT32* columns)
{
RETURN_HR_IF_NULL(E_INVALIDARG, columns);
*columns = 0;

RETURN_IF_FAILED(_AnalyzeRuns());
Expand Down Expand Up @@ -467,6 +470,8 @@ CustomTextLayout::CustomTextLayout(IDWriteFactory1* const factory,
IDWriteTextRenderer* renderer,
const D2D_POINT_2F origin) noexcept
{
RETURN_HR_IF_NULL(E_INVALIDARG, renderer);

try
{
// We're going to start from the origin given and walk to the right for each
Expand Down Expand Up @@ -561,6 +566,9 @@ CustomTextLayout::CustomTextLayout(IDWriteFactory1* const factory,
_Outptr_result_buffer_(*textLength) WCHAR const** textString,
_Out_ UINT32* textLength)
{
RETURN_HR_IF_NULL(E_INVALIDARG, textString);
RETURN_HR_IF_NULL(E_INVALIDARG, textLength);

*textString = nullptr;
*textLength = 0;

Expand All @@ -587,6 +595,9 @@ CustomTextLayout::CustomTextLayout(IDWriteFactory1* const factory,
_Outptr_result_buffer_(*textLength) WCHAR const** textString,
_Out_ UINT32* textLength) noexcept
{
RETURN_HR_IF_NULL(E_INVALIDARG, textString);
RETURN_HR_IF_NULL(E_INVALIDARG, textLength);

*textString = nullptr;
*textLength = 0;

Expand Down Expand Up @@ -624,6 +635,9 @@ CustomTextLayout::CustomTextLayout(IDWriteFactory1* const factory,
_Out_ UINT32* textLength,
_Outptr_result_z_ WCHAR const** localeName) noexcept
{
RETURN_HR_IF_NULL(E_INVALIDARG, textLength);
RETURN_HR_IF_NULL(E_INVALIDARG, localeName);

*localeName = _localeName.data();
*textLength = gsl::narrow<UINT32>(_text.size()) - textPosition;

Expand All @@ -643,6 +657,9 @@ CustomTextLayout::CustomTextLayout(IDWriteFactory1* const factory,
_Out_ UINT32* textLength,
_COM_Outptr_ IDWriteNumberSubstitution** numberSubstitution) noexcept
{
RETURN_HR_IF_NULL(E_INVALIDARG, textLength);
RETURN_HR_IF_NULL(E_INVALIDARG, numberSubstitution);

*numberSubstitution = nullptr;
*textLength = gsl::narrow<UINT32>(_text.size()) - textPosition;

Expand Down
88 changes: 54 additions & 34 deletions src/renderer/dx/CustomTextRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ using namespace Microsoft::Console::Render;
[[nodiscard]] HRESULT CustomTextRenderer::IsPixelSnappingDisabled(void* /*clientDrawingContext*/,
_Out_ BOOL* isDisabled) noexcept
{
RETURN_HR_IF_NULL(E_INVALIDARG, isDisabled);

*isDisabled = false;
return S_OK;
}
Expand All @@ -40,7 +42,10 @@ using namespace Microsoft::Console::Render;
[[nodiscard]] HRESULT CustomTextRenderer::GetPixelsPerDip(void* clientDrawingContext,
_Out_ FLOAT* pixelsPerDip) noexcept
{
RETURN_HR_IF_NULL(E_INVALIDARG, pixelsPerDip);

DrawingContext* drawingContext = static_cast<DrawingContext*>(clientDrawingContext);
RETURN_HR_IF_NULL(E_INVALIDARG, drawingContext);

float dpiX, dpiY;
drawingContext->renderTarget->GetDpi(&dpiX, &dpiY);
Expand All @@ -60,7 +65,10 @@ using namespace Microsoft::Console::Render;
[[nodiscard]] HRESULT CustomTextRenderer::GetCurrentTransform(void* clientDrawingContext,
DWRITE_MATRIX* transform) noexcept
{
RETURN_HR_IF_NULL(E_INVALIDARG, transform);

DrawingContext* drawingContext = static_cast<DrawingContext*>(clientDrawingContext);
RETURN_HR_IF_NULL(E_INVALIDARG, drawingContext);

// Matrix structures are defined identically
drawingContext->renderTarget->GetTransform(reinterpret_cast<D2D1_MATRIX_3X2_F*>(transform));
Expand Down Expand Up @@ -90,15 +98,14 @@ using namespace Microsoft::Console::Render;
_In_ const DWRITE_UNDERLINE* underline,
IUnknown* clientDrawingEffect) noexcept
{
_FillRectangle(clientDrawingContext,
clientDrawingEffect,
baselineOriginX,
baselineOriginY + underline->offset,
underline->width,
underline->thickness,
underline->readingDirection,
underline->flowDirection);
return S_OK;
return _FillRectangle(clientDrawingContext,
clientDrawingEffect,
baselineOriginX,
baselineOriginY + underline->offset,
underline->width,
underline->thickness,
underline->readingDirection,
underline->flowDirection);
}

// Routine Description:
Expand All @@ -122,15 +129,14 @@ using namespace Microsoft::Console::Render;
_In_ const DWRITE_STRIKETHROUGH* strikethrough,
IUnknown* clientDrawingEffect) noexcept
{
_FillRectangle(clientDrawingContext,
clientDrawingEffect,
baselineOriginX,
baselineOriginY + strikethrough->offset,
strikethrough->width,
strikethrough->thickness,
strikethrough->readingDirection,
strikethrough->flowDirection);
return S_OK;
return _FillRectangle(clientDrawingContext,
clientDrawingEffect,
baselineOriginX,
baselineOriginY + strikethrough->offset,
strikethrough->width,
strikethrough->thickness,
strikethrough->readingDirection,
strikethrough->flowDirection);
}

// Routine Description:
Expand All @@ -146,16 +152,17 @@ using namespace Microsoft::Console::Render;
// - flowDirection - textual flow information that could affect the rectangle
// Return Value:
// - S_OK
void CustomTextRenderer::_FillRectangle(void* clientDrawingContext,
IUnknown* clientDrawingEffect,
float x,
float y,
float width,
float thickness,
DWRITE_READING_DIRECTION /*readingDirection*/,
DWRITE_FLOW_DIRECTION /*flowDirection*/) noexcept
[[nodiscard]] HRESULT CustomTextRenderer::_FillRectangle(void* clientDrawingContext,
IUnknown* clientDrawingEffect,
float x,
float y,
float width,
float thickness,
DWRITE_READING_DIRECTION /*readingDirection*/,
DWRITE_FLOW_DIRECTION /*flowDirection*/) noexcept
{
DrawingContext* drawingContext = static_cast<DrawingContext*>(clientDrawingContext);
RETURN_HR_IF_NULL(E_INVALIDARG, drawingContext);

// Get brush
ID2D1Brush* brush = drawingContext->foregroundBrush;
Expand Down Expand Up @@ -191,6 +198,8 @@ void CustomTextRenderer::_FillRectangle(void* clientDrawingContext,
BOOL isRightToLeft,
IUnknown* clientDrawingEffect) noexcept
{
RETURN_HR_IF_NULL(E_INVALIDARG, inlineObject);

return inlineObject->Draw(clientDrawingContext,
this,
originX,
Expand Down Expand Up @@ -254,7 +263,7 @@ void CustomTextRenderer::_FillRectangle(void* clientDrawingContext,
{
rect.right += advance;
}

d2dContext->FillRectangle(rect, drawingContext->backgroundBrush);

// Now go onto drawing the text.
Expand Down Expand Up @@ -284,13 +293,13 @@ void CustomTextRenderer::_FillRectangle(void* clientDrawingContext,
// there are, glyphRunEnumerator can be used to iterate through them.
::Microsoft::WRL::ComPtr<IDWriteColorGlyphRunEnumerator1> glyphRunEnumerator;
const HRESULT hr = dwriteFactory4->TranslateColorGlyphRun(baselineOrigin,
glyphRun,
glyphRunDescription,
supportedFormats,
measuringMode,
nullptr,
0,
&glyphRunEnumerator);
glyphRun,
glyphRunDescription,
supportedFormats,
measuringMode,
nullptr,
0,
&glyphRunEnumerator);

// If the analysis found no color glyphs in the run, just draw normally.
if (hr == DWRITE_E_NOCOLOR)
Expand Down Expand Up @@ -414,6 +423,11 @@ void CustomTextRenderer::_FillRectangle(void* clientDrawingContext,
_In_ const DWRITE_GLYPH_RUN_DESCRIPTION* glyphRunDescription,
ID2D1Brush* brush)
{
RETURN_HR_IF_NULL(E_INVALIDARG, clientDrawingContext);
RETURN_HR_IF_NULL(E_INVALIDARG, glyphRun);
RETURN_HR_IF_NULL(E_INVALIDARG, glyphRunDescription);
RETURN_HR_IF_NULL(E_INVALIDARG, brush);

::Microsoft::WRL::ComPtr<ID2D1DeviceContext> d2dContext;
RETURN_IF_FAILED(clientDrawingContext->renderTarget->QueryInterface(d2dContext.GetAddressOf()));

Expand All @@ -435,6 +449,9 @@ void CustomTextRenderer::_FillRectangle(void* clientDrawingContext,
_In_ const DWRITE_GLYPH_RUN* glyphRun,
_In_ const DWRITE_GLYPH_RUN_DESCRIPTION* /*glyphRunDescription*/) noexcept
{
RETURN_HR_IF_NULL(E_INVALIDARG, clientDrawingContext);
RETURN_HR_IF_NULL(E_INVALIDARG, glyphRun);

// This is regular text but manually
::Microsoft::WRL::ComPtr<ID2D1Factory> d2dFactory;
clientDrawingContext->renderTarget->GetFactory(d2dFactory.GetAddressOf());
Expand Down Expand Up @@ -475,6 +492,9 @@ void CustomTextRenderer::_FillRectangle(void* clientDrawingContext,
_In_ const DWRITE_GLYPH_RUN* glyphRun,
_In_ const DWRITE_GLYPH_RUN_DESCRIPTION* /*glyphRunDescription*/) noexcept
{
RETURN_HR_IF_NULL(E_INVALIDARG, clientDrawingContext);
RETURN_HR_IF_NULL(E_INVALIDARG, glyphRun);

// This is glow text manually
::Microsoft::WRL::ComPtr<ID2D1Factory> d2dFactory;
clientDrawingContext->renderTarget->GetFactory(d2dFactory.GetAddressOf());
Expand Down
16 changes: 8 additions & 8 deletions src/renderer/dx/CustomTextRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@ namespace Microsoft::Console::Render
IUnknown* clientDrawingEffect) noexcept override;

private:
void _FillRectangle(void* clientDrawingContext,
IUnknown* clientDrawingEffect,
float x,
float y,
float width,
float thickness,
DWRITE_READING_DIRECTION readingDirection,
DWRITE_FLOW_DIRECTION flowDirection) noexcept;
[[nodiscard]] HRESULT _FillRectangle(void* clientDrawingContext,
IUnknown* clientDrawingEffect,
float x,
float y,
float width,
float thickness,
DWRITE_READING_DIRECTION readingDirection,
DWRITE_FLOW_DIRECTION flowDirection) noexcept;

[[nodiscard]] HRESULT _DrawBasicGlyphRun(DrawingContext* clientDrawingContext,
D2D1_POINT_2F baselineOrigin,
Expand Down
14 changes: 14 additions & 0 deletions src/renderer/dx/DxRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,8 @@ Microsoft::WRL::ComPtr<IDXGISwapChain1> DxEngine::GetSwapChain()
// - S_OK
[[nodiscard]] HRESULT DxEngine::Invalidate(const SMALL_RECT* const psrRegion) noexcept
{
RETURN_HR_IF_NULL(E_INVALIDARG, psrRegion);

_InvalidOr(*psrRegion);
return S_OK;
}
Expand All @@ -456,6 +458,8 @@ Microsoft::WRL::ComPtr<IDXGISwapChain1> DxEngine::GetSwapChain()
// - S_OK
[[nodiscard]] HRESULT DxEngine::InvalidateCursor(const COORD* const pcoordCursor) noexcept
{
RETURN_HR_IF_NULL(E_INVALIDARG, pcoordCursor);

const SMALL_RECT sr = Microsoft::Console::Types::Viewport::FromCoord(*pcoordCursor).ToInclusive();
return Invalidate(&sr);
}
Expand All @@ -468,6 +472,8 @@ Microsoft::WRL::ComPtr<IDXGISwapChain1> DxEngine::GetSwapChain()
// - S_OK
[[nodiscard]] HRESULT DxEngine::InvalidateSystem(const RECT* const prcDirtyClient) noexcept
{
RETURN_HR_IF_NULL(E_INVALIDARG, prcDirtyClient);

_InvalidOr(*prcDirtyClient);

return S_OK;
Expand Down Expand Up @@ -564,6 +570,8 @@ Microsoft::WRL::ComPtr<IDXGISwapChain1> DxEngine::GetSwapChain()
// - S_FALSE because we don't use this.
[[nodiscard]] HRESULT DxEngine::InvalidateCircling(_Out_ bool* const pForcePaint) noexcept
{
RETURN_HR_IF_NULL(E_INVALIDARG, pForcePaint);

*pForcePaint = false;
return S_FALSE;
}
Expand Down Expand Up @@ -709,6 +717,8 @@ void DxEngine::_InvalidOr(RECT rc) noexcept
// - S_FALSE because this is unused.
[[nodiscard]] HRESULT DxEngine::PrepareForTeardown(_Out_ bool* const pForcePaint) noexcept
{
RETURN_HR_IF_NULL(E_INVALIDARG, pForcePaint);

*pForcePaint = false;
return S_FALSE;
}
Expand Down Expand Up @@ -1382,6 +1392,8 @@ float DxEngine::GetScaling() const noexcept
// - S_OK or relevant DirectWrite error.
[[nodiscard]] HRESULT DxEngine::IsGlyphWideByFont(const std::wstring_view glyph, _Out_ bool* const pResult) noexcept
{
RETURN_HR_IF_NULL(E_INVALIDARG, pResult);

try
{
const Cluster cluster(glyph, 0); // columns don't matter, we're doing analysis not layout.
Expand Down Expand Up @@ -1532,6 +1544,8 @@ float DxEngine::GetScaling() const noexcept
[[nodiscard]] std::wstring DxEngine::_GetFontFamilyName(IDWriteFontFamily* const fontFamily,
std::wstring& localeName) const
{
THROW_HR_IF_NULL(E_INVALIDARG, fontFamily);

// See: https://docs.microsoft.com/en-us/windows/win32/api/dwrite/nn-dwrite-idwritefontcollection
Microsoft::WRL::ComPtr<IDWriteLocalizedStrings> familyNames;
THROW_IF_FAILED(fontFamily->GetFamilyNames(&familyNames));
Expand Down
Loading

0 comments on commit 30e8e7f

Please sign in to comment.