cppcheck: make static analysis more pedantic

This commit is contained in:
Felipe Zimmerle
2020-01-17 11:41:05 -03:00
parent cd9b8aa93b
commit 4f13fecbaf
23 changed files with 58 additions and 42 deletions

View File

@@ -37,36 +37,36 @@ bool ContainsWord::acceptableChar(const std::string& a, size_t pos) {
}
bool ContainsWord::evaluate(Transaction *transaction, Rule *rule,
const std::string &input, std::shared_ptr<RuleMessage> ruleMessage) {
const std::string &str, std::shared_ptr<RuleMessage> ruleMessage) {
std::string paramTarget(m_string->evaluate(transaction));
if (paramTarget.empty()) {
return true;
}
if (input.empty()) {
if (str.empty()) {
return false;
}
if (input == paramTarget) {
if (str == paramTarget) {
return true;
}
size_t pos = input.find(paramTarget);
size_t pos = str.find(paramTarget);
while (pos != std::string::npos) {
if (pos == 0 && acceptableChar(input, paramTarget.size())) {
if (pos == 0 && acceptableChar(str, paramTarget.size())) {
logOffset(ruleMessage, 0, paramTarget.size());
return true;
}
if (pos + paramTarget.size() == input.size() &&
acceptableChar(input, pos - 1)) {
if (pos + paramTarget.size() == str.size() &&
acceptableChar(str, pos - 1)) {
logOffset(ruleMessage, pos, paramTarget.size());
return true;
}
if (acceptableChar(input, pos - 1) &&
acceptableChar(input, pos + paramTarget.size())) {
if (acceptableChar(str, pos - 1) &&
acceptableChar(str, pos + paramTarget.size())) {
logOffset(ruleMessage, pos, paramTarget.size());
return true;
}
pos = input.find(paramTarget, pos + 1);
pos = str.find(paramTarget, pos + 1);
}
return false;