Skip to content

Commit

Permalink
fixed #12108 - Crash in CTU::FileInfo::getErrorPath() with Clang-buil…
Browse files Browse the repository at this point in the history
…t binary
  • Loading branch information
firewave committed Dec 11, 2023
1 parent d695c6c commit 735f3b3
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 4 deletions.
12 changes: 11 additions & 1 deletion lib/checkbufferoverrun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,13 @@ void CheckBufferOverrun::argumentSizeError(const Token *tok, const std::string &
// CTU..
//---------------------------------------------------------------------------

namespace {
// a Clang-built executable will crash when using the anonymous MyFileInfo later on - so put it in a unique namespace for now
// see https://trac.cppcheck.net/ticket/12108 for more details
namespace
#ifdef __clang__
CheckBufferOverrun_internal
#endif
{
/** data for multifile checking */
class MyFileInfo : public Check::FileInfo {
public:
Expand All @@ -907,6 +913,10 @@ namespace {
};
}

#ifdef __clang__
using CheckBufferOverrun_internal::MyFileInfo;
#endif

bool CheckBufferOverrun::isCtuUnsafeBufferUsage(const Settings *settings, const Token *argtok, MathLib::bigint *offset, int type)
{
if (!offset)
Expand Down
12 changes: 11 additions & 1 deletion lib/checkclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3402,7 +3402,13 @@ void CheckClass::unsafeClassRefMemberError(const Token *tok, const std::string &
CWE(0), Certainty::normal);
}

namespace {
// a Clang-built executable will crash when using the anonymous MyFileInfo later on - so put it in a unique namespace for now
// see https://trac.cppcheck.net/ticket/12108 for more details
namespace
#ifdef __clang__
CheckClass_internal
#endif
{
/* multifile checking; one definition rule violations */
class MyFileInfo : public Check::FileInfo {
public:
Expand Down Expand Up @@ -3438,6 +3444,10 @@ namespace {
};
}

#ifdef __clang__
using CheckClass_internal::MyFileInfo;
#endif

Check::FileInfo *CheckClass::getFileInfo(const Tokenizer *tokenizer, const Settings *settings) const
{
if (!tokenizer->isCPP())
Expand Down
11 changes: 10 additions & 1 deletion lib/checknullpointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,13 @@ static bool isUnsafeUsage(const Settings *settings, const Token *vartok, MathLib
return CheckNullPointer::isPointerDeRef(vartok, unknown, settings);
}

namespace {
// a Clang-built executable will crash when using the anonymous MyFileInfo later on - so put it in a unique namespace for now
// see https://trac.cppcheck.net/ticket/12108 for more details
namespace
#ifdef __clang__
CheckNullPointer_internal
#endif
{
/* data for multifile checking */
class MyFileInfo : public Check::FileInfo {
public:
Expand All @@ -573,6 +579,9 @@ namespace {
};
}

#ifdef __clang__
using CheckNullPointer_internal::MyFileInfo;
#endif

Check::FileInfo *CheckNullPointer::getFileInfo(const Tokenizer *tokenizer, const Settings *settings) const
{
Expand Down
12 changes: 11 additions & 1 deletion lib/checkuninitvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1682,7 +1682,13 @@ static bool isVariableUsage(const Settings *settings, const Token *vartok, MathL
return CheckUninitVar::isVariableUsage(vartok, settings->library, true, CheckUninitVar::Alloc::ARRAY);
}

namespace {
// a Clang-built executable will crash when using the anonymous MyFileInfo later on - so put it in a unique namespace for now
// see https://trac.cppcheck.net/ticket/12108 for more details
namespace
#ifdef __clang__
CheckUninitVar_internal
#endif
{
/* data for multifile checking */
class MyFileInfo : public Check::FileInfo {
public:
Expand All @@ -1697,6 +1703,10 @@ namespace {
};
}

#ifdef __clang__
using CheckUninitVar_internal::MyFileInfo;
#endif

Check::FileInfo *CheckUninitVar::getFileInfo(const Tokenizer *tokenizer, const Settings *settings) const
{
const std::list<CTU::FileInfo::UnsafeUsage> &unsafeUsage = CTU::getUnsafeUsage(tokenizer, settings, ::isVariableUsage);
Expand Down

0 comments on commit 735f3b3

Please sign in to comment.