Skip to content

Commit eb9956e

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

2 files changed

Lines changed: 98 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: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4657,4 +4657,94 @@ 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+
'--suppress=id0:test1.c',
4683+
str(tmp_path)
4684+
]
4685+
4686+
exitcode, stdout, stderr = cppcheck(args)
4687+
assert exitcode == 0
4688+
# sort the lines since the order is not fixed
4689+
stdout_exp = [
4690+
'writeToPipe - 4 - id0:test1.c;0;1;0;',
4691+
'handleRead - 4 - id0:test1.c;0;1;0;',
4692+
'writeToPipe - 5 - 0',
4693+
'handleRead - 5 - 0',
4694+
'writeToPipe - 5 - 0',
4695+
'handleRead - 5 - 0',
4696+
'writeToPipe - 5 - 0',
4697+
'handleRead - 5 - 0'
4698+
]
4699+
stdout_exp.sort()
4700+
stdout_lines = stdout.splitlines()
4701+
stdout_lines.sort()
4702+
assert stdout_lines == stdout_exp
4703+
assert stderr.splitlines() == []
4704+
4705+
4706+
@pytest.mark.skipif(sys.platform == 'win32', reason="requires ProcessExecutor")
4707+
def test_ipc_inline_suppressions(tmp_path):
4708+
test1_file = tmp_path / 'test1.c'
4709+
with open(test1_file, "w") as f:
4710+
f.write('void f() {} // cppcheck-suppress id1')
4711+
4712+
test2_file = tmp_path / 'test2.c'
4713+
with open(test2_file, "w") as f:
4714+
f.write('void f() {} // cppcheck-suppress id2')
4715+
4716+
test3_file = tmp_path / 'test3.c'
4717+
with open(test3_file, "w") as f:
4718+
f.write('void f() {} // cppcheck-suppress id3')
4719+
4720+
args = [
4721+
'-q',
4722+
'--debug-ipc',
4723+
'-j2',
4724+
'--executor=process',
4725+
'--inline-suppr',
4726+
str(tmp_path)
4727+
]
4728+
4729+
exitcode, stdout, stderr = cppcheck(args)
4730+
assert exitcode == 0
4731+
# sort the lines since the order is not fixed
4732+
stdout_exp = [
4733+
f'writeToPipe - 3 - id1:{test1_file}:1;13;1;0;',
4734+
f'handleRead - 3 - id1:{test1_file}:1;13;1;0;',
4735+
'writeToPipe - 5 - 0',
4736+
'handleRead - 5 - 0',
4737+
f'writeToPipe - 3 - id2:{test2_file}:1;13;1;0;',
4738+
f'handleRead - 3 - id2:{test2_file}:1;13;1;0;',
4739+
'writeToPipe - 5 - 0',
4740+
'handleRead - 5 - 0',
4741+
f'writeToPipe - 3 - id3:{test3_file}:1;13;1;0;',
4742+
f'handleRead - 3 - id3:{test3_file}:1;13;1;0;',
4743+
'writeToPipe - 5 - 0',
4744+
'handleRead - 5 - 0'
4745+
]
4746+
stdout_exp.sort()
4747+
stdout_lines = stdout.splitlines()
4748+
stdout_lines.sort()
4749+
assert stdout_lines == stdout_exp
46604750
assert stderr.splitlines() == []

0 commit comments

Comments
 (0)