================ @@ -0,0 +1,35 @@ +//===--- SprintfToSnprintfCheck.h - clang-tidy ------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_SPRINTFTOSNPRINTFCHECK_H +#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_SPRINTFTOSNPRINTFCHECK_H + +#include "../ClangTidyCheck.h" +#include <vector> + +namespace clang::tidy::bugprone { + +/// Finds calls to sprintf where the destination is a fixed-size character +/// array and replaces them with the safer snprintf. +/// +/// For the user-facing documentation see: +/// http://clang.llvm.org/extra/clang-tidy/checks/bugprone/sprintf-to-snprintf.html +class SprintfToSnprintfCheck : public ClangTidyCheck { +public: + SprintfToSnprintfCheck(StringRef Name, ClangTidyContext *Context); + void registerMatchers(ast_matchers::MatchFinder *Finder) override; + void check(const ast_matchers::MatchFinder::MatchResult &Result) override; + void storeOptions(ClangTidyOptions::OptionMap &Opts) override; + ---------------- ThanSin02426 wrote:
I think LangOptions doesn't have a generic LangOpts.C boolean flag. **If I simply return true;**, it will allow the check to run on all language modes. If I want to explicitly restrict it to only C and C++, what is the preferred way to write that condition? Or is return true; acceptable here since the AST matcher will ignore files where sprintf isn't declared anyway? https://github.com/llvm/llvm-project/pull/182823 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
