Skip to content

Commit 11426e8

Browse files
committed
ProcessExecutor: do not use mutable Suppressions object from parent in forked process
1 parent 504d1d2 commit 11426e8

2 files changed

Lines changed: 100 additions & 3 deletions

File tree

cli/processexecutor.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,12 @@ unsigned int ProcessExecutor::check()
342342
return v + p.size();
343343
});
344344

345+
// pass unmodified suppressions to forked process so we only transfer back the actual changes done by the fork
346+
// and do not see the changes which have already been transferred back
347+
Suppressions supprs;
348+
supprs.nomsg.addSuppressions(mSuppressions.nomsg.getSuppressions());
349+
supprs.nofail.addSuppressions(mSuppressions.nofail.getSuppressions());
350+
345351
std::list<int> rpipes;
346352
std::map<pid_t, std::string> childFile;
347353
std::map<int, std::string> pipeFile;
@@ -383,10 +389,9 @@ unsigned int ProcessExecutor::check()
383389
// reset so we do not have the data which has already been transferred back
384390
if (mTimerResults)
385391
mTimerResults->reset();
386-
// TODO: how to "reset" mSuppressions?
387392

388393
PipeWriter pipewriter(pipes[1], mSettings.debugipc);
389-
CppCheck fileChecker(mSettings, mSuppressions, pipewriter, mTimerResults, false, mExecuteCommand);
394+
CppCheck fileChecker(mSettings, supprs, pipewriter, mTimerResults, false, mExecuteCommand);
390395
unsigned int resultOfCheck = 0;
391396

392397
if (iFileSettings != mFileSettings.end()) {
@@ -396,7 +401,7 @@ unsigned int ProcessExecutor::check()
396401
resultOfCheck = fileChecker.check(*iFile);
397402
}
398403

399-
pipewriter.writeSuppr(mSuppressions.nomsg);
404+
pipewriter.writeSuppr(supprs.nomsg);
400405

401406
pipewriter.writeTimer(mTimerResults);
402407

test/cli/other_test.py

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4657,4 +4657,96 @@ def test_ipc(tmp_path):
46574657
'writeToPipe - 5 - 0',
46584658
'handleRead - 5 - 0'
46594659
]
4660+
assert stderr.splitlines() == []
4661+
4662+
4663+
@pytest.mark.skipif(sys.platform == 'win32', reason="requires ProcessExecutor")
4664+
def test_ipc_suppressions(tmp_path):
4665+
test1_file = tmp_path / 'test1.c'
4666+
with open(test1_file, "w") as f:
4667+
f.write('void f() {}')
4668+
4669+
test2_file = tmp_path / 'test2.c'
4670+
with open(test2_file, "w") as f:
4671+
f.write('void f() {}')
4672+
4673+
test3_file = tmp_path / 'test3.c'
4674+
with open(test3_file, "w") as f:
4675+
f.write('void f() {}')
4676+
4677+
args = [
4678+
'-q',
4679+
'--debug-ipc',
4680+
'-j2',
4681+
'--executor=process',
4682+
'--no-cppcheck-build-dir',
4683+
'--suppress=id0:test1.c',
4684+
str(tmp_path)
4685+
]
4686+
4687+
exitcode, stdout, stderr = cppcheck(args)
4688+
assert exitcode == 0
4689+
# sort the lines since the order is not fixed
4690+
stdout_exp = [
4691+
'writeToPipe - 4 - id0:test1.c;0;1;0;',
4692+
'handleRead - 4 - id0:test1.c;0;1;0;',
4693+
'writeToPipe - 5 - 0',
4694+
'handleRead - 5 - 0',
4695+
'writeToPipe - 5 - 0',
4696+
'handleRead - 5 - 0',
4697+
'writeToPipe - 5 - 0',
4698+
'handleRead - 5 - 0'
4699+
]
4700+
stdout_exp.sort()
4701+
stdout_lines = stdout.splitlines()
4702+
stdout_lines.sort()
4703+
assert stdout_lines == stdout_exp
4704+
assert stderr.splitlines() == []
4705+
4706+
4707+
@pytest.mark.skipif(sys.platform == 'win32', reason="requires ProcessExecutor")
4708+
def test_ipc_inline_suppressions(tmp_path):
4709+
test1_file = tmp_path / 'test1.c'
4710+
with open(test1_file, "w") as f:
4711+
f.write('void f() {} // cppcheck-suppress id1')
4712+
4713+
test2_file = tmp_path / 'test2.c'
4714+
with open(test2_file, "w") as f:
4715+
f.write('void f() {} // cppcheck-suppress id2')
4716+
4717+
test3_file = tmp_path / 'test3.c'
4718+
with open(test3_file, "w") as f:
4719+
f.write('void f() {} // cppcheck-suppress id3')
4720+
4721+
args = [
4722+
'-q',
4723+
'--debug-ipc',
4724+
'-j2',
4725+
'--executor=process',
4726+
'--no-cppcheck-build-dir',
4727+
'--inline-suppr',
4728+
str(tmp_path)
4729+
]
4730+
4731+
exitcode, stdout, stderr = cppcheck(args)
4732+
assert exitcode == 0
4733+
# sort the lines since the order is not fixed
4734+
stdout_exp = [
4735+
f'writeToPipe - 3 - id1:{test1_file}:1;13;1;0;',
4736+
f'handleRead - 3 - id1:{test1_file}:1;13;1;0;',
4737+
'writeToPipe - 5 - 0',
4738+
'handleRead - 5 - 0',
4739+
f'writeToPipe - 3 - id2:{test2_file}:1;13;1;0;',
4740+
f'handleRead - 3 - id2:{test2_file}:1;13;1;0;',
4741+
'writeToPipe - 5 - 0',
4742+
'handleRead - 5 - 0',
4743+
f'writeToPipe - 3 - id3:{test3_file}:1;13;1;0;',
4744+
f'handleRead - 3 - id3:{test3_file}:1;13;1;0;',
4745+
'writeToPipe - 5 - 0',
4746+
'handleRead - 5 - 0'
4747+
]
4748+
stdout_exp.sort()
4749+
stdout_lines = stdout.splitlines()
4750+
stdout_lines.sort()
4751+
assert stdout_lines == stdout_exp
46604752
assert stderr.splitlines() == []

0 commit comments

Comments
 (0)