C++: Add some test cases for cpp/wrong-type-format-argument by geoffw0 · Pull Request #21421 · github/codeql
There are two size_t types in the database, both are typedefs but only one is a typedef to an integral type as we would expect. I think this fits the theory that the definition of myFunctionPointerType is somehow creating an alternative size_t typedef type.
But which type does the variable "s" have? ... it looks like there is no Variable "s" extracted in the database. I only see variables "buffer" and "format" in this file. Thus, there are also no VariableAccesses to "s" in the printf calls, I see FunctionAccesses instead, understandably with function types. This seems to be the direct cause of the spurious results I'm seeing.
If I take the definition of myFunctionPointerType away, the variable "s" then exists with an error type, and it looks like we then don't extract the access to "s" at all (which means we don't get erroneous query results).
So I think we have two paths available to fixing this:
- fix the extraction of
myFunctionPointerTypeso that it doesn't spuriously generate asize_ttypedef, perhaps by simply erroring on this line. This approach has the upside of potentially resolving other related issues. - patch the query to ignore arguments that are accesses to functions with an erroneous type (or just: that are function accesses). This approach has the advantage of being simple and immediate.