idlc/inc/idlc/aststruct.hxx | 8 +++--- idlc/source/aststruct.cxx | 6 ++-- idlc/source/parser.y | 4 +-- l10ntools/source/xmlparse.cxx | 6 ++-- sal/rtl/strtmpl.cxx | 51 +++++++++++++++++++++--------------------- solenv/bin/concat-deps.c | 24 ------------------- soltools/cpp/cpp.h | 4 +-- 7 files changed, 40 insertions(+), 63 deletions(-)
New commits: commit 8b5dc58a3e36370c7469e341ac0400cebd7e131c Author: Stephan Bergmann <sberg...@redhat.com> Date: Wed Aug 14 16:08:42 2013 +0200 Misaligned access is always undefined behavior ...as flagged by Clang -fsanitize=undefined Change-Id: I924439b1546832ebc37b87d88279822b9b7b6c0d diff --git a/solenv/bin/concat-deps.c b/solenv/bin/concat-deps.c index b305d1a..f0147c8 100644 --- a/solenv/bin/concat-deps.c +++ b/solenv/bin/concat-deps.c @@ -16,25 +16,21 @@ #ifdef __x86_64__ #undef CORE_BIG_ENDIAN #define CORE_LITTLE_ENDIAN -#define USE_MEMORY_ALIGNMENT 64 /* big value -> no alignment */ #else #define CORE_BIG_ENDIAN #undef CORE_LITTLE_ENDIAN -#define USE_MEMORY_ALIGNMENT 4 #endif #endif #ifdef _AIX #define CORE_BIG_ENDIAN #undef CORE_LITTLE_ENDIAN -#define USE_MEMORY_ALIGNMENT 4 #endif /* Def _AIX */ #ifdef _MSC_VER #define __windows #undef CORE_BIG_ENDIAN #define CORE_LITTLE_ENDIAN -#define USE_MEMORY_ALIGNMENT 64 /* big value -> no alignment */ #endif /* Def _MSC_VER */ #if defined(__linux) || defined(__OpenBSD__) || \ @@ -44,16 +40,10 @@ #if __BYTE_ORDER == __LITTLE_ENDIAN #undef CORE_BIG_ENDIAN #define CORE_LITTLE_ENDIAN -#if defined(__x86_64) || defined(__i386) -#define USE_MEMORY_ALIGNMENT 64 -#else -#define USE_MEMORY_ALIGNMENT 4 -#endif #else /* !(__BYTE_ORDER == __LITTLE_ENDIAN) */ #if __BYTE_ORDER == __BIG_ENDIAN #define CORE_BIG_ENDIAN #undef CORE_LITTLE_ENDIAN -#define USE_MEMORY_ALIGNMENT 4 #endif /* __BYTE_ORDER == __BIG_ENDIAN */ #endif /* !(__BYTE_ORDER == __LITTLE_ENDIAN) */ #endif /* Def __linux || Def *BSD */ @@ -62,22 +52,12 @@ #ifdef __sparc #define CORE_BIG_ENDIAN #undef CORE_LITTLE_ENDIAN -#define USE_MEMORY_ALIGNMENT 4 #else /* Ndef __sparc */ #undef CORE_BIG_ENDIAN #define CORE_LITTLE_ENDIAN -#define USE_MEMORY_ALIGNMENT 4 #endif /* Ndef __sparc */ #endif /* Def __sun */ -/* Note USE_MEMORY_ALIGNMENT is 4 for platform that allow short non-aligned but required int access to be aligned (e.g sparc, ppc, zos..) - * USE_MEMORY_ALIGNMENT is 2 for platform that require short and int access to be aligned (e.g hppa ) - * if the platform does not have alignment requirement (x86/amd64) use a big value (i.e > 16) - */ -#ifndef USE_MEMORY_ALIGNMENT -#error "USE_MEMORY_ALIGNMENT must be defined to the proper alignment value for the platform" -#endif - #include <assert.h> #include <stdio.h> #include <stdlib.h> @@ -136,9 +116,6 @@ int result = 32; } #endif -#if (USE_MEMORY_ALIGNMENT > 4) -#define get_unaligned_uint(str) (*(unsigned int*)(str)) -#else static inline unsigned int get_unaligned_uint(const unsigned char* cursor) { unsigned int result; @@ -146,7 +123,6 @@ unsigned int result; memcpy(&result, cursor, sizeof(unsigned int)); return result; } -#endif /* =============================================== * memory pool for fast fix-size allocation (non-tread-safe) commit 76d5f993e53d4cd7cdbc16e318f36b58c17ed33b Author: Stephan Bergmann <sberg...@redhat.com> Date: Wed Aug 14 16:06:36 2013 +0200 downcast of address which does not point to an object of type 'XMLParentNode' (note: object is of type 'XMLDefault'); Clang -fsanitize=undefined Change-Id: Idaa1e30068c389ed57977d40fc90410ec9ff3665 diff --git a/l10ntools/source/xmlparse.cxx b/l10ntools/source/xmlparse.cxx index 40550bc..4203050 100644 --- a/l10ntools/source/xmlparse.cxx +++ b/l10ntools/source/xmlparse.cxx @@ -447,11 +447,11 @@ void XMLFile::SearchL10NElements( XMLParentNode *pCur , int pos) else { switch( pCur->GetNodeType()) { case XML_NODE_TYPE_FILE: { - XMLParentNode* pElement; + XMLChildNode* pElement; if( GetChildList()){ for ( size_t i = 0; i < GetChildList()->size(); i++ ){ - pElement = (XMLParentNode*) (*GetChildList())[ i ]; - if( pElement->GetNodeType() == XML_NODE_TYPE_ELEMENT ) SearchL10NElements( pElement , i); + pElement = (*GetChildList())[ i ]; + if( pElement->GetNodeType() == XML_NODE_TYPE_ELEMENT ) SearchL10NElements( (XMLParentNode*) pElement , i); } } } commit 4ef1f4ae499cbac7e85b03abff5c2bb31c68b90f Author: Stephan Bergmann <sberg...@redhat.com> Date: Wed Aug 14 16:05:07 2013 +0200 downcast of address which does not point to an object of type 'AstInterface' (note: object is of type 'AstTypeDef'); Clang -fsanitize=undefined Change-Id: I1b11a7678f18557c8040af2118c1c0101913f086 diff --git a/idlc/inc/idlc/aststruct.hxx b/idlc/inc/idlc/aststruct.hxx index 837bbaf..e13229c 100644 --- a/idlc/inc/idlc/aststruct.hxx +++ b/idlc/inc/idlc/aststruct.hxx @@ -33,15 +33,15 @@ public: AstStruct( const OString& name, std::vector< OString > const & typeParameters, - AstStruct* pBaseType, AstScope* pScope); + AstStruct const* pBaseType, AstScope* pScope); AstStruct(const NodeType type, const OString& name, - AstStruct* pBaseType, + AstStruct const* pBaseType, AstScope* pScope); virtual ~AstStruct(); - AstStruct* getBaseType() + AstStruct const* getBaseType() { return m_pBaseType; } DeclList::size_type getTypeParameterCount() const @@ -53,7 +53,7 @@ public: virtual sal_Bool dump(RegistryKey& rKey); private: - AstStruct* m_pBaseType; + AstStruct const* m_pBaseType; DeclList m_typeParameters; }; diff --git a/idlc/source/aststruct.cxx b/idlc/source/aststruct.cxx index fff256a..d60026a 100644 --- a/idlc/source/aststruct.cxx +++ b/idlc/source/aststruct.cxx @@ -27,7 +27,7 @@ using namespace ::rtl; AstStruct::AstStruct( const OString& name, std::vector< OString > const & typeParameters, - AstStruct* pBaseType, AstScope* pScope) + AstStruct const* pBaseType, AstScope* pScope) : AstType(NT_struct, name, pScope) , AstScope(NT_struct) , m_pBaseType(pBaseType) @@ -42,7 +42,7 @@ AstStruct::AstStruct( AstStruct::AstStruct(const NodeType type, const OString& name, - AstStruct* pBaseType, + AstStruct const* pBaseType, AstScope* pScope) : AstType(type, name, pScope) , AstScope(type) diff --git a/idlc/source/parser.y b/idlc/source/parser.y index 7bfdea2..c149219 100644 --- a/idlc/source/parser.y +++ b/idlc/source/parser.y @@ -582,7 +582,7 @@ interface_dcl : { pInterface = new AstInterface( *$1->getName(), - static_cast< AstInterface * >($1->getInherits()), pScope); + static_cast< AstInterface const * >(resolveTypedefs($1->getInherits())), pScope); if ( pInterface && (pDecl = pScope->lookupByName(pInterface->getScopedName())) ) { @@ -2586,7 +2586,7 @@ struct_type : if ( pScope ) { - AstStruct* pBase= static_cast< AstStruct* >($1->getInherits()); + AstStruct const* pBase= static_cast< AstStruct const* >(resolveTypedefs($1->getInherits())); pStruct = new AstStruct( *$1->getName(), $1->getTypeParameters(), pBase, pScope); pScope->addDeclaration(pStruct); commit d239ee4fa43c3936aceff343085bd2c74c25605c Author: Stephan Bergmann <sberg...@redhat.com> Date: Wed Aug 14 16:02:04 2013 +0200 downcast of address which does not point to an object of type 'AstType' (note: object is of type 'AstDeclaration'); Clang -fsanitize=undefined Change-Id: I08eef7d3e8b298abd16b0c6d72cfb72b75190cd5 diff --git a/idlc/source/aststruct.cxx b/idlc/source/aststruct.cxx index 7f64556..fff256a 100644 --- a/idlc/source/aststruct.cxx +++ b/idlc/source/aststruct.cxx @@ -36,7 +36,7 @@ AstStruct::AstStruct( i != typeParameters.end(); ++i) { m_typeParameters.push_back( - new AstDeclaration(NT_type_parameter, *i, 0)); + new AstType(NT_type_parameter, *i, 0)); } } commit e771d9248dfed643b4737d6a37af21b460bdf949 Author: Stephan Bergmann <sberg...@redhat.com> Date: Wed Aug 14 15:57:47 2013 +0200 Various undefined behavior involving signed integers as flagged by Clang -fsanitize=undefined Change-Id: Iff1aa4473d960009890b923fba734257ecd8b3ef diff --git a/sal/rtl/strtmpl.cxx b/sal/rtl/strtmpl.cxx index dc54945..496216f 100644 --- a/sal/rtl/strtmpl.cxx +++ b/sal/rtl/strtmpl.cxx @@ -22,9 +22,11 @@ /* String-Class */ /* ======================================================================= */ +#include <cassert> +#include <limits> + #include <string.h> #include <sal/log.hxx> -#include <limits> #include <boost/static_assert.hpp> /* @@ -278,13 +280,13 @@ sal_Int32 SAL_CALL IMPL_RTL_STRNAME( hashCode_WithLength )( const IMPL_RTL_STRCO sal_Int32 nLen ) SAL_THROW_EXTERN_C() { - sal_Int32 h = nLen; + sal_uInt32 h = static_cast<sal_uInt32>(nLen); if ( nLen < 256 ) { while ( nLen > 0 ) { - h = (h*37) + IMPL_RTL_USTRCODE( *pStr ); + h = (h*37U) + IMPL_RTL_USTRCODE( *pStr ); pStr++; nLen--; } @@ -296,34 +298,34 @@ sal_Int32 SAL_CALL IMPL_RTL_STRNAME( hashCode_WithLength )( const IMPL_RTL_STRCO /* only sample some characters */ /* the first 3, some characters between, and the last 5 */ - h = (h*39) + IMPL_RTL_USTRCODE( *pStr ); + h = (h*39U) + IMPL_RTL_USTRCODE( *pStr ); pStr++; - h = (h*39) + IMPL_RTL_USTRCODE( *pStr ); + h = (h*39U) + IMPL_RTL_USTRCODE( *pStr ); pStr++; - h = (h*39) + IMPL_RTL_USTRCODE( *pStr ); + h = (h*39U) + IMPL_RTL_USTRCODE( *pStr ); pStr++; nSkip = nLen / 8; nLen -= 8; while ( nLen > 0 ) { - h = (h*39) + IMPL_RTL_USTRCODE( *pStr ); + h = (h*39U) + IMPL_RTL_USTRCODE( *pStr ); pStr += nSkip; nLen -= nSkip; } - h = (h*39) + IMPL_RTL_USTRCODE( *pEndStr ); + h = (h*39U) + IMPL_RTL_USTRCODE( *pEndStr ); pEndStr++; - h = (h*39) + IMPL_RTL_USTRCODE( *pEndStr ); + h = (h*39U) + IMPL_RTL_USTRCODE( *pEndStr ); pEndStr++; - h = (h*39) + IMPL_RTL_USTRCODE( *pEndStr ); + h = (h*39U) + IMPL_RTL_USTRCODE( *pEndStr ); pEndStr++; - h = (h*39) + IMPL_RTL_USTRCODE( *pEndStr ); + h = (h*39U) + IMPL_RTL_USTRCODE( *pEndStr ); pEndStr++; - h = (h*39) + IMPL_RTL_USTRCODE( *pEndStr ); + h = (h*39U) + IMPL_RTL_USTRCODE( *pEndStr ); } - return h; + return static_cast<sal_Int32>(h); } /* ----------------------------------------------------------------------- */ @@ -752,8 +754,7 @@ sal_Int32 SAL_CALL IMPL_RTL_STRNAME( valueOfInt32 )( IMPL_RTL_STRCODE* pStr, *pStr = '-'; pStr++; nLen++; - nValue = -n; /* FIXME this code is not portable for n == -2147483648 - (smallest negative value for sal_Int32) */ + nValue = n == SAL_MIN_INT32 ? static_cast<sal_uInt32>(n) : -n; } else nValue = n; @@ -807,9 +808,7 @@ sal_Int32 SAL_CALL IMPL_RTL_STRNAME( valueOfInt64 )( IMPL_RTL_STRCODE* pStr, *pStr = '-'; pStr++; nLen++; - nValue = -n; /* FIXME this code is not portable for - n == -9223372036854775808 (smallest negative value for - sal_Int64) */ + nValue = n == SAL_MIN_INT64 ? static_cast<sal_uInt64>(n) : -n; } else nValue = n; @@ -914,13 +913,13 @@ sal_Bool SAL_CALL IMPL_RTL_STRNAME( toBoolean )( const IMPL_RTL_STRCODE* pStr ) /* ----------------------------------------------------------------------- */ namespace { - template <typename T> static inline T IMPL_RTL_STRNAME( toInt )( const IMPL_RTL_STRCODE* pStr, + template<typename T, typename U> static inline T IMPL_RTL_STRNAME( toInt )( const IMPL_RTL_STRCODE* pStr, sal_Int16 nRadix ) { BOOST_STATIC_ASSERT(std::numeric_limits<T>::is_signed); sal_Bool bNeg; sal_Int16 nDigit; - T n = 0; + U n = 0; if ( (nRadix < RTL_STR_MIN_RADIX) || (nRadix > RTL_STR_MAX_RADIX) ) nRadix = 10; @@ -968,7 +967,8 @@ namespace { nDigit = rtl_ImplGetDigit( IMPL_RTL_USTRCODE( *pStr ), nRadix ); if ( nDigit < 0 ) break; - if( ( nMod < nDigit ? nDiv-1 : nDiv ) < n ) + assert(nDiv > 0); + if( static_cast<U>( nMod < nDigit ? nDiv-1 : nDiv ) < n ) return 0; n *= nRadix; @@ -978,9 +978,10 @@ namespace { } if ( bNeg ) - return -n; + return n == static_cast<U>(std::numeric_limits<T>::min()) + ? std::numeric_limits<T>::min() : -static_cast<T>(n); else - return n; + return static_cast<T>(n); } } @@ -988,14 +989,14 @@ sal_Int32 SAL_CALL IMPL_RTL_STRNAME( toInt32 )( const IMPL_RTL_STRCODE* pStr, sal_Int16 nRadix ) SAL_THROW_EXTERN_C() { - return IMPL_RTL_STRNAME( toInt )<sal_Int32>(pStr, nRadix); + return IMPL_RTL_STRNAME( toInt )<sal_Int32, sal_uInt32>(pStr, nRadix); } sal_Int64 SAL_CALL IMPL_RTL_STRNAME( toInt64 )( const IMPL_RTL_STRCODE* pStr, sal_Int16 nRadix ) SAL_THROW_EXTERN_C() { - return IMPL_RTL_STRNAME( toInt )<sal_Int64>(pStr, nRadix); + return IMPL_RTL_STRNAME( toInt )<sal_Int64, sal_uInt64>(pStr, nRadix); } /* ----------------------------------------------------------------------- */ commit 376feb6a6fcd32887b50fba790a3230baf3dae98 Author: Stephan Bergmann <sberg...@redhat.com> Date: Wed Aug 14 15:54:46 2013 +0200 left shift of 1 by 31 places cannot be represented in type 'int' Clang -fsanitize=undefined Change-Id: I2b3f1bd28e098d5eb57892d2c7438c18c5c3b357 diff --git a/soltools/cpp/cpp.h b/soltools/cpp/cpp.h index 29a77ee..15c2e60 100644 --- a/soltools/cpp/cpp.h +++ b/soltools/cpp/cpp.h @@ -127,8 +127,8 @@ typedef struct wraplist } Wraplist; #define new(t) (t *)domalloc(sizeof(t)) -#define quicklook(a,b) (namebit[(a)&077] & (1<<((b)&037))) -#define quickset(a,b) namebit[(a)&077] |= (1<<((b)&037)) +#define quicklook(a,b) (namebit[(a)&077] & (1U<<((b)&037))) +#define quickset(a,b) namebit[(a)&077] |= (1U<<((b)&037)) extern unsigned long namebit[077 + 1]; enum errtype _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits