From ed740e741ec22f9aaea09bfc0b87d0801a7c492f Mon Sep 17 00:00:00 2001 From: Whisperity Date: Thu, 2 Feb 2023 15:22:04 +0100 Subject: [PATCH] [clang-tidy] Attempt fixing wrong caching result in `bugprone-unsafe-functions` There is a supposedly platform-specific crash related to not recognising the availability of *Annex K.* properly? This patch is an attempt for fixing this by moving the reset logic for the cache to a different place. It's really a coin-flip at this point whether this is really a fix... --- clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp | 4 ---- clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.h | 1 - .../test/clang-tidy/checkers/bugprone/unsafe-functions.c | 4 ++-- 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp index ebb4964..c069cc3 100644 --- a/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp @@ -226,10 +226,6 @@ void UnsafeFunctionsCheck::registerPPCallbacks( const SourceManager &SM, Preprocessor *PP, Preprocessor * /*ModuleExpanderPP*/) { this->PP = PP; -} - -void UnsafeFunctionsCheck::onEndOfTranslationUnit() { - this->PP = nullptr; IsAnnexKAvailable.reset(); } diff --git a/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.h b/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.h index 369ea25..f04a220 100644 --- a/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.h +++ b/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.h @@ -32,7 +32,6 @@ public: void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) override; - void onEndOfTranslationUnit() override; private: /// If true, additional functions from widely used API-s (such as POSIX) are diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/unsafe-functions.c b/clang-tools-extra/test/clang-tidy/checkers/bugprone/unsafe-functions.c index e1f8238..62754fa 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/unsafe-functions.c +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/unsafe-functions.c @@ -15,8 +15,8 @@ size_t wcslen(const wchar_t *S); void f1(char *S) { gets(S); - // CHECK-MESSAGES-WITH-ANNEX-K: :[[@LINE-1]]:3: warning: function 'gets' is insecure, was deprecated and removed in C11 and C++14; 'gets_s' should be used instead - // CHECK-MESSAGES-WITH-ANNEX-K-CERT-ONLY: :[[@LINE-2]]:3: warning: function 'gets' is insecure, was deprecated and removed in C11 and C++14; 'gets_s' should be used instea + // CHECK-MESSAGES-WITH-ANNEX-K: :[[@LINE-1]]:3: warning: function 'gets' is insecure, was deprecated and removed in C11 and C++14; 'gets_s' should be used instead [bugprone-unsafe-functions] + // CHECK-MESSAGES-WITH-ANNEX-K-CERT-ONLY: :[[@LINE-2]]:3: warning: function 'gets' is insecure, was deprecated and removed in C11 and C++14; 'gets_s' should be used instead // CHECK-MESSAGES-WITHOUT-ANNEX-K: :[[@LINE-3]]:3: warning: function 'gets' is insecure, was deprecated and removed in C11 and C++14; 'fgets' should be used instead strlen(S); -- 2.7.4