Repository navigation
Fix cppcheck 2.19 findings - #124
Merged
Merged
Conversation
The cppcheck job has been failing since ubuntu-latest moved to Ubuntu 26.04, which ships cppcheck 2.19 instead of 2.13. It reports 112 findings on master: - syntaxError in ppd-generator.c: the workflow passed -DVERSION=2.x.y without quotes, so "..." VERSION "..." string concatenation did not parse. Quote it, as cups-browsed already does. - dangerousTypeCast (58), a check new in 2.19, for the C-style casts in the C++ code that comes from CUPS (the PPD compiler, genstrings, ppdhtml, ppdpo and ppd-collection.cxx). Suppress it in the workflow, in line with how findings in the CUPS-derived code are already handled there, instead of rewriting the casts. - nullPointerOutOfResources (33) for unchecked tmpfile() results in the unit tests, and nullPointerOutOfMemory in testppd.c. Check them and fail the test. - intToPointerCast (10) for the (ppd_file_t *)1 placeholder that the argument-check tests pass as a non-NULL PPD. Pass the address of a static dummy ppd_file_t instead. - nullPointerOutOfMemory in ppdFilterLoadPPDFile(): the calloc() of the "libppd" filter data extension was not checked. Log an error, close the PPD and return -1, like the PPD loading failure above it. - uninitvar (3), false positives for "if ((s.field = f()) == NULL)" on a partly initialized struct in ppdFilterCUPSWrapper(), ppdFindMarkedChoice() and ppdIsMarked(). Moving the assignment out of the condition avoids them without a suppression. With this, cppcheck 2.19 and 2.13 run with the CI job's options report nothing. The build and "make check" still pass.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The cppcheck job is failing on master. No code change caused it:
ubuntu-latestmoved to Ubuntu 26.04, which installs cppcheck 2.19 instead of 2.13 (the same thing that broke cups-browsed, fixed in OpenPrinting/cups-browsed#87). On master, 2.19 reports 112 findings.ppd-generator.c: the workflow passed-DVERSION=2.x.ywithout quotes, so"..." VERSION "..."didn't parse and cppcheck skipped the file. It's quoted now, as cups-browsed already does.genstrings,ppdhtml,ppdpo,ppd-collection.cxx). The workflow already suppresses findings in CUPS-derived code to keep it identical to upstream, so this check is suppressed there too (with a comment) instead of rewriting 58 casts.tmpfile()results, pluscalloc()/strdup()intestppd.c. Each is now checked and fails the test.(ppd_file_t *)1as a non-NULL PPD. They now pass the address of a static dummyppd_file_t.ppdFilterLoadPPDFile(): thecalloc()of the "libppd" filter data extension wasn't checked. It now logs an error, closes the PPD and returns -1, like the load failure just above it.if ((s.field = f()) == NULL)on a partly initialized struct inppdFilterCUPSWrapper(),ppdFindMarkedChoice()andppdIsMarked(). Moving the assignment out of the condition avoids them without a suppression.I didn't pin the runner back to 24.04, because that would only hide the findings.
Testing: I ran the exact cppcheck command from
.github/workflows/cppcheck.ymlin containers. Inubuntu:26.04(2.19), master exits 1 with 112 findings (the same list as the failing CI run) and this branch exits 0. Inubuntu:24.04(2.13), this branch also exits 0. The build succeeds with no new warnings, andmake checkpasses 14/14, as on master.