File indexing completed on 2024-05-12 05:41:03
0001 /* 0002 SPDX-FileCopyrightText: 2018 Sergio Martins <smartins@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "raw-environment-function.h" 0008 #include "StringUtils.h" 0009 0010 #include <clang/AST/Decl.h> 0011 #include <clang/AST/Expr.h> 0012 #include <clang/AST/Stmt.h> 0013 #include <clang/Basic/LLVM.h> 0014 #include <llvm/ADT/StringRef.h> 0015 #include <llvm/Support/Casting.h> 0016 0017 class ClazyContext; 0018 0019 using namespace clang; 0020 0021 RawEnvironmentFunction::RawEnvironmentFunction(const std::string &name, ClazyContext *context) 0022 : CheckBase(name, context) 0023 { 0024 } 0025 0026 void RawEnvironmentFunction::VisitStmt(clang::Stmt *stmt) 0027 { 0028 auto *callexpr = dyn_cast<CallExpr>(stmt); 0029 if (!callexpr) { 0030 return; 0031 } 0032 0033 FunctionDecl *func = callexpr->getDirectCallee(); 0034 if (!func) { 0035 return; 0036 } 0037 0038 StringRef funcName = clazy::name(func); 0039 0040 if (funcName == "putenv") { 0041 emitWarning(stmt, "Prefer using qputenv instead of putenv"); 0042 } 0043 0044 if (funcName == "getenv") { 0045 emitWarning(stmt, "Prefer using qgetenv instead of getenv"); 0046 } 0047 }