Skip to content

Fix cppcheck 2.19 findings - #124

Merged
tillkamppeter merged 1 commit into
OpenPrinting:masterfrom
rue19:fix-cppcheck-2.19
Nov 24, 2026
Merged

tillkamppeter merged 1 commit into
OpenPrinting:masterfrom
rue19:fix-cppcheck-2.19

Conversation

@rue19

@rue19 rue19 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

The cppcheck job is failing on master. No code change caused it: ubuntu-latest moved 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.

  • syntaxError in ppd-generator.c: the workflow passed -DVERSION=2.x.y without quotes, so "..." VERSION "..." didn't parse and cppcheck skipped the file. It's quoted now, as cups-browsed already does.
  • dangerousTypeCast (58), a check new in 2.19. It flags the C-style casts in the C++ code that comes from CUPS (PPD compiler, 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.
  • nullPointerOutOfResources / nullPointerOutOfMemory (35) in the unit tests: unchecked tmpfile() results, plus calloc()/strdup() in testppd.c. Each is now checked and fails the test.
  • intToPointerCast (10): the argument-check tests passed (ppd_file_t *)1 as a non-NULL PPD. They now pass the address of a static dummy ppd_file_t.
  • nullPointerOutOfMemory in ppdFilterLoadPPDFile(): the calloc() 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.
  • 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.

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.yml in containers. In ubuntu:26.04 (2.19), master exits 1 with 112 findings (the same list as the failing CI run) and this branch exits 0. In ubuntu:24.04 (2.13), this branch also exits 0. The build succeeds with no new warnings, and make check passes 14/14, as on master.

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.
@tillkamppeter
tillkamppeter merged commit 2c5d305 into OpenPrinting:master Nov 24, 2026
15 checks passed
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.

2 participants