Several fixes to invalidScanfFormatWidthError():

- Different IDs for different messages (#5809)
- severity is warning, not style, so check _settings->isEnabled() properly
- Removed never shown message text
This commit is contained in:
PKEuS 2014-09-01 09:33:58 +02:00
parent d1d3c24f3e
commit 47764321f2
1 changed files with 17 additions and 19 deletions

View File

@ -1905,26 +1905,24 @@ void CheckIO::invalidLengthModifierError(const Token* tok, unsigned int numForma
void CheckIO::invalidScanfFormatWidthError(const Token* tok, unsigned int numFormat, int width, const Variable *var) void CheckIO::invalidScanfFormatWidthError(const Token* tok, unsigned int numFormat, int width, const Variable *var)
{ {
std::ostringstream errmsg; MathLib::bigint arrlen = 0;
Severity::SeverityType severity = Severity::warning; std::string varname;
bool inconclusive = false;
if (var) { if (var) {
if (var->dimension(0) > width) { arrlen = var->dimension(0);
if (!_settings->inconclusive) varname = var->name();
return; }
inconclusive = true;
errmsg << "Width " << width << " given in format string (no. " << numFormat << ") is smaller than destination buffer"
<< " '" << var->name() << "[" << var->dimension(0) << "]'.";
} else {
errmsg << "Width " << width << " given in format string (no. " << numFormat << ") is larger than destination buffer '"
<< var->name() << "[" << var->dimension(0) << "]', use %" << (var->dimension(0) - 1) << "s to prevent overflowing it.";
severity = Severity::error;
}
} else std::ostringstream errmsg;
errmsg << "Width " << width << " given in format string (no. " << numFormat << ") doesn't match destination buffer."; if (arrlen > width) {
if (!_settings->inconclusive || !_settings->isEnabled("warning"))
if (severity == Severity::error || _settings->isEnabled("style")) return;
reportError(tok, severity, "invalidScanfFormatWidth", errmsg.str(), inconclusive); errmsg << "Width " << width << " given in format string (no. " << numFormat << ") is smaller than destination buffer"
<< " '" << varname << "[" << arrlen << "]'.";
reportError(tok, Severity::warning, "invalidScanfFormatWidth_smaller", errmsg.str(), true);
} else {
errmsg << "Width " << width << " given in format string (no. " << numFormat << ") is larger than destination buffer '"
<< varname << "[" << arrlen << "]', use %" << (arrlen - 1) << "s to prevent overflowing it.";
reportError(tok, Severity::error, "invalidScanfFormatWidth", errmsg.str(), false);
}
} }