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

Method addSuppression

lib/suppressions.cpp:285–317  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

283}
284
285std::string SuppressionList::addSuppression(SuppressionList::Suppression suppression)
286{
287 std::lock_guard<std::mutex> lg(mSuppressionsSync);
288
289 // Check if suppression is already in list
290 auto foundSuppression = std::find_if(mSuppressions.begin(), mSuppressions.end(),
291 std::bind(&Suppression::isSameParameters, &suppression, std::placeholders::_1));
292 if (foundSuppression != mSuppressions.end()) {
293 return "suppression '" + suppression.toString() + "' already exists";
294 }
295
296 // Check that errorId is valid..
297 if (suppression.errorId.empty() && suppression.hash == 0)
298 return "Failed to add suppression. No id.";
299
300 for (std::string::size_type pos = 0; pos < suppression.errorId.length(); ++pos) {
301 if (!isAcceptedErrorIdChar(suppression.errorId[pos])) {
302 return "Failed to add suppression. Invalid id \"" + suppression.errorId + "\"";
303 }
304 if (pos == 0 && std::isdigit(suppression.errorId[pos])) {
305 return "Failed to add suppression. Invalid id \"" + suppression.errorId + "\"";
306 }
307 }
308
309 if (!isValidGlobPattern(suppression.errorId))
310 return "Failed to add suppression. Invalid glob pattern '" + suppression.errorId + "'.";
311 if (!isValidGlobPattern(suppression.fileName))
312 return "Failed to add suppression. Invalid glob pattern '" + suppression.fileName + "'.";
313
314 mSuppressions.push_back(std::move(suppression));
315
316 return "";
317}
318
319std::string SuppressionList::addSuppressions(std::list<Suppression> suppressions)
320{

Callers 1

addInlineSuppressionsFunction · 0.45

Calls 7

isAcceptedErrorIdCharFunction · 0.85
isValidGlobPatternFunction · 0.85
beginMethod · 0.45
endMethod · 0.45
toStringMethod · 0.45
emptyMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected