From 10c7c709706d66eed684470029880214c7c73985 Mon Sep 17 00:00:00 2001 From: orbitcowboy Date: Wed, 22 Jun 2022 00:03:18 +0200 Subject: [PATCH] Activated 'make validateRules' and improved rule XML file parsing. Now, it optionally accepts '...' tags to make xmllint happy. --- Makefile | 2 +- cli/cmdlineparser.cpp | 2 ++ rules/token-matching.xml | 52 +++++++++++++++++++++------------------- tools/dmake.cpp | 2 +- 4 files changed, 31 insertions(+), 27 deletions(-) diff --git a/Makefile b/Makefile index e0483901e..22cb89c9e 100644 --- a/Makefile +++ b/Makefile @@ -389,7 +389,7 @@ checkCWEEntries: /tmp/errorlist.xml $(PYTHON_INTERPRETER) tools/listErrorsWithoutCWE.py -F /tmp/errorlist.xml .PHONY: validateRules validateRules: - #xmllint --noout rules/*.xml + xmllint --noout rules/*.xml ###### Build diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp index 69af1c4ec..47afb8c9f 100644 --- a/cli/cmdlineparser.cpp +++ b/cli/cmdlineparser.cpp @@ -713,6 +713,8 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) tinyxml2::XMLDocument doc; if (doc.LoadFile(12+argv[i]) == tinyxml2::XML_SUCCESS) { tinyxml2::XMLElement *node = doc.FirstChildElement(); + if (node && strcmp(node->Value(), "rules") == 0) + node = node->NextSiblingElement("rules"); for (; node && strcmp(node->Value(), "rule") == 0; node = node->NextSiblingElement()) { Settings::Rule rule; diff --git a/rules/token-matching.xml b/rules/token-matching.xml index d85ed9e8e..8b7823c05 100644 --- a/rules/token-matching.xml +++ b/rules/token-matching.xml @@ -1,41 +1,43 @@ - + + Token :: (?:findm|(?:simple|)M)atch \([^,]+,\s+"(?:\s+|[^"]+?\s+") - TokenMatchSpacing - style - Useless extra spacing for Token::*Match. + TokenMatchSpacing + style + Useless extra spacing for Token::*Match. - - + + (?U)Token :: Match \([^,]+,\s+"[^%|!\[\]]+" \) - UseTokensimpleMatch - error - Token::simpleMatch should be used to match tokens without special pattern requirements. + UseTokensimpleMatch + error + Token::simpleMatch should be used to match tokens without special pattern requirements. - - + + \b[\w_]+ \. tokAt \( 0 \) - TokentokAt0 - error - tok->tokAt(0) is a slow way to say tok. + TokentokAt0 + error + tok->tokAt(0) is a slow way to say tok. - - + + \b[\w_]+ \. strAt \( 0 \) - TokenstrAt0 - error - tok->strAt(0) is a slow way to say tok->str() + TokenstrAt0 + error + tok->strAt(0) is a slow way to say tok->str() - - + + - TokenMatchVariable - error - Simplify 'Token :: Match ( expr , %var% ) && expr->variable()' to 'expr->variable()' + TokenMatchVariable + error + Simplify 'Token :: Match ( expr , %var% ) && expr->variable()' to 'expr->variable()' - + + diff --git a/tools/dmake.cpp b/tools/dmake.cpp index 557a2a499..a7d0df3b4 100644 --- a/tools/dmake.cpp +++ b/tools/dmake.cpp @@ -503,7 +503,7 @@ int main(int argc, char **argv) fout << "\t$(PYTHON_INTERPRETER) tools/listErrorsWithoutCWE.py -F /tmp/errorlist.xml\n"; fout << ".PHONY: validateRules\n"; fout << "validateRules:\n"; - fout << "\t#xmllint --noout rules/*.xml\n"; + fout << "\txmllint --noout rules/*.xml\n"; fout << "\n###### Build\n\n";