Kaydet (Commit) bf18f1b3 authored tarafından Michael Stahl's avatar Michael Stahl

compilerplugins: add "badstatics" to detect abuse of VCL Bitmaps

VCL Image/Bitmap/BitmapEx instances must not have static life-time
because then they will be destructed after DeInitVCL() and that
likely segfaults.

Change-Id: I3ff8d32de729c971b190028094cb4efe206395e2
üst bcd8da68
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include "plugin.hxx"
namespace {
class BadStatics
: public clang::RecursiveASTVisitor<BadStatics>
, public loplugin::Plugin
{
public:
explicit BadStatics(InstantiationData const& rData) : Plugin(rData) {}
void run() override {
if (compiler.getLangOpts().CPlusPlus) { // no non-trivial dtors in C
TraverseDecl(compiler.getASTContext().getTranslationUnitDecl());
}
}
bool VisitVarDecl(VarDecl const*const pVarDecl)
{
if (ignoreLocation(pVarDecl)) {
return true;
}
if (pVarDecl->hasGlobalStorage()) {
auto const type(pVarDecl->getType().getUnqualifiedType().getCanonicalType().getAsString());
if ( type == "class Image"
|| type == "class Bitmap"
|| type == "class BitmapEx"
)
{
report(DiagnosticsEngine::Warning,
"bad static variable causes crash on shutdown",
pVarDecl->getLocation())
<< pVarDecl->getSourceRange();
}
}
return true;
}
};
loplugin::Plugin::Registration<BadStatics> X("badstatics");
} // namespace
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -156,14 +156,8 @@ TYPEINIT1(FmFormItem, FmParentData); ...@@ -156,14 +156,8 @@ TYPEINIT1(FmFormItem, FmParentData);
Image FmFormItem::GetImage() const Image FmFormItem::GetImage() const
{ {
static Image aImage; ImageList aNavigatorImages( SVX_RES( RID_SVXIMGLIST_FMEXPL ) );
return aNavigatorImages.GetImage( RID_SVXIMG_FORM );
if (!aImage)
{
ImageList aNavigatorImages( SVX_RES( RID_SVXIMGLIST_FMEXPL ) );
aImage = aNavigatorImages.GetImage( RID_SVXIMG_FORM );
}
return aImage;
} }
...@@ -187,14 +181,8 @@ FmFilterItem* FmFilterItems::Find( const ::sal_Int32 _nFilterComponentIndex ) co ...@@ -187,14 +181,8 @@ FmFilterItem* FmFilterItems::Find( const ::sal_Int32 _nFilterComponentIndex ) co
Image FmFilterItems::GetImage() const Image FmFilterItems::GetImage() const
{ {
static Image aImage; ImageList aNavigatorImages( SVX_RES( RID_SVXIMGLIST_FMEXPL ) );
return aNavigatorImages.GetImage( RID_SVXIMG_FILTER );
if (!aImage)
{
ImageList aNavigatorImages( SVX_RES( RID_SVXIMGLIST_FMEXPL ) );
aImage = aNavigatorImages.GetImage( RID_SVXIMG_FILTER );
}
return aImage;
} }
...@@ -213,14 +201,8 @@ FmFilterItem::FmFilterItem( FmFilterItems* pParent, ...@@ -213,14 +201,8 @@ FmFilterItem::FmFilterItem( FmFilterItems* pParent,
Image FmFilterItem::GetImage() const Image FmFilterItem::GetImage() const
{ {
static Image aImage; ImageList aNavigatorImages( SVX_RES( RID_SVXIMGLIST_FMEXPL ) );
return aNavigatorImages.GetImage( RID_SVXIMG_FIELD );
if (!aImage)
{
ImageList aNavigatorImages( SVX_RES( RID_SVXIMGLIST_FMEXPL ) );
aImage = aNavigatorImages.GetImage( RID_SVXIMG_FIELD );
}
return aImage;
} }
......
...@@ -650,7 +650,7 @@ public: ...@@ -650,7 +650,7 @@ public:
// be done with a shader / gradient // be done with a shader / gradient
static void SimulateBorderStretch(OutputDevice &rDev, const Rectangle& r) static void SimulateBorderStretch(OutputDevice &rDev, const Rectangle& r)
{ {
static BitmapEx aPageShadowMask("sw/res/page-shadow-mask.png"); BitmapEx aPageShadowMask("sw/res/page-shadow-mask.png");
BitmapEx aRight(aPageShadowMask); BitmapEx aRight(aPageShadowMask);
sal_Int32 nSlice = (aPageShadowMask.GetSizePixel().Width() - 3) / 4; sal_Int32 nSlice = (aPageShadowMask.GetSizePixel().Width() - 3) / 4;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment