[PATCH] D89055: [analyzer] Wrong type cast occures during pointer dereferencing after type punning

Balázs Benics via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Oct 10 07:06:53 PDT 2020


steakhal added a comment.

If you don't mind I would also request some credit in the summary since I've spent some time on this as well.
Besides that I don't have much objection about this patch. It's defenately not my expertiese.
Good job coming up with the fix though, I had to focus on other things.



================
Comment at: clang/test/Analysis/string.c:367-373
+void *func_strcpy_no_assertion();
+char ***ptr_strcpy_no_assertion;
+void strcpy_no_assertion() {
+  *(unsigned char **)ptr_strcpy_no_assertion = (unsigned char *)(func_strcpy_no_assertion());
+  char c;
+  strcpy(**ptr_strcpy_no_assertion, &c); // no-assertion
+}
----------------
I would prefer slightly more readbale names.
`func_strcpy_no_assertion()` -> `get_void_ptr()`
`ptr_strcpy_no_assertion ` -> `type_punned_ptr`
`no-assertion` -> `no-crash`
You could also hoist the `char a` as a function parameter to spare a line :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89055



More information about the cfe-commits mailing list