Skip to content

C++: Add some test cases for cpp/wrong-type-format-argument#21421

Open
geoffw0 wants to merge 3 commits intogithub:mainfrom
geoffw0:wrongtypeformat
Open

C++: Add some test cases for cpp/wrong-type-format-argument#21421
geoffw0 wants to merge 3 commits intogithub:mainfrom
geoffw0:wrongtypeformat

Conversation

@geoffw0
Copy link
Contributor

@geoffw0 geoffw0 commented Mar 6, 2026

Add some test cases for cpp/wrong-type-format-argument, showing how we can apparently mistake size_t for a function pointer type in some circumstances. This is based on an issue I've seen in the wild (in a build-mode-none database).

The typedef for myFunctionPointerType is a compiler error as written, but we're simulating a situation where the definition of size_t is present, but invisible to the extractor due to BMN. I think the underlying issue may be something to do with how we handle this error case - though there are a few ways the problem could be addressed in the query if necessary.

Note that the query is very permissive, amongst other things it already allows integer signed-ness mismatches - so I'm of the opinion that using %zu for a signed size_t should not be flagged. Regardless, the message claiming the size_t is type ..(*)(..) is a problem, unless I'm missing something here.

@geoffw0 geoffw0 requested a review from a team as a code owner March 6, 2026 12:07
@geoffw0 geoffw0 added C++ no-change-note-required This PR does not need a change note labels Mar 6, 2026
Copilot AI review requested due to automatic review settings March 6, 2026 12:07
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds new test coverage for cpp/wrong-type-format-argument to reproduce/track a build-mode-none-style failure mode where size_t can be misinterpreted (e.g., as a function pointer type) and yields nonsensical alert messages.

Changes:

  • Adds a buildless-style repro involving size_t and printf format specifiers.
  • Updates the expected test output for WrongTypeFormatArguments accordingly.
  • Adds supporting buildless test inputs to exercise the extractor/query behavior under errors.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

Show a summary per file
File Description
cpp/ql/test/query-tests/Likely Bugs/Format/WrongTypeFormatArguments/Buildless/second.cpp New/updated repro that exercises the size_t mis-typing scenario in a buildless/error-tolerant extraction context.
cpp/ql/test/query-tests/Likely Bugs/Format/WrongTypeFormatArguments/Buildless/first.cpp Provides a plausible size_t typedef for the multi-TU scenario.
cpp/ql/test/query-tests/Likely Bugs/Format/WrongTypeFormatArguments/Buildless/tests.c Additional buildless/error-handling coverage for format argument typing.
cpp/ql/test/query-tests/Likely Bugs/Format/WrongTypeFormatArguments/Buildless/tests2.c Additional wrapper/multiple-definition scenario coverage.
cpp/ql/test/query-tests/Likely Bugs/Format/WrongTypeFormatArguments/Buildless/WrongTypeFormatArguments.expected Updates expected alerts to capture the reproduced behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C++ no-change-note-required This PR does not need a change note

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants