[PATCH] D60281: [analyzer] Add docs for cplusplus.InnerPointer

Reka Kovacs via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 4 12:26:54 PDT 2019


rnkovacs created this revision.
rnkovacs added reviewers: NoQ, xazax.hun, Szelethus, dcoughlin, dkrupp.
Herald added subscribers: cfe-commits, Charusso, gamesh411, donat.nagy, mikhail.ramalho, a.sidorin, szepet, baloghadamsoftware, whisperity.
Herald added a project: clang.

Tried to pick two interesting examples from the tests.
This check has no options.


Repository:
  rC Clang

https://reviews.llvm.org/D60281

Files:
  docs/analyzer/checkers.rst


Index: docs/analyzer/checkers.rst
===================================================================
--- docs/analyzer/checkers.rst
+++ docs/analyzer/checkers.rst
@@ -216,10 +216,34 @@
 
 C++ Checkers.
 
-cplusplus.InnerPointer
-""""""""""""""""""""""
+cplusplus.InnerPointer (C++)
+""""""""""""""""""""""""""""
 Check for inner pointers of C++ containers used after re/deallocation.
 
+In its present state, the check detects incorrect uses of raw inner pointers of
+``std::string``s, by recognizing member functions that may re/deallocate the buffer
+before use. In the future, it would be great to add support for other STL and
+non-STL containers, and most notably, ``std::string_view``s.
+
+.. code-block:: cpp
+
+ void consume(const char *);
+
+ void test_deref_after_equals() {
+   std::string s = "llvm";
+   const char *c = s.data(); // note: pointer to inner buffer of 'std::string' obtained here
+   s = "clang"; // note: inner buffer of 'std::string' reallocated by call to 'operator='
+   consume(c); // warn: inner pointer of container used after re/deallocation
+ }
+
+ const char *test_return_temp() {
+   int x;
+   return std::to_string(x).c_str(); // warn: inner pointer of container used after re/deallocation
+   // note: pointer to inner buffer of 'std::string' obtained here
+   // note: inner buffer of 'std::string' deallocated by call to destructor
+ }
+
+
 cplusplus.NewDelete (C++)
 """""""""""""""""""""""""
 Check for double-free and use-after-free problems. Traces memory managed by new/delete.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D60281.193762.patch
Type: text/x-patch
Size: 1527 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190404/9516aa90/attachment.bin>


More information about the cfe-commits mailing list