[clang] [clang][analyzer] Bring checker 'alpha.unix.cstring.NotNullTerminated' out of alpha (PR #113899)

DonĂ¡t Nagy via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 28 06:47:39 PDT 2024


================
@@ -53,3 +53,7 @@ struct TestNotNullTerm {
     strlen((char *)&x); // expected-warning{{Argument to string length function is not a null-terminated string}}
   }
 };
+
+void test_notcstring_tempobject() {
+  strlen((char[]){'a', 0}); // expected-warning{{Argument to string length function is a C++ temp object of type char[2], which is not a null-terminated string}}
+}
----------------
NagyDonat wrote:

To me this result looks like a false positive (I'd guess that this `strlen` call is well-defined and returns 1, but I'm not familiar with the exact rules for C++ temp objects).

If this is indeed a false positive, then either fix it, or add a comment like "FIXME: In this corner case the checker produces a false positive".

If the report is a true positive, then perhaps explain why is it a true positive.

https://github.com/llvm/llvm-project/pull/113899


More information about the cfe-commits mailing list