diff options
-rw-r--r-- | include/o3tl/safeint.hxx | 5 | ||||
-rw-r--r-- | vcl/win/gdi/DWriteTextRenderer.cxx | 5 | ||||
-rw-r--r-- | vcl/win/gdi/winlayout.cxx | 7 |
3 files changed, 14 insertions, 3 deletions
diff --git a/include/o3tl/safeint.hxx b/include/o3tl/safeint.hxx index 6d8d1304fdf3..a5c212244c7c 100644 --- a/include/o3tl/safeint.hxx +++ b/include/o3tl/safeint.hxx @@ -234,6 +234,11 @@ make_unsigned(T value) return value; } +// An implicit conversion from T2 to T1, useful in places where an explicit conversion from T2 to +// T1 is needed (e.g., in list initialization, if the implicit conversion would be narrowing) but +// tools like -fsanitize=implict-conversion should still be able to detect truncation: +template<typename T1, typename T2> constexpr T1 narrowing(T2 value) { return value; } + } #endif diff --git a/vcl/win/gdi/DWriteTextRenderer.cxx b/vcl/win/gdi/DWriteTextRenderer.cxx index da8eab0e6ce0..185925ae7967 100644 --- a/vcl/win/gdi/DWriteTextRenderer.cxx +++ b/vcl/win/gdi/DWriteTextRenderer.cxx @@ -30,6 +30,7 @@ #include <winver.h> #include <comphelper/windowserrorstring.hxx> +#include <o3tl/safeint.hxx> #include <sal/log.hxx> namespace @@ -190,7 +191,9 @@ bool D2DWriteTextOutRenderer::Ready() const HRESULT D2DWriteTextOutRenderer::BindDC(HDC hDC, tools::Rectangle const & rRect) { - RECT const rc = { rRect.Left(), rRect.Top(), rRect.Right(), rRect.Bottom() }; + RECT const rc = { + o3tl::narrowing<LONG>(rRect.Left()), o3tl::narrowing<LONG>(rRect.Top()), + o3tl::narrowing<LONG>(rRect.Right()), o3tl::narrowing<LONG>(rRect.Bottom()) }; return CHECKHR(mpRT->BindDC(hDC, &rc)); } diff --git a/vcl/win/gdi/winlayout.cxx b/vcl/win/gdi/winlayout.cxx index 7863a3c353d2..398196438fb7 100644 --- a/vcl/win/gdi/winlayout.cxx +++ b/vcl/win/gdi/winlayout.cxx @@ -21,6 +21,8 @@ #include <config_features.h> #include <memory> + +#include <o3tl/safeint.hxx> #include <osl/module.h> #include <osl/file.h> #include <sal/log.hxx> @@ -594,8 +596,9 @@ void WinSalGraphics::DrawTextLayout(const GenericSalLayout& rLayout) // we are making changes to the DC, make sure we got a new one assert(aDC->getCompatibleHDC() != hDC); - RECT aWinRect = { aRect.Left(), aRect.Top(), aRect.Left() + aRect.GetWidth(), - aRect.Top() + aRect.GetHeight() }; + RECT aWinRect = { o3tl::narrowing<LONG>(aRect.Left()), o3tl::narrowing<LONG>(aRect.Top()), + o3tl::narrowing<LONG>(aRect.Left() + aRect.GetWidth()), + o3tl::narrowing<LONG>(aRect.Top() + aRect.GetHeight()) }; ::FillRect(aDC->getCompatibleHDC(), &aWinRect, static_cast<HBRUSH>(::GetStockObject(WHITE_BRUSH))); |