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.