| 1 |
/* |
| 2 |
SPDX-FileCopyrightText: 2018 Sergio Martins <[email protected]> |
| 3 |
|
| 4 |
SPDX-License-Identifier: LGPL-2.0-or-later |
| 5 |
*/ |
| 6 |
|
| 7 |
#include "raw-environment-function.h" |
| 8 |
#include "StringUtils.h" |
| 9 |
|
| 10 |
#include <clang/AST/Decl.h> |
| 11 |
#include <clang/AST/Expr.h> |
| 12 |
#include <clang/AST/Stmt.h> |
| 13 |
#include <clang/Basic/LLVM.h> |
| 14 |
#include <llvm/ADT/StringRef.h> |
| 15 |
#include <llvm/Support/Casting.h> |
| 16 |
|
| 17 |
using namespace clang; |
| 18 |
|
| 19 |
void RawEnvironmentFunction::VisitStmt(clang::Stmt *stmt) |
| 20 |
{ |
| 21 |
auto *callexpr = dyn_cast<CallExpr>(stmt); |
| 22 |
if (!callexpr) { |
| 23 |
return; |
| 24 |
} |
| 25 |
|
| 26 |
const FunctionDecl *func = callexpr->getDirectCallee(); |
| 27 |
if (!func) { |
| 28 |
return; |
| 29 |
} |
| 30 |
|
| 31 |
StringRef funcName = clazy::name(func); |
| 32 |
|
| 33 |
if (funcName == "putenv") { |
| 34 |
emitWarning(stmt, "Prefer using qputenv instead of putenv"); |
| 35 |
} |
| 36 |
|
| 37 |
if (funcName == "getenv") { |
| 38 |
emitWarning(stmt, "Prefer using qgetenv instead of getenv"); |
| 39 |
} |
| 40 |
} |