Kaydet (Commit) bbab991c authored tarafından Stephan Bergmann's avatar Stephan Bergmann Kaydeden (comit) Caolán McNamara

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: 's avatarCaolán McNamara <caolanm@redhat.com>
Tested-by: 's avatarCaolán McNamara <caolanm@redhat.com>
üst 91731a86
......@@ -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;
......
......@@ -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();
......
......@@ -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>
......
......@@ -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>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment