Skip to content

Fix #15010: ErrorLogger: do not open and read from files unless necessary - #8826

Merged
ludviggunne merged 6 commits into
cppcheck-opensource:mainfrom
ludviggunne:15010-redundant-read
Sep 7, 2026
Merged

Fix #15010: ErrorLogger: do not open and read from files unless necessary#8826
ludviggunne merged 6 commits into
cppcheck-opensource:mainfrom
ludviggunne:15010-redundant-read

Conversation

@ludviggunne

@ludviggunne ludviggunne commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator

Not exactly sure how to test the number of times the file is read.
I was thinking of adding a test under test/scripts using strace, but I'm not sure how robust it would be.

@ludviggunne
ludviggunne marked this pull request as draft September 4, 2026 12:32
@ludviggunne

Copy link
Copy Markdown
Collaborator Author

Before this change:

$ strace --trace=openat --trace-path=zerodiv.c --follow-forks ./cppcheck --suppress=zerodiv zerodiv.c
Checking zerodiv.c ...
openat(AT_FDCWD, "zerodiv.c", O_RDONLY) = 3
openat(AT_FDCWD, "zerodiv.c", O_RDONLY) = 3
openat(AT_FDCWD, "zerodiv.c", O_RDONLY) = 3
openat(AT_FDCWD, "zerodiv.c", O_RDONLY) = 3
openat(AT_FDCWD, "zerodiv.c", O_RDONLY) = 3
+++ exited with 0 +++

After this change:

$ strace --trace=openat --trace-path=zerodiv.c --follow-forks ./cppcheck --suppress=zerodiv zerodiv.c
zerodiv.c"
Checking zerodiv.c ...
openat(AT_FDCWD, "zerodiv.c", O_RDONLY) = 3
+++ exited with 0 +++

@ludviggunne
ludviggunne marked this pull request as ready for review September 4, 2026 14:31
@danmar

danmar commented Sep 5, 2026

Copy link
Copy Markdown
Collaborator

I was thinking of adding a test under test/scripts using strace, but I'm not sure how robust it would be.

Imho, such a test in test/cli that uses strace would be great. I guess it can be added in the other_test.py. It could test with --suppress , --xml and --template=cppcheck1 .. each of those options should mean the file is only opened once.

so I guess it will only run in linux but that is OK.

@MartinBP

MartinBP commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

The timeout in this test can most likely also be reduced togther with this change.

def test_large_number_of_violations_and_suppressions(tmpdir):

Comment thread test/cli/other_test.py
Comment thread test/cli/other_test.py

@danmar danmar left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assuming CI will be happy I approve this.

@ludviggunne
ludviggunne merged commit c976cac into cppcheck-opensource:main Sep 7, 2026
71 checks passed
@ludviggunne
ludviggunne deleted the 15010-redundant-read branch September 7, 2026 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants