[Libreoffice-commits] core.git: 4 commits - basic/source include/tools

Stephan Bergmann sbergman at redhat.com
Wed May 28 05:34:43 PDT 2014


 basic/source/classes/sbunoobj.cxx |   57 +++++++++++---------------------------
 basic/source/comp/scanner.cxx     |    9 +++---
 basic/source/inc/sbunoobj.hxx     |    7 ++--
 include/tools/resmgr.hxx          |    8 ++---
 4 files changed, 29 insertions(+), 52 deletions(-)

New commits:
commit 480bb72515bf1bae07a0fcc0a8509d7bc0118ab7
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Wed May 28 14:33:34 2014 +0200

    Avoid undefined computation of unaligned pointers to multi-byte objects
    
    Change-Id: Iafca1288e044ab4650b004439027c134e159b45f

diff --git a/include/tools/resmgr.hxx b/include/tools/resmgr.hxx
index 7a49228..cb5d3a3 100644
--- a/include/tools/resmgr.hxx
+++ b/include/tools/resmgr.hxx
@@ -32,10 +32,10 @@ class InternalResMgr;
 struct RSHEADER_TYPE
 {
 private:
-    sal_uInt32              nId;        ///< Identifier of resource
-    RESOURCE_TYPE           nRT;        ///< Resource type
-    sal_uInt32              nGlobOff;   ///< Global offset
-    sal_uInt32              nLocalOff;  ///< Local offset
+    char nId[4];        ///< Identifier of resource
+    char nRT[4];        ///< Resource type
+    char nGlobOff[4];   ///< Global offset
+    char nLocalOff[4];  ///< Local offset
 
 public:
     inline sal_uInt32       GetId();    ///< Identifier of resource
commit 145b64c4eb0a335d4290e998c78ca8280a5004a3
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Wed May 28 14:30:25 2014 +0200

    Avoid undefined signed integer overflow
    
    Change-Id: I3f32ea88dbb34a05baccba49c15b6691d923753e

diff --git a/basic/source/comp/scanner.cxx b/basic/source/comp/scanner.cxx
index fd6ff11..042518d 100644
--- a/basic/source/comp/scanner.cxx
+++ b/basic/source/comp/scanner.cxx
@@ -439,7 +439,7 @@ bool SbiScanner::NextSym()
         bNumber = true;
         // Hex literals are signed Integers ( as defined by basic
         // e.g. -2,147,483,648 through 2,147,483,647 (signed)
-        sal_Int32 l = 0;
+        sal_uInt32 lu = 0;
         int i;
         bool bBufOverflow = false;
         while(nCol < aLine.getLength() &&  theBasicCharClass::get().isAlphaNumeric(aLine[nCol] & 0xFF, bCompatible))
@@ -463,15 +463,16 @@ bool SbiScanner::NextSym()
         {
             i = (*p & 0xFF) - '0';
             if( i > 9 ) i -= 7;
-            l = ( l * base ) + i;
+            lu = ( lu * base ) + i;
             if( !ndig-- )
             {
                 GenError( SbERR_MATH_OVERFLOW ); break;
             }
         }
         if(nCol < aLine.getLength() && aLine[nCol] == '&') ++pLine, ++nCol;
-        nVal = (double) l;
-        eScanType = ( l >= SbxMININT && l <= SbxMAXINT ) ? SbxINTEGER : SbxLONG;
+        sal_Int32 ls = static_cast<sal_Int32>(lu);
+        nVal = (double) ls;
+        eScanType = ( ls >= SbxMININT && ls <= SbxMAXINT ) ? SbxINTEGER : SbxLONG;
         if( bBufOverflow )
             GenError( SbERR_MATH_OVERFLOW );
     }
commit a77a7f608316f647ed8736e9474ff8f4f432f08b
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Wed May 28 14:29:18 2014 +0200

    Fix memory leak
    
    ...by using css::uno::Type instead of a naked typelib_TypeDescription.
    
    Change-Id: I387692265e9e032cb5ed6519739ebb3307db6f28

diff --git a/basic/source/classes/sbunoobj.cxx b/basic/source/classes/sbunoobj.cxx
index 3c4d1b3..d1b52ba 100644
--- a/basic/source/classes/sbunoobj.cxx
+++ b/basic/source/classes/sbunoobj.cxx
@@ -2401,9 +2401,7 @@ SbUnoObject::SbUnoObject( const OUString& aName_, const Any& aUnoObj_ )
             aClassName_ = aUnoObj_.getValueType().getTypeName();
             bSetClassName = true;
         }
-        typelib_TypeDescription * pDeclTD = 0;
-        typelib_typedescription_getByName( &pDeclTD, maTmpUnoObj.getValueTypeName().pData );
-        StructRefInfo aThisStruct( maTmpUnoObj, pDeclTD, 0 );
+        StructRefInfo aThisStruct( maTmpUnoObj, maTmpUnoObj.getValueType(), 0 );
         maStructInfo.reset( new SbUnoStructRefObject( GetName(), aThisStruct ) );
     }
     else if( eType == TypeClass_INTERFACE )
@@ -4776,16 +4774,19 @@ Any StructRefInfo::getValue()
     Any aRet;
     uno_any_destruct(
         &aRet, reinterpret_cast< uno_ReleaseFunc >(cpp_release) );
+    typelib_TypeDescription * pTD = 0;
+    maType.getDescription(&pTD);
     uno_any_construct(
-        &aRet, getInst(), mpTD,
+        &aRet, getInst(), pTD,
                 reinterpret_cast< uno_AcquireFunc >(cpp_acquire) );
+    typelib_typedescription_release(pTD);
     return aRet;
 }
 
 void StructRefInfo::setValue( const Any& rValue )
 {
     uno_type_assignData( getInst(),
-        mpTD->pWeakRef,
+       maType.getTypeLibType(),
        (void*)rValue.getValue(),
        rValue.getValueTypeRef(),
        reinterpret_cast< uno_QueryInterfaceFunc >(cpp_queryInterface),
@@ -4795,12 +4796,7 @@ void StructRefInfo::setValue( const Any& rValue )
 
 OUString StructRefInfo::getTypeName() const
 {
-    OUString sTypeName;
-    if ( mpTD )
-    {
-        sTypeName = mpTD->pTypeName;
-    }
-    return sTypeName;
+    return maType.getTypeName();
 }
 
 void* StructRefInfo::getInst()
@@ -4810,10 +4806,7 @@ void* StructRefInfo::getInst()
 
 TypeClass StructRefInfo::getTypeClass() const
 {
-    TypeClass t = TypeClass_VOID;
-    if ( mpTD )
-        t =  (TypeClass)mpTD->eTypeClass;
-    return t;
+    return maType.getTypeClass();
 }
 
 SbUnoStructRefObject::SbUnoStructRefObject( const OUString& aName_, const StructRefInfo& rMemberInfo ) :  SbxObject( aName_ ), maMemberInfo( rMemberInfo ), mbMemberCacheInit( false )
@@ -4832,7 +4825,8 @@ void SbUnoStructRefObject::initMemberCache()
     if ( mbMemberCacheInit )
         return;
     sal_Int32 nAll = 0;
-    typelib_TypeDescription * pTD = maMemberInfo.getTD();
+    typelib_TypeDescription * pTD = 0;
+    maMemberInfo.getType().getDescription(&pTD);
     typelib_CompoundTypeDescription * pCompTypeDescr = (typelib_CompoundTypeDescription *)pTD;
     for ( ; pCompTypeDescr; pCompTypeDescr = pCompTypeDescr->pBaseTypeDescription )
         nAll += pCompTypeDescr->nMembers;
@@ -4844,17 +4838,11 @@ void SbUnoStructRefObject::initMemberCache()
         sal_Int32 * pMemberOffsets                     = pCompTypeDescr->pMemberOffsets;
         for ( sal_Int32 nPos = pCompTypeDescr->nMembers; nPos--; )
         {
-            typelib_TypeDescription * pMemberTD = 0;
-            TYPELIB_DANGER_GET( &pMemberTD, ppTypeRefs[nPos] );
-            OSL_ENSURE( pMemberTD, "### cannot get field in struct!" );
-            if (pMemberTD)
-            {
-                OUString aName( ppNames[nPos] );
-                TYPELIB_DANGER_RELEASE( pMemberTD );
-                maFields[ aName ] = new StructRefInfo( maMemberInfo.getRootAnyRef(), pMemberTD, maMemberInfo.getPos() + pMemberOffsets[nPos] );
-            }
+            OUString aName( ppNames[nPos] );
+            maFields[ aName ] = new StructRefInfo( maMemberInfo.getRootAnyRef(), ppTypeRefs[nPos], maMemberInfo.getPos() + pMemberOffsets[nPos] );
         }
     }
+    typelib_typedescription_release(pTD);
     mbMemberCacheInit = true;
 }
 
@@ -5093,15 +5081,15 @@ StructRefInfo SbUnoStructRefObject::getStructMember( const OUString& rMemberName
     }
     StructFieldInfo::iterator it = maFields.find( rMemberName );
 
-    typelib_TypeDescription * pFoundTD = NULL;
+    css::uno::Type aFoundType;
     sal_Int32 nFoundPos = -1;
 
     if ( it != maFields.end() )
     {
-        pFoundTD = it->second->getTD();
+        aFoundType = it->second->getType();
         nFoundPos = it->second->getPos();
     }
-    StructRefInfo aRet( maMemberInfo.getRootAnyRef(), pFoundTD, nFoundPos );
+    StructRefInfo aRet( maMemberInfo.getRootAnyRef(), aFoundType, nFoundPos );
     return aRet;
 }
 
diff --git a/basic/source/inc/sbunoobj.hxx b/basic/source/inc/sbunoobj.hxx
index 84b2669..29033ff 100644
--- a/basic/source/inc/sbunoobj.hxx
+++ b/basic/source/inc/sbunoobj.hxx
@@ -40,15 +40,14 @@
 
 class StructRefInfo
 {
-    StructRefInfo();
     com::sun::star::uno::Any& maAny;
-    typelib_TypeDescription* mpTD;
+    css::uno::Type maType;
     sal_Int32 mnPos;
 public:
-    StructRefInfo( com::sun::star::uno::Any& aAny, typelib_TypeDescription* pTD, sal_Int32 nPos ) : maAny( aAny ), mpTD( pTD ), mnPos( nPos ) {}
+    StructRefInfo( com::sun::star::uno::Any& aAny, css::uno::Type const & rType, sal_Int32 nPos ) : maAny( aAny ), maType( rType ), mnPos( nPos ) {}
 
     sal_Int32 getPos() const { return mnPos; }
-    typelib_TypeDescription* getTD() const { return mpTD; }
+    css::uno::Type getType() const { return maType; }
     OUString getTypeName() const;
     com::sun::star::uno::Any& getRootAnyRef() { return maAny; };
 
commit b8a329989cead1db2e4b11ee41368010e55a7ce8
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Wed May 28 14:23:17 2014 +0200

    Fix memory leak (missing typelib_TypeDescription_release)
    
    ...by radically simplifying TypeToIdlClass().  It is unclear to me why this was
    so complicated.  The only mildly plausible reaons would be that the old code
    was careful to return null instead of throwing an exception for an unknown type,
    but the TypeToIdlClass-call-sites either strongly expect a non-null return value
    (by dereferencing it without any further checking) or use OSL_ASSERT or similar
    to verify it.  So lets hope this is good.
    
    Change-Id: I3e24eb6117e84c9d33f4c5f0e2fa88da4c4f2c30

diff --git a/basic/source/classes/sbunoobj.cxx b/basic/source/classes/sbunoobj.cxx
index 7e5dcfd..3c4d1b3 100644
--- a/basic/source/classes/sbunoobj.cxx
+++ b/basic/source/classes/sbunoobj.cxx
@@ -368,18 +368,7 @@ TYPEINIT1(SbUnoAnyObject,SbxObject)
 // TODO: source out later
 Reference<XIdlClass> TypeToIdlClass( const Type& rType )
 {
-    // register void as default class
-    Reference<XIdlClass> xRetClass;
-    typelib_TypeDescription * pTD = 0;
-    rType.getDescription( &pTD );
-
-    if( pTD )
-    {
-        OUString sOWName( pTD->pTypeName );
-        Reference< XIdlReflection > xRefl = getCoreReflection_Impl();
-        xRetClass = xRefl->forName( sOWName );
-    }
-    return xRetClass;
+    return getCoreReflection_Impl()->forName(rType.getTypeName());
 }
 
 // Exception type unknown


More information about the Libreoffice-commits mailing list