[PATCH] D154838: [analyzer] Add check for null pointer passed to %p of printf family

Georgiy Lebedev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 29 04:28:59 PDT 2023


CuriousGeorgiy updated this revision to Diff 554259.
CuriousGeorgiy marked 2 inline comments as done.
CuriousGeorgiy added a comment.
Herald added a subscriber: ormris.

[analyzer] Add check for null pointer passed to the %p of printf family

The result of passing a null pointer to the pointer conversion specifier of
printf family of functions is implementation defined — for instance, on
Windows zeros are printed, whilst on Linux '(nil)' is printed.

The problem described above is a minor portability issue, so we don't just
add a check for to the existing Unix API checker, since it would be
desirable to be able to disable it.

Instead, to collect such checks we add a new APIPortabilityMinor checker to
the alpha.unix package with a check for the problem described above.

The check assumes that a null pointer is only passed to a pointer
conversion specifier, otherwise it would be undefined behaviour. By making
this assumption we do not have to check the format string and match data
arguments to conversion specifiers.

Closes #43453

Differential Revision: https://reviews.llvm.org/D154838


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154838/new/

https://reviews.llvm.org/D154838

Files:
  clang/docs/analyzer/checkers.rst
  clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
  clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
  clang/lib/StaticAnalyzer/Checkers/UnixAPIPortabilityMinorChecker.cpp
  clang/test/Analysis/unix-api-portability-minor.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154838.554259.patch
Type: text/x-patch
Size: 13392 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230829/4f567bff/attachment-0001.bin>


More information about the cfe-commits mailing list