From 61bbcbeeee7128d4679957d3c6dcde38fe77adb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Thu, 14 Dec 2023 17:44:09 +0100 Subject: [PATCH] fixed #12108 - Crash in `CTU::FileInfo::getErrorPath()` with Clang-built binary (#5746) This is actually just a workaround as it seems the issue is an upstream Clang one. --- lib/checkbufferoverrun.cpp | 9 ++++++++- lib/checkclass.cpp | 9 ++++++++- lib/checknullpointer.cpp | 10 ++++++++-- lib/checkuninitvar.cpp | 9 ++++++++- 4 files changed, 32 insertions(+), 5 deletions(-) diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp index c0c5ddb64..dea22b984 100644 --- a/lib/checkbufferoverrun.cpp +++ b/lib/checkbufferoverrun.cpp @@ -884,7 +884,14 @@ 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 +#ifdef __clang__ +inline namespace CheckBufferOverrun_internal +#else +namespace +#endif +{ /** data for multifile checking */ class MyFileInfo : public Check::FileInfo { public: diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 245455ad4..9d3fa47fc 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -3402,7 +3402,14 @@ 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 +#ifdef __clang__ +inline namespace CheckClass_internal +#else +namespace +#endif +{ /* multifile checking; one definition rule violations */ class MyFileInfo : public Check::FileInfo { public: diff --git a/lib/checknullpointer.cpp b/lib/checknullpointer.cpp index cf70f7293..bb530e63a 100644 --- a/lib/checknullpointer.cpp +++ b/lib/checknullpointer.cpp @@ -558,7 +558,14 @@ 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 +#ifdef __clang__ +inline namespace CheckNullPointer_internal +#else +namespace +#endif +{ /* data for multifile checking */ class MyFileInfo : public Check::FileInfo { public: @@ -573,7 +580,6 @@ namespace { }; } - Check::FileInfo *CheckNullPointer::getFileInfo(const Tokenizer *tokenizer, const Settings *settings) const { const std::list &unsafeUsage = CTU::getUnsafeUsage(tokenizer, settings, isUnsafeUsage); diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index 94d64d275..3ab800b3d 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -1682,7 +1682,14 @@ 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 +#ifdef __clang__ +inline namespace CheckUninitVar_internal +#else +namespace +#endif +{ /* data for multifile checking */ class MyFileInfo : public Check::FileInfo { public: