Apache OpenOffice (AOO) Bugzilla – Issue 114412
sw: dubious delete in SwCalc::Str2Double
Last modified: 2017-05-20 10:22:13 UTC
There is the following code in BOOL SwCalc::Str2Double( const String& rCommand, xub_StrLen& rCommandPos, double& rVal, const LocaleDataWrapper* const pLclData ) : if( !pLclData && pLclD != &SvtSysLocale.GetLocaleData() ) delete (LocaleDataWrapper*)pLclD; . The condition is always false because pLclData is assigned from &SvtSysLocale::GetLocaleData() if it's 0. I've removed it and refactored the remaining code a bit to get rid of duplicate code. The patch is only applicable if the patch in #i114409# is also applied.
Created attachment 71615 [details] remove the delete and simplify the code a bit
.
@dtardon: you've left the "if (...) delete pLclD" in the second copy of Str2Double, can't see a reason why only one should be removed, i guess that's an oversight?
dtardon->mst: because pLclD might have been created inside the function: see pLclD = new LocaleDataWrapper(...) a few lines above. (I don't know if that block is still relevant, though. Maybe the condition eLang != SvxLocaleToLanguage( pLclD->getLocale() ) is always false...)
@dtardon: d'oh, of course, now that you mention it i also see it :)
thanks for removing the code duplication; you have unfortunately introduced a problem that you never expected: the stupid SunStudio C++ compiler can't link sw anymore, because it's stupid and mangles the "const" that you added to the parameter into the method name, which is afaik not allowed by the C++ standard (for good reasons, because whether a parameter is const/volatile or not is purely an implementation detail). unfortunately it's necessary to adapt the header as well to make stupid Sun C++ happy. so i've fixed that and then refactored a bit more to replace the UGLY BOOL with nice bool and also replaced the other delete with an auto_ptr. fixed in cws sw34bf01 http://hg.services.openoffice.org/hg/cws/sw34bf01/rev/43f603d097e0 http://hg.services.openoffice.org/hg/cws/sw34bf01/rev/6e6683f194c5
please verify
looks good
um, http://hg.services.openoffice.org/hg/cws/sw34bf01/rev/6e6683f194c5 doesn't make any sense to me. ::std::auto_ptr<const LocaleDataWrapper> pLclD; ... if( eLang != SvxLocaleToLanguage( pLclD->getLocale() ) ) ... i.e. dereference of unset pLclD maybe, if( eLang != SvxLocaleToLanguage( aSysLocale.GetLocaleData().getLocale() ) ) is what was intended
@cmc: d'oh! of course you are right! 114412 is now officially my unlucky number... fixed here (but please double-check it): http://hg.services.openoffice.org/hg/cws/sw34bf01/rev/2b2b31b4f97e
That seems sane to me, yup