[PATCH] D70823: [clang-tidy] Adding cert-pos34-c check

Zurab Tsinadze via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 5 09:57:08 PST 2019


zukatsinadze marked an inline comment as done.
zukatsinadze added inline comments.


================
Comment at: clang-tools-extra/clang-tidy/cert/PutenvWithAutoCheck.cpp:27
+                  hasAutomaticStorageDuration(),
+                  unless(hasDescendant(callExpr(callee(functionDecl(hasAnyName(
+                      "::alloc", "::malloc", "::realloc", "::calloc")))))))))))
----------------
aaron.ballman wrote:
> I don't know that this is sufficient for the check, and I sort of think this may need to be implemented by the static analyzer rather than clang-tidy. The initialization of the variable is going to be control flow sensitive. Consider something like:
> ```
> void foo(void) {
>   char *buffer = "huttah!";
>   if (rand() % 2 == 0) {
>     buffer = malloc(5);
>     strcpy(buffer, "woot");
>   }
>   putenv(buffer);
> }
> 
> void bar(void) {
>   char *buffer = malloc(5);
>   strcpy(buffer, "woot");
> 
>   if (rand() % 2 == 0) {
>     free(buffer);
>     buffer = "blah blah blah";
>   }
>   putenv(buffer);
> }
> ```
Yes, I see your point. I will try to rewrite it as SA checker. 
Thanks for the review.


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

https://reviews.llvm.org/D70823





More information about the cfe-commits mailing list