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(
16 callee(functionDecl(anyOf(
17 allOf(isInSystemHeader(), anyOf(hasName("LoadLibraryA"),
18 hasName("LoadLibraryExA"))),
19 hasName("PR_LoadLibrary")))),
20 unless(hasArgument(0, stringLiteral()))))
25 void LoadLibraryUsageChecker::check(const MatchFinder::MatchResult
&Result
) {
26 const CallExpr
*FuncCall
= Result
.Nodes
.getNodeAs
<CallExpr
>("funcCall");
29 diag(FuncCall
->getBeginLoc(),
30 "Usage of ASCII file functions (such as %0) is forbidden.",
32 << FuncCall
->getDirectCallee()->getName();