MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / tooBigSignedBitwiseShiftError

Method tooBigSignedBitwiseShiftError

lib/checktype.cpp:132–161  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

130}
131
132void CheckTypeImpl::tooBigSignedBitwiseShiftError(const Token *tok, int lhsbits, const ValueFlow::Value &rhsbits)
133{
134 constexpr char id[] = "shiftTooManyBitsSigned";
135
136 const bool cpp14 = ((tok && tok->isCpp()) || (mTokenizer && mTokenizer->isCPP())) && (mSettings.standards.cpp >= Standards::CPP14);
137
138 std::string behaviour = "undefined";
139 if (cpp14)
140 behaviour = "implementation-defined";
141 if (!tok) {
142 reportError(tok, Severity::error, id, "Shifting signed 32-bit value by 31 bits is " + behaviour + " behaviour", CWE758, Certainty::normal);
143 return;
144 }
145
146
147 Severity severity = rhsbits.errorSeverity() ? Severity::error : Severity::warning;
148 if (cpp14)
149 severity = Severity::portability;
150
151 if ((severity == Severity::portability) && !mSettings.severity.isEnabled(Severity::portability))
152 return;
153 ErrorPath errorPath = getErrorPath(tok, &rhsbits, "Shift");
154
155 std::ostringstream errmsg;
156 errmsg << "Shifting signed " << lhsbits << "-bit value by " << rhsbits.intvalue << " bits is " + behaviour + " behaviour";
157 if (rhsbits.condition)
158 errmsg << ". See condition at line " << rhsbits.condition->linenr() << ".";
159
160 reportError(std::move(errorPath), severity, id, errmsg.str(), CWE758, rhsbits.isInconclusive() ? Certainty::inconclusive : Certainty::normal);
161}
162
163//---------------------------------------------------------------------------
164// Checking for integer overflow

Callers 1

getErrorMessagesMethod · 0.80

Calls 5

isCPPMethod · 0.80
reportErrorFunction · 0.70
isEnabledMethod · 0.45
strMethod · 0.45
isInconclusiveMethod · 0.45

Tested by

no test coverage detected