[Libreoffice-commits] core.git: 3 commits - include/sal sal/qa sal/rtl
Stephan Bergmann
sbergman at redhat.com
Thu May 22 09:37:12 PDT 2014
include/sal/types.h | 6 ++++--
sal/qa/inc/valueequal.hxx | 8 ++++++++
sal/qa/rtl/oustring/rtl_OUString2.cxx | 20 ++++++++++++++++++--
sal/rtl/ustring.cxx | 19 +++++++++++++++++--
4 files changed, 47 insertions(+), 6 deletions(-)
New commits:
commit 9adad0d1eae6e3d54042ab1e65f0b80a77562dc6
Author: Stephan Bergmann <sbergman at redhat.com>
Date: Thu May 22 18:36:31 2014 +0200
Avoid undef use of null ptr, use offsetof instead
Change-Id: I095f45b537690fe98bf385d99194db6319d7ac93
diff --git a/include/sal/types.h b/include/sal/types.h
index 5a534b8..c19673a 100644
--- a/include/sal/types.h
+++ b/include/sal/types.h
@@ -21,8 +21,10 @@
#define INCLUDED_SAL_TYPES_H
#include <sal/config.h>
-#include <sal/macros.h>
+#include <stddef.h>
+
+#include <sal/macros.h>
#include <sal/typesizes.h>
#ifdef __cplusplus
@@ -337,7 +339,7 @@ typedef struct _sal_Sequence
char elements[1];
} sal_Sequence;
-#define SAL_SEQUENCE_HEADER_SIZE ((sal_Size)&((sal_Sequence *)0)->elements)
+#define SAL_SEQUENCE_HEADER_SIZE ((sal_Size) offsetof(sal_Sequence,elements))
#if defined( SAL_W32)
#pragma pack(pop)
commit b5cb4935c268f12e63b61e035b455b0a59e67aa2
Author: Stephan Bergmann <sbergman at redhat.com>
Date: Thu May 22 18:31:07 2014 +0200
Work around undef conversion of large double to float
...as flagged by -fsanitize=undefined. But is it really undefined?
[conv.double] "If the source value is between two adjacent destination values,
the result of the conversion is an implementation-defined choice of either of
those values." So if the double is between std::numeric_limits<float>::max()
and std::numeric_limits<float>::infinity()...
Change-Id: I6389c8ac4a922991e240638d231dd2a39e173882
diff --git a/sal/qa/rtl/oustring/rtl_OUString2.cxx b/sal/qa/rtl/oustring/rtl_OUString2.cxx
index 849c521..27a06ab 100644
--- a/sal/qa/rtl/oustring/rtl_OUString2.cxx
+++ b/sal/qa/rtl/oustring/rtl_OUString2.cxx
@@ -23,6 +23,7 @@
#include <stdio.h>
#include <algorithm>
+#include <limits>
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
@@ -34,6 +35,21 @@
namespace rtl_OUString
{
+namespace {
+
+// Avoid -fsanitize=undefined warning e.g. "runtime error: value 1e+99 is
+// outside the range of representable values of type 'float'":
+float doubleToFloat(double x) {
+ return
+ x < -std::numeric_limits<float>::max()
+ ? -std::numeric_limits<float>::infinity()
+ : x > std::numeric_limits<float>::max()
+ ? std::numeric_limits<float>::infinity()
+ : static_cast<float>(x);
+}
+
+}
+
class number : public CppUnit::TestFixture
{
void number_float_test_impl(float _nValue)
@@ -43,7 +59,7 @@ class number : public CppUnit::TestFixture
sValue <<= suValue;
printf("nFloat := %.9f sValue := %s\n", _nValue, sValue.getStr());
- float nValueATOF = static_cast<float>(atof( sValue.getStr() ));
+ double nValueATOF = doubleToFloat(atof( sValue.getStr() ));
bool bEqualResult = is_float_equal(_nValue, nValueATOF);
CPPUNIT_ASSERT_MESSAGE("Values are not equal.", bEqualResult == true);
@@ -439,7 +455,7 @@ sal_Int16 SAL_CALL checkPrecisionSize()
void toFloat_test_impl(rtl::OString const& _sValue)
{
//printf("the original str is %s\n", _sValue.getStr());
- float nValueATOF = static_cast<float>(atof( _sValue.getStr() ));
+ float nValueATOF = doubleToFloat(atof( _sValue.getStr() ));
//printf("the original str is %.10f\n", nValueATOF);
rtl::OUString suValue = rtl::OUString::createFromAscii( _sValue.getStr() );
float nValueToFloat = suValue.toFloat();
diff --git a/sal/rtl/ustring.cxx b/sal/rtl/ustring.cxx
index f10e755..a79c917 100644
--- a/sal/rtl/ustring.cxx
+++ b/sal/rtl/ustring.cxx
@@ -148,11 +148,26 @@ sal_Int32 SAL_CALL rtl_ustr_valueOfDouble(sal_Unicode * pStr, double d)
return nLen;
}
+namespace {
+
+// Avoid -fsanitize=undefined warning e.g. "runtime error: value 1e+99 is
+// outside the range of representable values of type 'float'":
+float doubleToFloat(double x) {
+ return
+ x < -std::numeric_limits<float>::max()
+ ? -std::numeric_limits<float>::infinity()
+ : x > std::numeric_limits<float>::max()
+ ? std::numeric_limits<float>::infinity()
+ : static_cast<float>(x);
+}
+
+}
+
float SAL_CALL rtl_ustr_toFloat(sal_Unicode const * pStr) SAL_THROW_EXTERN_C()
{
- return (float) rtl_math_uStringToDouble(pStr,
+ return doubleToFloat(rtl_math_uStringToDouble(pStr,
pStr + rtl_ustr_getLength(pStr),
- '.', 0, 0, 0);
+ '.', 0, 0, 0));
}
double SAL_CALL rtl_ustr_toDouble(sal_Unicode const * pStr) SAL_THROW_EXTERN_C()
commit 4330085f141327ee494bb541d4f2f291dd1c590b
Author: Stephan Bergmann <sbergman at redhat.com>
Date: Thu May 22 18:29:35 2014 +0200
Avoid undef conversion from log10(INF) = INF to sal_Int32
Change-Id: Iffe85763097829cb04b766314077b5f2a9b5b8d5
diff --git a/sal/qa/inc/valueequal.hxx b/sal/qa/inc/valueequal.hxx
index 2f39594..563314d 100644
--- a/sal/qa/inc/valueequal.hxx
+++ b/sal/qa/inc/valueequal.hxx
@@ -17,8 +17,12 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
+#include <sal/config.h>
+
#include <math.h>
+#include <sal/mathconf.h>
+
#define PREC_float 1
#define PREC_double 2
#define PREC_long_double 3
@@ -26,6 +30,10 @@
template<class T>
bool is_equal(T x, T y, sal_Int16 _nPrec)
{
+ if (!(SAL_MATH_FINITE(x) && SAL_MATH_FINITE(y))) {
+ return x == y;
+ }
+
// due to the fact that this check looks only if both values are equal
// we only need to look on one value
More information about the Libreoffice-commits
mailing list