[PATCH] D139604: [PATCH] Github Issue: Create a check that warns about using %p printf specifier #43453

Gianni Crivello via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 7 22:32:58 PST 2022


giannicrivello created this revision.
giannicrivello added reviewers: NoQ, tbaeder.
giannicrivello added a project: clang.
Herald added subscribers: steakhal, martong.
Herald added a reviewer: sscalpone.
Herald added projects: Flang, All.
giannicrivello requested review of this revision.
Herald added subscribers: cfe-commits, jdoerfert.

Patched llvm-project/clang/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp to account for the user passing a nullptr to the implementation dependent function printf(). Invoked with `bin/scan-build -enable-checker optin.portability bin/clang -g test.cpp` where the contents of test.cpp is:

  c++
  #include <stdio.h>
  #include <stdlib.h>
  
  int main() {
      int *p = nullptr;
      printf("%p", p);
  }

now produces the warning:

  test.cpp:6:5: warning: Passing a null pointer to printf() is implementation dependant. Portability warning [optin.portability.UnixAPI]
      printf("%p", p);
      ^~~~~~~~~~~~~~~
  1 warning generated.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139604

Files:
  clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
  clang/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp
  flang/docs/Extensions.md
  flang/lib/Parser/Fortran-parsers.cpp
  flang/test/Parser/missing-colons.f90

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D139604.481150.patch
Type: text/x-patch
Size: 6030 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221208/292c5d10/attachment.bin>


More information about the cfe-commits mailing list