[Libreoffice-commits] core.git: include/o3tl vcl/win
Stephan Bergmann (via logerrit)
logerrit at kemper.freedesktop.org
Wed Nov 25 13:09:10 UTC 2020
include/o3tl/safeint.hxx | 5 +++++
vcl/win/gdi/DWriteTextRenderer.cxx | 5 ++++-
vcl/win/gdi/winlayout.cxx | 7 +++++--
3 files changed, 14 insertions(+), 3 deletions(-)
New commits:
commit b1404b5919f8c18bde715f68b229d2c030de5b2a
Author: Stephan Bergmann <sbergman at redhat.com>
AuthorDate: Wed Nov 25 11:06:00 2020 +0100
Commit: Stephan Bergmann <sbergman at redhat.com>
CommitDate: Wed Nov 25 14:08:20 2020 +0100
-Wc++11-narrowing (clang-cl)
MSVC seems not to mind, but a Windows 64-bit build with clang-cl fails with
"error: non-constant-expression cannot be narrowed from type 'tools::Long' (aka
'long long') to 'LONG' (aka 'long') in initializer list". But adding explicit
casts would have the downside of preventing tools like
-fsanitize=implict-conversion (if we ever use that on Windows) from detecting
truncation, so introduce o3tl::narrowing.
Change-Id: Ia33a9ae4d8134b5ad0c8b7cf6812fbdd625ca89e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/106577
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman at redhat.com>
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)));
More information about the Libreoffice-commits
mailing list