[PATCH] D140968: [clang-tidy] Add check for passing the result of `std::string::c_str` to `strlen`

Eugene Zelenko via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 4 07:00:25 PST 2023


Eugene.Zelenko added inline comments.


================
Comment at: clang-tools-extra/clang-tidy/readability/StrlenStringCStrCheck.cpp:1
+//===- StrlenStringCStrCheck.cpp - Check for strlen(string::c_str()) calls
+//-----===//
----------------
Please make it single string.


================
Comment at: clang-tools-extra/clang-tidy/readability/StrlenStringCStrCheck.cpp:35
+      cxxMethodDecl(MethodNameMatcher,
+                    ofClass(cxxRecordDecl(hasName("::std::basic_string"))))));
+  const auto StrlenCall =
----------------
What about `std::basic_string_view`? Or any class with `c_str/data/length/size`?


================
Comment at: clang-tools-extra/clang-tidy/readability/StrlenStringCStrCheck.cpp:66
+} // namespace clang
\ No newline at end of file

----------------
Please fix.


================
Comment at: clang-tools-extra/docs/ReleaseNotes.rst:135
+
+Warns when the return value of `std::basic_string::c_str` or `std::basic_string::data`
+is used as the argument for `strlen`, and suggests a fix.
----------------
Please use double back-ticks for language constructs.


================
Comment at: clang-tools-extra/docs/clang-tidy/checks/readability/strlen-string-cstr.rst:6
+
+Finds calls to ``strlen`` and similar functions where the result
+of ``std::basic_string::c_str`` or ``std::basic_string::data`` is used
----------------
Please make it same as statement in Release Notes.


================
Comment at: clang-tools-extra/docs/clang-tidy/checks/readability/strlen-string-cstr.rst:30
+    ``std::basic_string::data`` is used as an argument for ``strlen``.
\ No newline at end of file

----------------
Please fix.


================
Comment at: clang-tools-extra/test/clang-tidy/checkers/readability/strlen-string-cstr.cpp:61
+}
\ No newline at end of file

----------------
Please fix.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140968



More information about the cfe-commits mailing list