Bug 1874684 - Part 17: Fix uninitialised variable warnings from clang-tidy. r=allstarschh
[gecko.git] / build / clang-plugin / LoadLibraryUsageChecker.cpp
blob1c7d336ea9479997cb9d274c1c1ed1a873a36f6b
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include "LoadLibraryUsageChecker.h"
6 #include "CustomMatchers.h"
8 // On MacOS the filesystem is UTF-8, on linux the canonical filename is 8-bit
9 // string. On Windows data loss conversion will occur. This checker restricts
10 // the use of ASCII file functions for loading libraries.
12 void LoadLibraryUsageChecker::registerMatchers(MatchFinder *AstMatcher) {
13 AstMatcher->addMatcher(
14 callExpr(
15 allOf(isFirstParty(),
16 callee(functionDecl(anyOf(
17 allOf(isInSystemHeader(), anyOf(hasName("LoadLibraryA"),
18 hasName("LoadLibraryExA"))),
19 hasName("PR_LoadLibrary")))),
20 unless(hasArgument(0, stringLiteral()))))
21 .bind("funcCall"),
22 this);
25 void LoadLibraryUsageChecker::check(const MatchFinder::MatchResult &Result) {
26 const CallExpr *FuncCall = Result.Nodes.getNodeAs<CallExpr>("funcCall");
28 if (FuncCall) {
29 diag(FuncCall->getBeginLoc(),
30 "Usage of ASCII file functions (such as %0) is forbidden.",
31 DiagnosticIDs::Error)
32 << FuncCall->getDirectCallee()->getName();