@@ -254,6 +254,8 @@ std::string SuppressionList::addSuppressionLine(const std::string &line)
254
254
255
255
std::string SuppressionList::addSuppression (SuppressionList::Suppression suppression)
256
256
{
257
+ std::lock_guard<std::mutex> lg (mSuppressionsSync );
258
+
257
259
// Check if suppression is already in list
258
260
auto foundSuppression = std::find_if (mSuppressions .begin (), mSuppressions .end (),
259
261
std::bind (&Suppression::isSameParameters, &suppression, std::placeholders::_1));
@@ -297,6 +299,8 @@ std::string SuppressionList::addSuppressions(std::list<Suppression> suppressions
297
299
// cppcheck-suppress unusedFunction
298
300
bool SuppressionList::updateSuppressionState (const SuppressionList::Suppression& suppression)
299
301
{
302
+ std::lock_guard<std::mutex> lg (mSuppressionsSync );
303
+
300
304
// Check if suppression is already in list
301
305
auto foundSuppression = std::find_if (mSuppressions .begin (), mSuppressions .end (),
302
306
std::bind (&Suppression::isSameParameters, &suppression, std::placeholders::_1));
@@ -431,6 +435,8 @@ std::string SuppressionList::Suppression::getText() const
431
435
432
436
bool SuppressionList::isSuppressed (const SuppressionList::ErrorMessage &errmsg, bool global)
433
437
{
438
+ std::lock_guard<std::mutex> lg (mSuppressionsSync );
439
+
434
440
const bool unmatchedSuppression (errmsg.errorId == " unmatchedSuppression" );
435
441
bool returnValue = false ;
436
442
for (Suppression &s : mSuppressions ) {
@@ -446,6 +452,8 @@ bool SuppressionList::isSuppressed(const SuppressionList::ErrorMessage &errmsg,
446
452
447
453
bool SuppressionList::isSuppressedExplicitly (const SuppressionList::ErrorMessage &errmsg, bool global)
448
454
{
455
+ std::lock_guard<std::mutex> lg (mSuppressionsSync );
456
+
449
457
for (Suppression &s : mSuppressions ) {
450
458
if (!global && !s.isLocal ())
451
459
continue ;
@@ -459,13 +467,19 @@ bool SuppressionList::isSuppressedExplicitly(const SuppressionList::ErrorMessage
459
467
460
468
bool SuppressionList::isSuppressed (const ::ErrorMessage &errmsg, const std::set<std::string>& macroNames)
461
469
{
462
- if (mSuppressions .empty ())
463
- return false ;
470
+ {
471
+ std::lock_guard<std::mutex> lg (mSuppressionsSync );
472
+
473
+ if (mSuppressions .empty ())
474
+ return false ;
475
+ }
464
476
return isSuppressed (SuppressionList::ErrorMessage::fromErrorMessage (errmsg, macroNames));
465
477
}
466
478
467
479
void SuppressionList::dump (std::ostream & out) const
468
480
{
481
+ std::lock_guard<std::mutex> lg (mSuppressionsSync );
482
+
469
483
out << " <suppressions>" << std::endl;
470
484
for (const Suppression &suppression : mSuppressions ) {
471
485
out << " <suppression" ;
@@ -499,6 +513,8 @@ void SuppressionList::dump(std::ostream & out) const
499
513
500
514
std::list<SuppressionList::Suppression> SuppressionList::getUnmatchedLocalSuppressions (const FileWithDetails &file, const bool unusedFunctionChecking) const
501
515
{
516
+ std::lock_guard<std::mutex> lg (mSuppressionsSync );
517
+
502
518
std::list<Suppression> result;
503
519
for (const Suppression &s : mSuppressions ) {
504
520
if (s.matched || ((s.lineNumber != Suppression::NO_LINE) && !s.checked ))
@@ -520,6 +536,8 @@ std::list<SuppressionList::Suppression> SuppressionList::getUnmatchedLocalSuppre
520
536
521
537
std::list<SuppressionList::Suppression> SuppressionList::getUnmatchedGlobalSuppressions (const bool unusedFunctionChecking) const
522
538
{
539
+ std::lock_guard<std::mutex> lg (mSuppressionsSync );
540
+
523
541
std::list<Suppression> result;
524
542
for (const Suppression &s : mSuppressions ) {
525
543
if (s.matched || ((s.lineNumber != Suppression::NO_LINE) && !s.checked ))
@@ -537,12 +555,16 @@ std::list<SuppressionList::Suppression> SuppressionList::getUnmatchedGlobalSuppr
537
555
return result;
538
556
}
539
557
540
- const std::list<SuppressionList::Suppression> & SuppressionList::getSuppressions () const
558
+ std::list<SuppressionList::Suppression> SuppressionList::getSuppressions () const
541
559
{
560
+ std::lock_guard<std::mutex> lg (mSuppressionsSync );
561
+
542
562
return mSuppressions ;
543
563
}
544
564
545
565
void SuppressionList::markUnmatchedInlineSuppressionsAsChecked (const Tokenizer &tokenizer) {
566
+ std::lock_guard<std::mutex> lg (mSuppressionsSync );
567
+
546
568
int currLineNr = -1 ;
547
569
int currFileIdx = -1 ;
548
570
for (const Token *tok = tokenizer.tokens (); tok; tok = tok->next ()) {
0 commit comments