[Libreoffice-commits] core.git: include/o3tl xmloff/source

2018-01-28 Thread Caolán McNamara
 include/o3tl/safeint.hxx|   30 ++
 xmloff/source/draw/ximpshap.cxx |8 
 2 files changed, 34 insertions(+), 4 deletions(-)

New commits:
commit 94823392874be9c9249e312f6783394edf0e731f
Author: Caolán McNamara 
Date:   Sun Jan 28 14:15:44 2018 +

ofz#5621 Integer-overflow

Change-Id: Ie0a7c29428e686e5c480997b84b8d12e5be4539f
Reviewed-on: https://gerrit.libreoffice.org/48790
Tested-by: Jenkins 
Reviewed-by: Caolán McNamara 
Tested-by: Caolán McNamara 

diff --git a/include/o3tl/safeint.hxx b/include/o3tl/safeint.hxx
index 67af99cf810c..fa08b6dfc899 100644
--- a/include/o3tl/safeint.hxx
+++ b/include/o3tl/safeint.hxx
@@ -57,6 +57,36 @@ typename std::enable_if::type 
saturating_add(
 }
 
 template inline
+typename std::enable_if::type saturating_sub(
+T a, T b)
+{
+if (b >= 0) {
+if (a >= std::numeric_limits::min() + b) {
+return a - b;
+} else {
+return std::numeric_limits::min();
+}
+} else {
+if (a <= std::numeric_limits::max() + b) {
+return a - b;
+} else {
+return std::numeric_limits::max();
+}
+}
+}
+
+template inline
+typename std::enable_if::type saturating_sub(
+T a, T b)
+{
+if (a >= std::numeric_limits::min() + b) {
+return a - b;
+} else {
+return std::numeric_limits::min();
+}
+}
+
+template inline
 typename std::enable_if::type 
saturating_toggle_sign(
 T a)
 {
diff --git a/xmloff/source/draw/ximpshap.cxx b/xmloff/source/draw/ximpshap.cxx
index 616dec4d1ba2..4ccdb68d5ff1 100644
--- a/xmloff/source/draw/ximpshap.cxx
+++ b/xmloff/source/draw/ximpshap.cxx
@@ -1083,16 +1083,16 @@ void SdXMLLineShapeContext::StartElement(const 
uno::Reference< xml::sax::XAttrib
 pOuterSequence->realloc(2);
 awt::Point* pInnerSequence = pOuterSequence->getArray();
 
-*pInnerSequence = awt::Point(o3tl::saturating_add(mnX1, -aTopLeft.X), 
o3tl::saturating_add(mnY1, -aTopLeft.Y));
+*pInnerSequence = awt::Point(o3tl::saturating_sub(mnX1, aTopLeft.X), 
o3tl::saturating_sub(mnY1, aTopLeft.Y));
 pInnerSequence++;
-*pInnerSequence = awt::Point(o3tl::saturating_add(mnX2, -aTopLeft.X), 
o3tl::saturating_add(mnY2, -aTopLeft.Y));
+*pInnerSequence = awt::Point(o3tl::saturating_sub(mnX2, aTopLeft.X), 
o3tl::saturating_sub(mnY2, aTopLeft.Y));
 
 xPropSet->setPropertyValue("Geometry", Any(aPolyPoly));
 }
 
 // set sizes for transformation
-maSize.Width = o3tl::saturating_add(aBottomRight.X, -aTopLeft.X);
-maSize.Height = o3tl::saturating_add(aBottomRight.Y, -aTopLeft.Y);
+maSize.Width = o3tl::saturating_sub(aBottomRight.X, aTopLeft.X);
+maSize.Height = o3tl::saturating_sub(aBottomRight.Y, aTopLeft.Y);
 maPosition.X = aTopLeft.X;
 maPosition.Y = aTopLeft.Y;
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/o3tl xmloff/source

2016-06-02 Thread Stephan Bergmann
 include/o3tl/any.hxx  |  264 ++
 xmloff/source/core/unoatrcn.cxx   |   10 
 xmloff/source/draw/XMLImageMapExport.cxx  |3 
 xmloff/source/draw/animationexport.cxx|   66 ++---
 xmloff/source/draw/shapeexport.cxx|   13 -
 xmloff/source/draw/ximpcustomshape.cxx|   21 -
 xmloff/source/style/XMLPageExport.cxx |3 
 xmloff/source/style/prstylei.cxx  |5 
 xmloff/source/style/styleexp.cxx  |9 
 xmloff/source/style/xmlbahdl.cxx  |3 
 xmloff/source/style/xmlnume.cxx   |6 
 xmloff/source/style/xmlnumi.cxx   |3 
 xmloff/source/style/xmlstyle.cxx  |2 
 xmloff/source/text/XMLIndexMarkExport.cxx |5 
 xmloff/source/text/XMLLineNumberingExport.cxx |9 
 xmloff/source/text/XMLRedlineExport.cxx   |   23 +
 xmloff/source/text/XMLSectionExport.cxx   |   31 +-
 xmloff/source/text/XMLTextColumnsExport.cxx   |7 
 xmloff/source/text/XMLTextHeaderFooterContext.cxx |7 
 xmloff/source/text/XMLTextMasterPageContext.cxx   |3 
 xmloff/source/text/txtexppr.cxx   |9 
 xmloff/source/text/txtflde.cxx|5 
 xmloff/source/text/txtftne.cxx|6 
 xmloff/source/text/txtimppr.cxx   |5 
 xmloff/source/text/txtparae.cxx   |   45 ++-
 xmloff/source/text/txtprhdl.cxx   |   15 -
 xmloff/source/text/txtstyli.cxx   |4 
 27 files changed, 437 insertions(+), 145 deletions(-)

New commits:
commit 0d7c5823124696f80583ac2a5f0e28f329f6f786
Author: Stephan Bergmann 
Date:   Thu Jun 2 15:06:06 2016 +0200

New o3tl::try/doGet to obtain value from Any

...in an attempt to reduce usage of type-unsafe

  void const * css::uno::Any::getValue()

These new functions are often more convenient to use than the existing 
">>=" and
Any::get.  Note how they are careful to provide a pointer directly into 
the
given Any, instead of creating temporaries.

As an example, replaced most calls of getValue across xmloff:

* Cases that first check for a specific type (via getValueType etc.) and 
then
  call getValue can instead call tryGet.  (But beware that tryGet supports 
some
  conversions, which a check for a specific type may have missed---either
  intentionally or by accident.  Also beware the somewhat common idiom of
  checking for TypeClass_ENUM and then using getValue to obtain a sal_Int32;
  this cannot be replaced with a call to tryGet.)

* Cases that seem confident that the Any is of the correct type when calling
  getValue (but apparently are confident due to some higher-layer protocol, 
as
  the surrounding code does not do any checking via getValueType or 
similar) can
  instead call doGet.  It throws an exception if it turns out the confidence
  wasn't warranted.  (Many of the existing calls that directly dereferenced 
the
  return value of getValue as sal_Bool look suspicious, in that the author 
might
  have thought the given code would also cover a VOID Any---which 
technically it
  even would have happened to do.  If any RuntimeExceptions thrown from 
these
  doGet calls start to crop up, these changes need to be revisited.  Some 
may
  even be rewritten as uses of ">>=".  But at least "make check" did not 
show
  any such problems.  Also note that casting the value obtained from 
getValue to
  any css::uno::Reference with X being anything but the base
  css::uno::XInterface was always prone to producing a bad pointer, in case 
the
  interface actually stored in the Any derived from X via multiple 
inheritance.)

* Should there ever be cases where an Any is known to be of the requested 
type,
  some additional forceGet could be introduced (which would assert instead 
of
  throwing an exception).

Change-Id: I2d8739e86314eff73abfcafe01d806f5bc5c34db

diff --git a/include/o3tl/any.hxx b/include/o3tl/any.hxx
new file mode 100644
index 000..268ae20
--- /dev/null
+++ b/include/o3tl/any.hxx
@@ -0,0 +1,264 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef INCLUDED_O3TL_ANY_HXX
+#define INCLUDED_O3TL_ANY_HXX
+
+#include 
+
+#include 
+#include 
+
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+// Some functionality related to css::uno::Any that would ideally be part of
+// , but (for now) cannot be for some reason.
+