brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.9 KiB · cf61eb5 Raw
64 lines · c
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_NOTNULLTERMINATEDRESULTCHECK_H10#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_NOTNULLTERMINATEDRESULTCHECK_H11 12#include "../ClangTidyCheck.h"13 14namespace clang::tidy::bugprone {15 16/// Finds function calls where it is possible to cause a not null-terminated17/// result. Usually the proper length of a string is 'strlen(src) + 1' or18/// equal length of this expression, because the null terminator needs an extra19/// space. Without the null terminator it can result in undefined behaviour20/// when the string is read.21///22/// For the user-facing documentation see:23/// https://clang.llvm.org/extra/clang-tidy/checks/bugprone/not-null-terminated-result.html24class NotNullTerminatedResultCheck : public ClangTidyCheck {25public:26  NotNullTerminatedResultCheck(StringRef Name, ClangTidyContext *Context);27  void storeOptions(ClangTidyOptions::OptionMap &Opts) override;28  void registerMatchers(ast_matchers::MatchFinder *Finder) override;29  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;30  void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,31                           Preprocessor *ModuleExpanderPP) override;32 33private:34  // If non-zero it is specifying if the target environment is considered to35  // implement '_s' suffixed memory and string handler functions which are safer36  // than older version (e.g. 'memcpy_s()'). The default value is '1'.37  const bool WantToUseSafeFunctions;38 39  bool UseSafeFunctions = false;40 41  void memoryHandlerFunctionFix(42      StringRef Name, const ast_matchers::MatchFinder::MatchResult &Result);43  void memcpyFix(StringRef Name,44                 const ast_matchers::MatchFinder::MatchResult &Result,45                 DiagnosticBuilder &Diag);46  void memcpySFix(StringRef Name,47                  const ast_matchers::MatchFinder::MatchResult &Result,48                  DiagnosticBuilder &Diag);49  void memchrFix(StringRef Name,50                 const ast_matchers::MatchFinder::MatchResult &Result);51  void memmoveFix(StringRef Name,52                  const ast_matchers::MatchFinder::MatchResult &Result,53                  DiagnosticBuilder &Diag) const;54  void strerrorSFix(const ast_matchers::MatchFinder::MatchResult &Result);55  void ncmpFix(StringRef Name,56               const ast_matchers::MatchFinder::MatchResult &Result);57  void xfrmFix(StringRef Name,58               const ast_matchers::MatchFinder::MatchResult &Result);59};60 61} // namespace clang::tidy::bugprone62 63#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_NOTNULLTERMINATEDRESULTCHECK_H64