Hello, Here is a patch for cppcheck cleaning in vcl Compiling was ok.
I'm not sure if what I did about realloc pb in the file : vcl/unx/source/gdi/xlfd_attr.cxx was sufficient (even correct !). In general in LO for memory problem, what is recommended ? Julien (LGPLv3+ / MPL)
commit 455bfe6d11844e4de5f89dfcec878c5ed4b27a6a Author: Julien Nabet <[email protected]> Date: Thu Dec 30 18:36:12 2010 +0100 cppcheck cleaning part1 diff --git a/vcl/unx/kde/salnativewidgets-kde.cxx b/vcl/unx/kde/salnativewidgets-kde.cxx index c15e617..010ba59 100644 --- a/vcl/unx/kde/salnativewidgets-kde.cxx +++ b/vcl/unx/kde/salnativewidgets-kde.cxx @@ -394,7 +394,11 @@ WidgetPainter::WidgetPainter( void ) m_pToolBarVert( NULL ), m_pToolButton( NULL ), m_pMenuBar( NULL ), + m_nMenuBarEnabledItem( 0 ), + m_nMenuBarDisabledItem( 0 ), m_pPopupMenu( NULL ), + m_nPopupMenuEnabledItem( 0 ), + m_nPopupMenuDisabledItem( 0 ), m_pProgressBar( NULL ) { } diff --git a/vcl/unx/source/fontmanager/fontmanager.cxx b/vcl/unx/source/fontmanager/fontmanager.cxx index c226a99..640648f 100644 --- a/vcl/unx/source/fontmanager/fontmanager.cxx +++ b/vcl/unx/source/fontmanager/fontmanager.cxx @@ -755,7 +755,6 @@ bool PrintFontManager::PrintFont::readAfmMetrics( const OString& rFileName, Mult { PrintFontManager& rManager( PrintFontManager::get() ); - int i; FontInfo* pInfo = NULL; parseFile( rFileName.getStr(), &pInfo, P_ALL ); if( ! pInfo || ! pInfo->numOfChars ) @@ -969,6 +968,7 @@ bool PrintFontManager::PrintFont::readAfmMetrics( const OString& rFileName, Mult // note: this only works with single byte encodings sal_Unicode* pUnicodes = (sal_Unicode*)alloca( pInfo->numOfChars * sizeof(sal_Unicode)); CharMetricInfo* pChar = pInfo->cmi; + int i; for( i = 0; i < pInfo->numOfChars; i++, pChar++ ) { diff --git a/vcl/unx/source/fontmanager/parseAFM.cxx b/vcl/unx/source/fontmanager/parseAFM.cxx index bc35b29..2076b74 100644 --- a/vcl/unx/source/fontmanager/parseAFM.cxx +++ b/vcl/unx/source/fontmanager/parseAFM.cxx @@ -1421,7 +1421,7 @@ int parseFile( const char* pFilename, FontInfo** fi, FLAGS flags) void freeFontInfo (FontInfo *fi) { - int i, j; + int i; if (fi->gfi) { @@ -1475,6 +1475,7 @@ freeFontInfo (FontInfo *fi) for (i = 0; i < fi->numOfComps; i++) { free (fi->ccd[i].ccName); + int j; for (j = 0; j < fi->ccd[i].numOfPieces; j++) free (fi->ccd[i].pieces[j].pccName); diff --git a/vcl/unx/source/gdi/cdeint.cxx b/vcl/unx/source/gdi/cdeint.cxx index a1b43fe..e18554a 100644 --- a/vcl/unx/source/gdi/cdeint.cxx +++ b/vcl/unx/source/gdi/cdeint.cxx @@ -73,7 +73,6 @@ void CDEIntegrator::GetSystemLook( AllSettings& rSettings ) int nStringCount; XTextProperty aTextProperty; aTextProperty.value = 0; - int i; static Atom nResMgrAtom = XInternAtom( mpDisplay, "RESOURCE_MANAGER", False ); @@ -89,6 +88,7 @@ void CDEIntegrator::GetSystemLook( AllSettings& rSettings ) // *n*ColorPalette: palettefile ByteString aLines; + int i; for( i=0; i < nStringCount; i++ ) aLines += ppStringList[i]; for( i = aLines.GetTokenCount( '\n' )-1; i >= 0; i-- ) diff --git a/vcl/unx/source/gdi/salbmp.cxx b/vcl/unx/source/gdi/salbmp.cxx index 1dadfdb..59a9d64 100644 --- a/vcl/unx/source/gdi/salbmp.cxx +++ b/vcl/unx/source/gdi/salbmp.cxx @@ -783,11 +783,11 @@ bool X11SalBitmap::Create( const ::com::sun::star::uno::Reference< ::com::sun::s { ::com::sun::star::uno::Reference< ::com::sun::star::beans::XFastPropertySet > xFastPropertySet( xBitmapCanvas, ::com::sun::star::uno::UNO_QUERY ); if( xFastPropertySet.get() ) { - long pixmapHandle; sal_Int32 depth; ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > args; if( xFastPropertySet->getFastPropertyValue(bMask ? 2 : 1) >>= args ) { + long pixmapHandle; if( ( args[1] >>= pixmapHandle ) && ( args[2] >>= depth ) ) { mbGrey = bMask; diff --git a/vcl/unx/source/gdi/xlfd_attr.cxx b/vcl/unx/source/gdi/xlfd_attr.cxx index 787832e..a122b4e 100644 --- a/vcl/unx/source/gdi/xlfd_attr.cxx +++ b/vcl/unx/source/gdi/xlfd_attr.cxx @@ -541,8 +541,19 @@ AttributeStorage::Enlarge() } else { + int mnSizetemp = mnSize; mnSize = mnSize < 32768 ? (mnSize * 2) : 65535; - mpList = (Attribute*) realloc( mpList, mnSize * sizeof(Attribute) ); + Attribute* pTemp; + //mpList = (Attribute*) realloc( mpList, mnSize * sizeof(Attribute) ); + pTemp = (Attribute*) realloc( mpList, mnSize * sizeof(Attribute) ); + if (pTemp) + { + mpList = pTemp; + } + else + { + mnSize = mnSizetemp; + } } } @@ -572,14 +583,16 @@ AttributeStorage::Insert( const char *pString, int nLength ) // if still not found we have to Insert the new string if ( mnSize == mnCount ) Enlarge(); - mpList[mnCount].SetName( pString, nLength ); - mpList[mnCount].SetValue( mnDefaultValue ); - mpList[mnCount].SetAnnotation( NULL ); - mpList[mnCount].SetFeature( XLFD_FEATURE_NONE ); - mpList[mnCount].InitKey( ); - mnLastmatch = mnCount; - mnCount = mnCount < 65535 ? mnCount + 1 : mnCount; - + if ( mnSize != mnCount ) + { + mpList[mnCount].SetName( pString, nLength ); + mpList[mnCount].SetValue( mnDefaultValue ); + mpList[mnCount].SetAnnotation( NULL ); + mpList[mnCount].SetFeature( XLFD_FEATURE_NONE ); + mpList[mnCount].InitKey( ); + mnLastmatch = mnCount; + mnCount = mnCount < 65535 ? mnCount + 1 : mnCount; + } return mnLastmatch; } diff --git a/vcl/unx/source/printer/cupsmgr.cxx b/vcl/unx/source/printer/cupsmgr.cxx index acfabf1..1e750f5 100644 --- a/vcl/unx/source/printer/cupsmgr.cxx +++ b/vcl/unx/source/printer/cupsmgr.cxx @@ -440,7 +440,6 @@ void CUPSManager::runDests() #if OSL_DEBUG_LEVEL > 1 fprintf( stderr, "starting cupsGetDests\n" ); #endif - int nDests = 0; cups_dest_t* pDests = NULL; // #i86306# prepare against really broken CUPS installations / missing servers @@ -460,7 +459,7 @@ void CUPSManager::runDests() // prepare against a signal during FcInit or FcConfigGetCurrent if( sigsetjmp( aViolationBuffer, ~0 ) == 0 ) { - nDests = m_pCUPSWrapper->cupsGetDests( &pDests ); + int nDests = m_pCUPSWrapper->cupsGetDests( &pDests ); #if OSL_DEBUG_LEVEL > 1 fprintf( stderr, "came out of cupsGetDests\n" ); #endif @@ -855,7 +854,6 @@ void CUPSManager::getOptionsFromDocumentSetup( const JobData& rJob, int& rNumOpt { rNumOptions = 0; *rOptions = NULL; - int i; // emit features ordered to OrderDependency // ignore features that are set to default @@ -863,6 +861,7 @@ void CUPSManager::getOptionsFromDocumentSetup( const JobData& rJob, int& rNumOpt // sanity check if( rJob.m_pParser == rJob.m_aContext.getParser() && rJob.m_pParser ) { + int i; int nKeys = rJob.m_aContext.countValuesModified(); ::std::vector< const PPDKey* > aKeys( nKeys ); for( i = 0; i < nKeys; i++ ) diff --git a/vcl/unx/source/printer/ppdparser.cxx b/vcl/unx/source/printer/ppdparser.cxx index a9bed0b..5fee6f9 100644 --- a/vcl/unx/source/printer/ppdparser.cxx +++ b/vcl/unx/source/printer/ppdparser.cxx @@ -1490,13 +1490,14 @@ void PPDParser::getResolutionFromString( const String& rString, int& rXRes, int& rYRes ) const { - int nPos = 0, nDPIPos; + int nDPIPos; rXRes = rYRes = 300; nDPIPos = rString.SearchAscii( "dpi" ); if( nDPIPos != STRING_NOTFOUND ) { + int nPos = 0; if( ( nPos = rString.Search( 'x' ) ) != STRING_NOTFOUND ) { rXRes = rString.Copy( 0, nPos ).ToInt32(); diff --git a/vcl/unx/source/printergfx/glyphset.cxx b/vcl/unx/source/printergfx/glyphset.cxx index 98fb2b9..3144ef3 100644 --- a/vcl/unx/source/printergfx/glyphset.cxx +++ b/vcl/unx/source/printergfx/glyphset.cxx @@ -713,7 +713,7 @@ GlyphSet::PSUploadEncoding(osl::File* pOutFile, PrinterGfx &rGfx) // loop thru all the font subsets sal_Int32 nGlyphSetID = 0; char_list_t::iterator aGlyphSet; - for (aGlyphSet = maCharList.begin(); aGlyphSet != maCharList.end(); aGlyphSet++) + for (aGlyphSet = maCharList.begin(); aGlyphSet != maCharList.end(); ++aGlyphSet) { ++nGlyphSetID; @@ -873,7 +873,7 @@ GlyphSet::PSUploadFont (osl::File& rOutFile, PrinterGfx &rGfx, bool bAllowType42 // loop thru all the chars in the subset char_map_t::const_iterator aChar; sal_Int32 n = 0; - for (aChar = (*aCharSet).begin(); aChar != (*aCharSet).end(); aChar++) + for (aChar = (*aCharSet).begin(); aChar != (*aCharSet).end(); ++aChar) { pUChars [n] = (*aChar).first; pEncoding [n] = (*aChar).second; @@ -905,7 +905,7 @@ GlyphSet::PSUploadFont (osl::File& rOutFile, PrinterGfx &rGfx, bool bAllowType42 // loop thru all the glyphs in the subset glyph_map_t::const_iterator aGlyph; sal_Int32 n = 0; - for (aGlyph = (*aGlyphSet).begin(); aGlyph != (*aGlyphSet).end(); aGlyph++) + for (aGlyph = (*aGlyphSet).begin(); aGlyph != (*aGlyphSet).end(); ++aGlyph) { pTTGlyphMapping [n] = (*aGlyph).first; pEncoding [n] = (*aGlyph).second; diff --git a/vcl/unx/source/printergfx/printerjob.cxx b/vcl/unx/source/printergfx/printerjob.cxx index d5dd983..a3788d5 100644 --- a/vcl/unx/source/printergfx/printerjob.cxx +++ b/vcl/unx/source/printergfx/printerjob.cxx @@ -327,12 +327,12 @@ createSpoolDir () PrinterJob::~PrinterJob () { std::list< osl::File* >::iterator pPage; - for (pPage = maPageList.begin(); pPage != maPageList.end(); pPage++) + for (pPage = maPageList.begin(); pPage != maPageList.end(); ++pPage) { //(*pPage)->remove(); delete *pPage; } - for (pPage = maHeaderList.begin(); pPage != maHeaderList.end(); pPage++) + for (pPage = maHeaderList.begin(); pPage != maHeaderList.end(); ++pPage) { //(*pPage)->remove(); delete *pPage; @@ -575,7 +575,7 @@ PrinterJob::EndJob () std::list< osl::File* >::iterator pPageHead; for (pPageBody = maPageList.begin(), pPageHead = maHeaderList.begin(); pPageBody != maPageList.end() && pPageHead != maHeaderList.end(); - pPageBody++, pPageHead++) + ++pPageBody, ++pPageHead) { if( *pPageHead ) { @@ -806,7 +806,6 @@ static bool writeFeature( osl::File* pFile, const PPDKey* pKey, const PPDValue* bool PrinterJob::writeFeatureList( osl::File* pFile, const JobData& rJob, bool bDocumentSetup ) { bool bSuccess = true; - int i; // emit features ordered to OrderDependency // ignore features that are set to default @@ -817,6 +816,7 @@ bool PrinterJob::writeFeatureList( osl::File* pFile, const JobData& rJob, bool b ( m_aLastJobData.m_pParser == rJob.m_pParser || m_aLastJobData.m_pParser == NULL ) ) { + int i; int nKeys = rJob.m_aContext.countValuesModified(); ::std::vector< const PPDKey* > aKeys( nKeys ); for( i = 0; i < nKeys; i++ ) diff --git a/vcl/unx/source/printergfx/text_gfx.cxx b/vcl/unx/source/printergfx/text_gfx.cxx index c81a49f..f68110f 100644 --- a/vcl/unx/source/printergfx/text_gfx.cxx +++ b/vcl/unx/source/printergfx/text_gfx.cxx @@ -179,7 +179,7 @@ void PrinterGfx::drawGlyphs( // draw the string // search for a glyph set matching the set font std::list< GlyphSet >::iterator aIter; - for (aIter = maPS3Font.begin(); aIter != maPS3Font.end(); aIter++) + for (aIter = maPS3Font.begin(); aIter != maPS3Font.end(); ++aIter) if ( ((*aIter).GetFontID() == mnFontID) && ((*aIter).IsVertical() == mbTextVertical)) { @@ -622,7 +622,7 @@ PrinterGfx::drawText( // search for a glyph set matching the set font std::list< GlyphSet >::iterator aIter; - for (aIter = maPS3Font.begin(); aIter != maPS3Font.end(); aIter++) + for (aIter = maPS3Font.begin(); aIter != maPS3Font.end(); ++aIter) if ( ((*aIter).GetFontID() == mnFontID) && ((*aIter).IsVertical() == mbTextVertical)) {
_______________________________________________ LibreOffice mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/libreoffice
