misra; add rule 17.3
This commit is contained in:
parent
f64097465f
commit
d0e68e0d77
|
@ -812,6 +812,7 @@ class Configuration:
|
||||||
typedefInfo = []
|
typedefInfo = []
|
||||||
valueflow = []
|
valueflow = []
|
||||||
standards = None
|
standards = None
|
||||||
|
clang_warnings = []
|
||||||
|
|
||||||
def __init__(self, name):
|
def __init__(self, name):
|
||||||
self.name = name
|
self.name = name
|
||||||
|
@ -825,6 +826,7 @@ class Configuration:
|
||||||
self.typedefInfo = []
|
self.typedefInfo = []
|
||||||
self.valueflow = []
|
self.valueflow = []
|
||||||
self.standards = Standards()
|
self.standards = Standards()
|
||||||
|
self.clang_warnings = []
|
||||||
|
|
||||||
def set_tokens_links(self):
|
def set_tokens_links(self):
|
||||||
"""Set next/previous links between tokens."""
|
"""Set next/previous links between tokens."""
|
||||||
|
@ -1063,6 +1065,12 @@ class CppcheckData:
|
||||||
cfg = None
|
cfg = None
|
||||||
cfg_arguments = []
|
cfg_arguments = []
|
||||||
|
|
||||||
|
elif node.tag == 'clang-warning' and event == 'start':
|
||||||
|
cfg.clang_warnings.append({'file': node.get('file'),
|
||||||
|
'line': int(node.get('line')),
|
||||||
|
'column': int(node.get('column')),
|
||||||
|
'message': node.get('message')})
|
||||||
|
|
||||||
# Parse standards
|
# Parse standards
|
||||||
elif node.tag == "standards" and event == 'start':
|
elif node.tag == "standards" and event == 'start':
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -3126,6 +3126,11 @@ class MisraChecker:
|
||||||
self.reportError(tok, 17, 2)
|
self.reportError(tok, 17, 2)
|
||||||
tok = tok.next
|
tok = tok.next
|
||||||
|
|
||||||
|
def misra_17_3(self, cfg):
|
||||||
|
for w in cfg.clang_warnings:
|
||||||
|
if w['message'].endswith('[-Wimplicit-function-declaration]'):
|
||||||
|
self.reportError(cppcheckdata.Location(w), 17, 3)
|
||||||
|
|
||||||
def misra_17_6(self, rawTokens):
|
def misra_17_6(self, rawTokens):
|
||||||
for token in rawTokens:
|
for token in rawTokens:
|
||||||
if simpleMatch(token, '[ static'):
|
if simpleMatch(token, '[ static'):
|
||||||
|
@ -4339,6 +4344,7 @@ class MisraChecker:
|
||||||
self.executeCheck(1607, self.misra_16_7, cfg)
|
self.executeCheck(1607, self.misra_16_7, cfg)
|
||||||
self.executeCheck(1701, self.misra_17_1, cfg)
|
self.executeCheck(1701, self.misra_17_1, cfg)
|
||||||
self.executeCheck(1702, self.misra_17_2, cfg)
|
self.executeCheck(1702, self.misra_17_2, cfg)
|
||||||
|
self.executeCheck(1702, self.misra_17_3, cfg)
|
||||||
if cfgNumber == 0:
|
if cfgNumber == 0:
|
||||||
self.executeCheck(1706, self.misra_17_6, data.rawTokens)
|
self.executeCheck(1706, self.misra_17_6, data.rawTokens)
|
||||||
self.executeCheck(1707, self.misra_17_7, cfg)
|
self.executeCheck(1707, self.misra_17_7, cfg)
|
||||||
|
|
|
@ -371,7 +371,7 @@ const char * CppCheck::extraVersion()
|
||||||
return ExtraVersion;
|
return ExtraVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool reportClangErrors(std::istream &is, std::function<void(const ErrorMessage&)> reportErr)
|
static bool reportClangErrors(std::istream &is, std::function<void(const ErrorMessage&)> reportErr, std::vector<ErrorMessage> *warnings)
|
||||||
{
|
{
|
||||||
std::string line;
|
std::string line;
|
||||||
while (std::getline(is, line)) {
|
while (std::getline(is, line)) {
|
||||||
|
@ -381,6 +381,8 @@ static bool reportClangErrors(std::istream &is, std::function<void(const ErrorMe
|
||||||
std::string::size_type pos3 = line.find(": error: ");
|
std::string::size_type pos3 = line.find(": error: ");
|
||||||
if (pos3 == std::string::npos)
|
if (pos3 == std::string::npos)
|
||||||
pos3 = line.find(": fatal error:");
|
pos3 = line.find(": fatal error:");
|
||||||
|
if (warnings && pos3 == std::string::npos)
|
||||||
|
pos3 = line.find(": warning:");
|
||||||
if (pos3 == std::string::npos)
|
if (pos3 == std::string::npos)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -408,6 +410,12 @@ static bool reportClangErrors(std::istream &is, std::function<void(const ErrorMe
|
||||||
msg,
|
msg,
|
||||||
"syntaxError",
|
"syntaxError",
|
||||||
Certainty::normal);
|
Certainty::normal);
|
||||||
|
|
||||||
|
if (line.compare(pos3, 10, ": warning:") == 0) {
|
||||||
|
warnings->push_back(errmsg);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
reportErr(errmsg);
|
reportErr(errmsg);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -459,19 +467,20 @@ unsigned int CppCheck::check(const std::string &path)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure there are not syntax errors...
|
// Ensure there are not syntax errors...
|
||||||
|
std::vector<ErrorMessage> compilerWarnings;
|
||||||
if (!mSettings.buildDir.empty()) {
|
if (!mSettings.buildDir.empty()) {
|
||||||
std::ifstream fin(clangStderr);
|
std::ifstream fin(clangStderr);
|
||||||
auto reportError = [this](const ErrorMessage& errorMessage) {
|
auto reportError = [this](const ErrorMessage& errorMessage) {
|
||||||
reportErr(errorMessage);
|
reportErr(errorMessage);
|
||||||
};
|
};
|
||||||
if (reportClangErrors(fin, reportError))
|
if (reportClangErrors(fin, reportError, &compilerWarnings))
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
std::istringstream istr(output2);
|
std::istringstream istr(output2);
|
||||||
auto reportError = [this](const ErrorMessage& errorMessage) {
|
auto reportError = [this](const ErrorMessage& errorMessage) {
|
||||||
reportErr(errorMessage);
|
reportErr(errorMessage);
|
||||||
};
|
};
|
||||||
if (reportClangErrors(istr, reportError))
|
if (reportClangErrors(istr, reportError, &compilerWarnings))
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -496,6 +505,8 @@ unsigned int CppCheck::check(const std::string &path)
|
||||||
createDumpFile(mSettings, path, tokenizer.list.getFiles(), nullptr, fdump, dumpFile);
|
createDumpFile(mSettings, path, tokenizer.list.getFiles(), nullptr, fdump, dumpFile);
|
||||||
if (fdump.is_open()) {
|
if (fdump.is_open()) {
|
||||||
fdump << "<dump cfg=\"\">" << std::endl;
|
fdump << "<dump cfg=\"\">" << std::endl;
|
||||||
|
for (const ErrorMessage& errmsg: compilerWarnings)
|
||||||
|
fdump << " <clang-warning file=\"" << toxml(errmsg.callStack.front().getfile()) << "\" line=\"" << errmsg.callStack.front().line << "\" column=\"" << errmsg.callStack.front().column << "\" message=\"" << toxml(errmsg.shortMessage()) << "\"/>\n";
|
||||||
fdump << " <standards>" << std::endl;
|
fdump << " <standards>" << std::endl;
|
||||||
fdump << " <c version=\"" << mSettings.standards.getC() << "\"/>" << std::endl;
|
fdump << " <c version=\"" << mSettings.standards.getC() << "\"/>" << std::endl;
|
||||||
fdump << " <cpp version=\"" << mSettings.standards.getCPP() << "\"/>" << std::endl;
|
fdump << " <cpp version=\"" << mSettings.standards.getCPP() << "\"/>" << std::endl;
|
||||||
|
|
Loading…
Reference in New Issue