summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2019-02-12 15:21:12 +0100
committerCaolán McNamara <caolanm@redhat.com>2019-02-13 10:06:21 +0100
commitbbab991c70e2a1867493d701168f49a0d0dcbd48 (patch)
treecd7487e769dba2f826401fecf5005d197aefb436
parent91731a8674d764293e2988333027f82f15b2577e (diff)
Avoid -fsanitize=implicit-signed-integer-truncation in weld::MetricSpinButton
Both of Draw's "Insert - Snap Guide..." and "Shape - Duplicate..." dialogs have MetricSpinButtons with ranges set programmatically in the dialogs' ctors. Computing the ranges' min and max values was done via SetMetricValue, which does any necessary unit conversions and then sets the MetricSpinButton's current value, which is then read back out in the dialog ctors (again, doing any necessary unit conversions) and finally set as the min or max range value. However, setting a MetricSpinButton's current value clamps it to the min and max range values that are currently in effect (i.e., before they have been set programmatically), so the corresponding .ui files specified very large initial values for those. Large enough so that any actually set current values will not artificially be clamped, but also so large that weld::MetricSpinButton::ConvertValue, which indirectly gets called during the above computations and converts from sal_Int64 to int, would produce Clang -fsanitize=implicit-signed-integer-truncation warnings (e.g., "implicit conversion from type 'sal_Int64' (aka 'long') of value -56692913386 (64-bit, signed) to type 'int' changed the value to -858338538 (32-bit, signed)" from within the CopyDlg ctor). So don't use SetMetricValue to compute the min/max range values. That way, the MetricSpinButton's current value is not set before the computed min/max range values are actually set, so the .ui file doesn't need to contain any static min/max range values. Also, both dialogs call SetFieldUnit, which also sets the MetricSpinButtons' increment values, so those don't need to be set statically in the .ui files, either. Change-Id: I191cfc3837278530e0c3a87e00708c4c76a76361 Reviewed-on: https://gerrit.libreoffice.org/67734 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r--sd/source/ui/dlg/copydlg.cxx5
-rw-r--r--sd/source/ui/dlg/dlgsnap.cxx31
-rw-r--r--sd/uiconfig/sdraw/ui/copydlg.ui28
-rw-r--r--sd/uiconfig/sdraw/ui/dlgsnap.ui14
4 files changed, 14 insertions, 64 deletions
diff --git a/sd/source/ui/dlg/copydlg.cxx b/sd/source/ui/dlg/copydlg.cxx
index afaf7d89c873..9abcb751787f 100644
--- a/sd/source/ui/dlg/copydlg.cxx
+++ b/sd/source/ui/dlg/copydlg.cxx
@@ -94,8 +94,9 @@ void CopyDlg::Reset()
// Set Min/Max values
::tools::Rectangle aRect = mpView->GetAllMarkedRect();
Size aPageSize = mpView->GetSdrPageView()->GetPage()->GetSize();
- SetMetricValue( *m_xMtrFldMoveX, long(1000000 / maUIScale), MapUnit::Map100thMM);
- double fScaleFactor = m_xMtrFldMoveX->get_value(FieldUnit::NONE)/1000000.0;
+ auto const n1 = m_xMtrFldMoveX->normalize(long(1000000 / maUIScale));
+ auto const n2 = m_xMtrFldMoveX->convert_value_from(n1, FieldUnit::MM_100TH);
+ double fScaleFactor = m_xMtrFldMoveX->convert_value_to(n2, FieldUnit::NONE)/1000000.0;
long nPageWidth = aPageSize.Width() * fScaleFactor;
long nPageHeight = aPageSize.Height() * fScaleFactor;
diff --git a/sd/source/ui/dlg/dlgsnap.cxx b/sd/source/ui/dlg/dlgsnap.cxx
index 0401ed7a8596..43f38c37cfac 100644
--- a/sd/source/ui/dlg/dlgsnap.cxx
+++ b/sd/source/ui/dlg/dlgsnap.cxx
@@ -71,26 +71,17 @@ SdSnapLineDlg::SdSnapLineDlg(weld::Window* pWindow, const SfxItemSet& rInAttrs,
// determine max and min values depending on
// WorkArea, PoolUnit and FieldUnit:
- SetMetricValue(*m_xMtrFldX, aLeftTop.X(), ePoolUnit );
-
- int nValue = m_xMtrFldX->get_value(FieldUnit::NONE);
- nValue = sal_Int32(nValue / aUIScale);
- m_xMtrFldX->set_min(nValue, FieldUnit::NONE);
-
- SetMetricValue(*m_xMtrFldX, aRightBottom.X(), ePoolUnit);
- nValue = m_xMtrFldX->get_value(FieldUnit::NONE);
- nValue = sal_Int32(nValue / aUIScale);
- m_xMtrFldX->set_max(nValue, FieldUnit::NONE);
-
- SetMetricValue(*m_xMtrFldY, aLeftTop.Y(), ePoolUnit);
- nValue = m_xMtrFldY->get_value(FieldUnit::NONE);
- nValue = sal_Int32(nValue / aUIScale);
- m_xMtrFldY->set_min(nValue, FieldUnit::NONE);
-
- SetMetricValue(*m_xMtrFldY, aRightBottom.Y(), ePoolUnit);
- nValue = m_xMtrFldY->get_value(FieldUnit::NONE);
- nValue = sal_Int32(nValue / aUIScale);
- m_xMtrFldY->set_max(nValue, FieldUnit::NONE);
+ auto const map = [ePoolUnit](std::unique_ptr<weld::MetricSpinButton> const & msb, long value) {
+ auto const n1 = OutputDevice::LogicToLogic(value, ePoolUnit, MapUnit::Map100thMM);
+ auto const n2 = msb->normalize(n1);
+ auto const n3 = msb->convert_value_from(n2, FieldUnit::MM_100TH);
+ auto const n4 = msb->convert_value_to(n3, FieldUnit::NONE);
+ return n4;
+ };
+ m_xMtrFldX->set_min(map(m_xMtrFldX, aLeftTop.X()), FieldUnit::NONE);
+ m_xMtrFldX->set_max(map(m_xMtrFldX, aRightBottom.X()), FieldUnit::NONE);
+ m_xMtrFldY->set_min(map(m_xMtrFldY, aLeftTop.Y()), FieldUnit::NONE);
+ m_xMtrFldY->set_max(map(m_xMtrFldY, aRightBottom.Y()), FieldUnit::NONE);
// set values
nXValue = static_cast<const SfxInt32Item&>( rInAttrs.Get(ATTR_SNAPLINE_X)).GetValue();
diff --git a/sd/uiconfig/sdraw/ui/copydlg.ui b/sd/uiconfig/sdraw/ui/copydlg.ui
index 31f2a48f0cf9..1bb828ece646 100644
--- a/sd/uiconfig/sdraw/ui/copydlg.ui
+++ b/sd/uiconfig/sdraw/ui/copydlg.ui
@@ -15,30 +15,6 @@
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
- <object class="GtkAdjustment" id="adjustment3">
- <property name="lower">-1000000</property>
- <property name="upper">1000000</property>
- <property name="step_increment">0.10000000000000001</property>
- <property name="page_increment">1</property>
- </object>
- <object class="GtkAdjustment" id="adjustment4">
- <property name="lower">-1000000</property>
- <property name="upper">1000000</property>
- <property name="step_increment">0.10000000000000001</property>
- <property name="page_increment">1</property>
- </object>
- <object class="GtkAdjustment" id="adjustment5">
- <property name="lower">-1000000</property>
- <property name="upper">1000000</property>
- <property name="step_increment">0.10000000000000001</property>
- <property name="page_increment">1</property>
- </object>
- <object class="GtkAdjustment" id="adjustment6">
- <property name="lower">-1000000</property>
- <property name="upper">1000000</property>
- <property name="step_increment">0.10000000000000001</property>
- <property name="page_increment">1</property>
- </object>
<object class="GtkImage" id="image1">
<property name="visible">True</property>
<property name="can_focus">False</property>
@@ -269,7 +245,6 @@
<property name="can_focus">True</property>
<property name="hexpand">True</property>
<property name="activates_default">True</property>
- <property name="adjustment">adjustment3</property>
<property name="digits">2</property>
</object>
<packing>
@@ -283,7 +258,6 @@
<property name="can_focus">True</property>
<property name="hexpand">True</property>
<property name="activates_default">True</property>
- <property name="adjustment">adjustment4</property>
<property name="digits">2</property>
</object>
<packing>
@@ -381,7 +355,6 @@
<property name="can_focus">True</property>
<property name="hexpand">True</property>
<property name="activates_default">True</property>
- <property name="adjustment">adjustment5</property>
<property name="digits">2</property>
</object>
<packing>
@@ -395,7 +368,6 @@
<property name="can_focus">True</property>
<property name="hexpand">True</property>
<property name="activates_default">True</property>
- <property name="adjustment">adjustment6</property>
<property name="digits">2</property>
</object>
<packing>
diff --git a/sd/uiconfig/sdraw/ui/dlgsnap.ui b/sd/uiconfig/sdraw/ui/dlgsnap.ui
index 0bb64dc9e5eb..3a766c1abc0a 100644
--- a/sd/uiconfig/sdraw/ui/dlgsnap.ui
+++ b/sd/uiconfig/sdraw/ui/dlgsnap.ui
@@ -2,18 +2,6 @@
<!-- Generated with glade 3.20.4 -->
<interface domain="sd">
<requires lib="gtk+" version="3.18"/>
- <object class="GtkAdjustment" id="adjustment1">
- <property name="lower">-5000000</property>
- <property name="upper">5000000</property>
- <property name="step_increment">1</property>
- <property name="page_increment">10</property>
- </object>
- <object class="GtkAdjustment" id="adjustment2">
- <property name="lower">-5000000</property>
- <property name="upper">5000000</property>
- <property name="step_increment">1</property>
- <property name="page_increment">10</property>
- </object>
<object class="GtkImage" id="image1">
<property name="visible">True</property>
<property name="can_focus">False</property>
@@ -142,7 +130,6 @@
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="activates_default">True</property>
- <property name="adjustment">adjustment1</property>
<property name="digits">2</property>
</object>
<packing>
@@ -155,7 +142,6 @@
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="activates_default">True</property>
- <property name="adjustment">adjustment2</property>
<property name="digits">2</property>
</object>
<packing>