diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2014-03-03 18:27:00 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2014-03-03 18:36:55 +0100 |
commit | b2371492dfd5c8003f89ed8acf3dbc690d6af8d0 (patch) | |
tree | 876a32c415fa06d41a51a2a4a9cc16b1e97bdf76 /sw | |
parent | 768ea2924680fc4beb75a782cb0faf26695fee53 (diff) |
Use cstdlib std::abs instead of stdlib.h abs
...because the latter lacks the abs(long) overload in some popular environments,
cf. <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60401> "stdlib.h does not
provide abs(long) overload."
Similarly, stdlib.h lacks the abs(float), abs(double), abs(long double)
overloads compared to cmath there, whose use was apparently intended in
sw/qa/extras/ooxmlexport/ooxmlsdrexport.cxx. Rewrote that to use
CPPUNIT_ASSERT_DOUBLES_EQUAL instead, which revealed that the comparisons need
rather large deltas of .1 resp. .2 (which the original code hid with an
implicit conversion to integral type, thus using an effective delta of 1).
Discovered with -Wabsolute-value ("absolute value function 'abs' given an
argument of type 'long' but has parameter of type 'int' which may cause
truncation of value") recently introduced on Clang trunk towards 3.5.
Change-Id: I4c41575ffdccb2944498b662bd3a53fd510cb0c0
Diffstat (limited to 'sw')
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlsdrexport.cxx | 8 | ||||
-rw-r--r-- | sw/source/core/doc/docnum.cxx | 3 | ||||
-rw-r--r-- | sw/source/core/docnode/ndtbl.cxx | 7 | ||||
-rw-r--r-- | sw/source/core/table/swnewtable.cxx | 3 | ||||
-rw-r--r-- | sw/source/core/txtnode/fntcache.cxx | 6 | ||||
-rw-r--r-- | sw/source/ui/docvw/SidebarWin.cxx | 6 | ||||
-rw-r--r-- | sw/source/ui/sidebar/PageMarginControl.cxx | 36 | ||||
-rw-r--r-- | sw/source/ui/sidebar/PagePropertyPanel.cxx | 36 |
8 files changed, 62 insertions, 43 deletions
diff --git a/sw/qa/extras/ooxmlexport/ooxmlsdrexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlsdrexport.cxx index 8dc0ef5d85fd..e9ef92837d4a 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlsdrexport.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlsdrexport.cxx @@ -517,22 +517,22 @@ DECLARE_OOXMLEXPORT_TEST(testFdo70838, "fdo70838.docx") if( aStyleCommandName.equals( "margin-left" ) ) { float fValue = aStyleCommandValue.getToken( 0, 'p' ).toFloat(); - CPPUNIT_ASSERT_EQUAL(0, abs(97.6 - fValue)); + CPPUNIT_ASSERT_DOUBLES_EQUAL(97.6, fValue, 0.1); } else if( aStyleCommandName.equals( "margin-top" ) ) { float fValue = aStyleCommandValue.getToken( 0, 'p' ).toFloat(); - CPPUNIT_ASSERT_EQUAL(0, abs(165 - fValue)); + CPPUNIT_ASSERT_DOUBLES_EQUAL(165.0, fValue, 0.2); } else if( aStyleCommandName.equals( "width" ) ) { float fValue = aStyleCommandValue.getToken( 0, 'p' ).toFloat(); - CPPUNIT_ASSERT_EQUAL(0, abs(283.4 - fValue)); + CPPUNIT_ASSERT_DOUBLES_EQUAL(283.4, fValue, 0.1); } else if( aStyleCommandName.equals( "height" ) ) { float fValue = aStyleCommandValue.getToken( 0, 'p' ).toFloat(); - CPPUNIT_ASSERT_EQUAL(0, abs(141.7 - fValue)); + CPPUNIT_ASSERT_DOUBLES_EQUAL(141.7, fValue, 0.1); } } while( nextTokenPos != -1 ); diff --git a/sw/source/core/doc/docnum.cxx b/sw/source/core/doc/docnum.cxx index 79aa45d61e47..05ec96d4aebb 100644 --- a/sw/source/core/doc/docnum.cxx +++ b/sw/source/core/doc/docnum.cxx @@ -52,6 +52,7 @@ #include <switerator.hxx> #include <comphelper/string.hxx> +#include <cstdlib> #include <map> namespace { @@ -1758,7 +1759,7 @@ bool SwDoc::MoveParagraph( const SwPaM& rPam, long nOffset, bool bIsOutlMv ) else { // Impossible to move to negative index - if( sal_uLong(abs( nOffset )) > nStIdx) + if( sal_uLong(std::abs( nOffset )) > nStIdx) return false; nInEndIdx = nStIdx - 1; diff --git a/sw/source/core/docnode/ndtbl.cxx b/sw/source/core/docnode/ndtbl.cxx index 4a7f4e552ebf..4cd0278c30ed 100644 --- a/sw/source/core/docnode/ndtbl.cxx +++ b/sw/source/core/docnode/ndtbl.cxx @@ -79,6 +79,7 @@ #include <unochart.hxx> #include <node.hxx> #include <ndtxt.hxx> +#include <cstdlib> #include <map> #include <algorithm> #include <rootfrm.hxx> @@ -2516,7 +2517,7 @@ struct FuzzyCompare bool FuzzyCompare::operator() ( long s1, long s2 ) const { - return ( s1 < s2 && abs( s1 - s2 ) > ROWFUZZY ); + return ( s1 < s2 && std::abs( s1 - s2 ) > ROWFUZZY ); } static bool lcl_IsFrmInColumn( const SwCellFrm& rFrm, SwSelBoxes& rBoxes ) @@ -2801,7 +2802,7 @@ void SwDoc::SetTabRows( const SwTabCols &rNew, sal_Bool bCurColOnly, const SwCur const long nNewRowHeight = nNewRowEnd - nNewRowStart; const long nDiff = nNewRowHeight - nOldRowHeight; - if ( abs( nDiff ) >= ROWFUZZY ) + if ( std::abs( nDiff ) >= ROWFUZZY ) { // For the old table model pTxtFrm and pLine will be set for every box. // For the new table model pTxtFrm will be set if the box is not covered, @@ -2819,7 +2820,7 @@ void SwDoc::SetTabRows( const SwTabCols &rNew, sal_Bool bCurColOnly, const SwCur { const long nLowerBorder = (pFrm->Frm().*fnRect->fnGetBottom)(); const sal_uLong nTabTop = (pTab->*fnRect->fnGetPrtTop)(); - if ( abs( (*fnRect->fnYInc)( nTabTop, nOldRowEnd ) - nLowerBorder ) <= ROWFUZZY ) + if ( std::abs( (*fnRect->fnYInc)( nTabTop, nOldRowEnd ) - nLowerBorder ) <= ROWFUZZY ) { if ( !bCurColOnly || pFrm == pBoxFrm ) { diff --git a/sw/source/core/table/swnewtable.cxx b/sw/source/core/table/swnewtable.cxx index ff26c7b2aa65..26a445aa8aba 100644 --- a/sw/source/core/table/swnewtable.cxx +++ b/sw/source/core/table/swnewtable.cxx @@ -29,6 +29,7 @@ #include <fmtfsize.hxx> #include <doc.hxx> #include <IDocumentUndoRedo.hxx> +#include <cstdlib> #include <vector> #include <set> #include <list> @@ -2141,7 +2142,7 @@ void SwTable::CheckConsistency() const SAL_WARN_IF( nWidth != nLineWidth, "sw.core", "Different Line Widths: first: " << nLineWidth << " current [" << nCurrLine << "]: " << nWidth); - SAL_WARN_IF( abs(nWidth - nTabSize) > 1 /* how tolerant? */, "sw.core", + SAL_WARN_IF( std::abs(nWidth - nTabSize) > 1 /* how tolerant? */, "sw.core", "Line width differs from table width: " << nTabSize << " current [" << nCurrLine << "]: " << nWidth); SAL_WARN_IF( nWidth < 0 || nWidth > USHRT_MAX, "sw.core", diff --git a/sw/source/core/txtnode/fntcache.cxx b/sw/source/core/txtnode/fntcache.cxx index 78362c372566..3bcbb0886c78 100644 --- a/sw/source/core/txtnode/fntcache.cxx +++ b/sw/source/core/txtnode/fntcache.cxx @@ -17,6 +17,10 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <sal/config.h> + +#include <cstdlib> + #include <i18nlangtag/mslangid.hxx> #include <vcl/outdev.hxx> #include <vcl/print.hxx> @@ -348,7 +352,7 @@ sal_uInt16 SwFntObj::GetFontHeight( const SwViewShell* pSh, const OutputDevice& long nTmpPrtHeight = (sal_uInt16)aOutMet.GetAscent() + aOutMet.GetDescent(); (void) nTmpPrtHeight; // #i106098#: do not compare with == here due to rounding error - OSL_ENSURE( abs(nTmpPrtHeight - nPrtHeight) < 3, + OSL_ENSURE( std::abs(nTmpPrtHeight - nPrtHeight) < 3, "GetTextHeight != Ascent + Descent" ); #endif diff --git a/sw/source/ui/docvw/SidebarWin.cxx b/sw/source/ui/docvw/SidebarWin.cxx index f05fd724c485..503549e159a1 100644 --- a/sw/source/ui/docvw/SidebarWin.cxx +++ b/sw/source/ui/docvw/SidebarWin.cxx @@ -17,6 +17,10 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <sal/config.h> + +#include <cstdlib> + #include <SidebarWin.hxx> #include <SidebarWinAcc.hxx> #include <PostItMgr.hxx> @@ -462,7 +466,7 @@ void SwSidebarWin::SetPosAndSize() DoResize(); } - if (GetPosPixel().X() != mPosSize.TopLeft().X() || (abs(GetPosPixel().Y() - mPosSize.TopLeft().Y()) > 5) ) + if (GetPosPixel().X() != mPosSize.TopLeft().X() || (std::abs(GetPosPixel().Y() - mPosSize.TopLeft().Y()) > 5) ) { bChange = true; SetPosPixel(mPosSize.TopLeft()); diff --git a/sw/source/ui/sidebar/PageMarginControl.cxx b/sw/source/ui/sidebar/PageMarginControl.cxx index 717a18554f9c..dd3d031c8dff 100644 --- a/sw/source/ui/sidebar/PageMarginControl.cxx +++ b/sw/source/ui/sidebar/PageMarginControl.cxx @@ -17,6 +17,10 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <sal/config.h> + +#include <cstdlib> + #include "PageMarginControl.hxx" #include "PagePropertyPanel.hxx" #include "PagePropertyPanel.hrc" @@ -259,34 +263,34 @@ void PageMarginControl::SelectValueSetItem() { const long cTolerance = 5; - if( abs(mnPageLeftMargin - SWPAGE_NARROW_VALUE) <= cTolerance && - abs(mnPageRightMargin - SWPAGE_NARROW_VALUE) <= cTolerance && - abs(mnPageTopMargin - SWPAGE_NARROW_VALUE) <= cTolerance && - abs(mnPageBottomMargin - SWPAGE_NARROW_VALUE) <= cTolerance && + if( std::abs(mnPageLeftMargin - SWPAGE_NARROW_VALUE) <= cTolerance && + std::abs(mnPageRightMargin - SWPAGE_NARROW_VALUE) <= cTolerance && + std::abs(mnPageTopMargin - SWPAGE_NARROW_VALUE) <= cTolerance && + std::abs(mnPageBottomMargin - SWPAGE_NARROW_VALUE) <= cTolerance && !mbMirrored ) { mpMarginValueSet->SelectItem(1); } - else if( abs(mnPageLeftMargin - SWPAGE_NORMAL_VALUE) <= cTolerance && - abs(mnPageRightMargin - SWPAGE_NORMAL_VALUE) <= cTolerance && - abs(mnPageTopMargin - SWPAGE_NORMAL_VALUE) <= cTolerance && - abs(mnPageBottomMargin - SWPAGE_NORMAL_VALUE) <= cTolerance && + else if( std::abs(mnPageLeftMargin - SWPAGE_NORMAL_VALUE) <= cTolerance && + std::abs(mnPageRightMargin - SWPAGE_NORMAL_VALUE) <= cTolerance && + std::abs(mnPageTopMargin - SWPAGE_NORMAL_VALUE) <= cTolerance && + std::abs(mnPageBottomMargin - SWPAGE_NORMAL_VALUE) <= cTolerance && !mbMirrored ) { mpMarginValueSet->SelectItem(2); } - else if( abs(mnPageLeftMargin - SWPAGE_WIDE_VALUE2) <= cTolerance && - abs(mnPageRightMargin - SWPAGE_WIDE_VALUE2) <= cTolerance && - abs(mnPageTopMargin - SWPAGE_WIDE_VALUE1) <= cTolerance && - abs(mnPageBottomMargin - SWPAGE_WIDE_VALUE1) <= cTolerance && + else if( std::abs(mnPageLeftMargin - SWPAGE_WIDE_VALUE2) <= cTolerance && + std::abs(mnPageRightMargin - SWPAGE_WIDE_VALUE2) <= cTolerance && + std::abs(mnPageTopMargin - SWPAGE_WIDE_VALUE1) <= cTolerance && + std::abs(mnPageBottomMargin - SWPAGE_WIDE_VALUE1) <= cTolerance && !mbMirrored ) { mpMarginValueSet->SelectItem(3); } - else if( abs(mnPageLeftMargin - SWPAGE_WIDE_VALUE3) <= cTolerance && - abs(mnPageRightMargin - SWPAGE_WIDE_VALUE1) <= cTolerance && - abs(mnPageTopMargin - SWPAGE_WIDE_VALUE1) <= cTolerance && - abs(mnPageBottomMargin - SWPAGE_WIDE_VALUE1) <= cTolerance && + else if( std::abs(mnPageLeftMargin - SWPAGE_WIDE_VALUE3) <= cTolerance && + std::abs(mnPageRightMargin - SWPAGE_WIDE_VALUE1) <= cTolerance && + std::abs(mnPageTopMargin - SWPAGE_WIDE_VALUE1) <= cTolerance && + std::abs(mnPageBottomMargin - SWPAGE_WIDE_VALUE1) <= cTolerance && mbMirrored ) { mpMarginValueSet->SelectItem(4); diff --git a/sw/source/ui/sidebar/PagePropertyPanel.cxx b/sw/source/ui/sidebar/PagePropertyPanel.cxx index 156a1cb03429..a5d02386cb52 100644 --- a/sw/source/ui/sidebar/PagePropertyPanel.cxx +++ b/sw/source/ui/sidebar/PagePropertyPanel.cxx @@ -17,6 +17,10 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <sal/config.h> + +#include <cstdlib> + #include "PagePropertyPanel.hxx" #include "PagePropertyPanel.hrc" @@ -566,31 +570,31 @@ void PagePropertyPanel::ChangeMarginImage() const long cTolerance = 5; const sal_uInt16 nIdMargin = mpToolBoxMargin->GetItemId(UNO_MARGIN); - if( abs(mpPageLRMarginItem->GetLeft() - SWPAGE_NARROW_VALUE) <= cTolerance && - abs(mpPageLRMarginItem->GetRight() - SWPAGE_NARROW_VALUE) <= cTolerance && - abs(mpPageULMarginItem->GetUpper() - SWPAGE_NARROW_VALUE) <= cTolerance && - abs(mpPageULMarginItem->GetLower() - SWPAGE_NARROW_VALUE) <= cTolerance && + if( std::abs(mpPageLRMarginItem->GetLeft() - SWPAGE_NARROW_VALUE) <= cTolerance && + std::abs(mpPageLRMarginItem->GetRight() - SWPAGE_NARROW_VALUE) <= cTolerance && + std::abs(mpPageULMarginItem->GetUpper() - SWPAGE_NARROW_VALUE) <= cTolerance && + std::abs(mpPageULMarginItem->GetLower() - SWPAGE_NARROW_VALUE) <= cTolerance && mpPageItem->GetPageUsage() != SVX_PAGE_MIRROR ) mpToolBoxMargin->SetItemImage( nIdMargin, mpPageItem->IsLandscape() ? mImgNarrow_L : mImgNarrow ); - else if( abs(mpPageLRMarginItem->GetLeft() - SWPAGE_NORMAL_VALUE) <= cTolerance && - abs(mpPageLRMarginItem->GetRight() - SWPAGE_NORMAL_VALUE) <= cTolerance && - abs(mpPageULMarginItem->GetUpper() - SWPAGE_NORMAL_VALUE) <= cTolerance && - abs(mpPageULMarginItem->GetLower() - SWPAGE_NORMAL_VALUE) <= cTolerance && + else if( std::abs(mpPageLRMarginItem->GetLeft() - SWPAGE_NORMAL_VALUE) <= cTolerance && + std::abs(mpPageLRMarginItem->GetRight() - SWPAGE_NORMAL_VALUE) <= cTolerance && + std::abs(mpPageULMarginItem->GetUpper() - SWPAGE_NORMAL_VALUE) <= cTolerance && + std::abs(mpPageULMarginItem->GetLower() - SWPAGE_NORMAL_VALUE) <= cTolerance && mpPageItem->GetPageUsage() != SVX_PAGE_MIRROR ) mpToolBoxMargin->SetItemImage( nIdMargin, mpPageItem->IsLandscape() ? mImgNormal_L : mImgNormal ); - else if( abs(mpPageLRMarginItem->GetLeft() - SWPAGE_WIDE_VALUE2) <= cTolerance && - abs(mpPageLRMarginItem->GetRight() - SWPAGE_WIDE_VALUE2) <= cTolerance && - abs(mpPageULMarginItem->GetUpper() - SWPAGE_WIDE_VALUE1) <= cTolerance && - abs(mpPageULMarginItem->GetLower() - SWPAGE_WIDE_VALUE1) <= cTolerance && + else if( std::abs(mpPageLRMarginItem->GetLeft() - SWPAGE_WIDE_VALUE2) <= cTolerance && + std::abs(mpPageLRMarginItem->GetRight() - SWPAGE_WIDE_VALUE2) <= cTolerance && + std::abs(mpPageULMarginItem->GetUpper() - SWPAGE_WIDE_VALUE1) <= cTolerance && + std::abs(mpPageULMarginItem->GetLower() - SWPAGE_WIDE_VALUE1) <= cTolerance && mpPageItem->GetPageUsage() != SVX_PAGE_MIRROR ) mpToolBoxMargin->SetItemImage( nIdMargin, mpPageItem->IsLandscape() ? mImgWide_L : mImgWide ); - else if( abs(mpPageLRMarginItem->GetLeft() - SWPAGE_WIDE_VALUE3) <= cTolerance && - abs(mpPageLRMarginItem->GetRight() - SWPAGE_WIDE_VALUE1) <= cTolerance && - abs(mpPageULMarginItem->GetUpper() - SWPAGE_WIDE_VALUE1) <= cTolerance && - abs(mpPageULMarginItem->GetLower() - SWPAGE_WIDE_VALUE1) <= cTolerance && + else if( std::abs(mpPageLRMarginItem->GetLeft() - SWPAGE_WIDE_VALUE3) <= cTolerance && + std::abs(mpPageLRMarginItem->GetRight() - SWPAGE_WIDE_VALUE1) <= cTolerance && + std::abs(mpPageULMarginItem->GetUpper() - SWPAGE_WIDE_VALUE1) <= cTolerance && + std::abs(mpPageULMarginItem->GetLower() - SWPAGE_WIDE_VALUE1) <= cTolerance && mpPageItem->GetPageUsage() == SVX_PAGE_MIRROR ) mpToolBoxMargin->SetItemImage( nIdMargin, mpPageItem->IsLandscape() ? mImgMirrored_L : mImgMirrored ); |