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:
parent
d1d3c24f3e
commit
47764321f2
|
@ -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)
|
||||
{
|
||||
std::ostringstream errmsg;
|
||||
Severity::SeverityType severity = Severity::warning;
|
||||
bool inconclusive = false;
|
||||
MathLib::bigint arrlen = 0;
|
||||
std::string varname;
|
||||
|
||||
if (var) {
|
||||
if (var->dimension(0) > width) {
|
||||
if (!_settings->inconclusive)
|
||||
arrlen = var->dimension(0);
|
||||
varname = var->name();
|
||||
}
|
||||
|
||||
std::ostringstream errmsg;
|
||||
if (arrlen > width) {
|
||||
if (!_settings->inconclusive || !_settings->isEnabled("warning"))
|
||||
return;
|
||||
inconclusive = true;
|
||||
errmsg << "Width " << width << " given in format string (no. " << numFormat << ") is smaller than destination buffer"
|
||||
<< " '" << var->name() << "[" << var->dimension(0) << "]'.";
|
||||
<< " '" << 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 '"
|
||||
<< var->name() << "[" << var->dimension(0) << "]', use %" << (var->dimension(0) - 1) << "s to prevent overflowing it.";
|
||||
severity = Severity::error;
|
||||
<< varname << "[" << arrlen << "]', use %" << (arrlen - 1) << "s to prevent overflowing it.";
|
||||
reportError(tok, Severity::error, "invalidScanfFormatWidth", errmsg.str(), false);
|
||||
}
|
||||
|
||||
} else
|
||||
errmsg << "Width " << width << " given in format string (no. " << numFormat << ") doesn't match destination buffer.";
|
||||
|
||||
if (severity == Severity::error || _settings->isEnabled("style"))
|
||||
reportError(tok, severity, "invalidScanfFormatWidth", errmsg.str(), inconclusive);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue