-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Disallow explicit cast to nt_array_ptr in checked scopes (#391) #626
Disallow explicit cast to nt_array_ptr in checked scopes (#391) #626
Conversation
Disallow cast from other checked pointer types to nt_array_ptr in checked scopes because the source pointer might not point to a NULL_terminated array. Casting from an unchecked pointer to a nt_array_ptr pointer should also be prohibited; this has already been handled as no unchecked pointers are allowed in checked scopes. Also added a new error message in clang/include/clang/Basic/DiagnosticSemaKinds.td for casting to nt_array_ptr in checked scopes. The test file tests/typechecking/checked_scope_basic.c was updated with a new function test_cast_to_nt_array_ptr to test casting to nt_array_ptr.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks - I think the code could be cleaned up a bit by using an existing helper function to test for whether a type is an nt_array_ptr type.
lib/Sema/SemaCast.cpp
Outdated
// Disallow cast from other Checked Pointer types to nt_arary_ptr because | ||
// the SrcType might not point to a NULL-terminated array. | ||
if (DestType->isPointerType()) { | ||
if (cast<PointerType>(DestType)->getKind() == CheckedPointerKind::NtArray) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you use the function isCheckedPointerNtArrayType
for testing whether a type is or is not an nt_array_ptr type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have updated the code as suggested.
In the code that disallows casting to nt_array_ptr in a checked scope, we can use an exsiting helper function isCheckedPointerNtArrayType() to test whether a pointer type is nt_array_ptr. This makes the code a little bit cleaner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good - thanks!
Cherry-picked from commit e13fcff Disallow cast from other checked pointer types to nt_array_ptr in checked scopes because the source pointer might not point to a NULL_terminated array. Casting from an unchecked pointer to a nt_array_ptr pointer should also be prohibited; this has already been handled as no unchecked pointers are allowed in checked scopes. Also added a new error message in clang/include/clang/Basic/DiagnosticSemaKinds.td for casting to nt_array_ptr in checked scopes. The test file tests/typechecking/checked_scope_basic.c was updated with a new function test_cast_to_nt_array_ptr to test casting to nt_array_ptr.
…indows. (#626) * Fix escaping bugs that currently affect the JSON formatting test on Windows. Other escaping bugs may remain; #620 is to fix all of them. Fixes #619. * Add test of a backslash in a file path on Linux and Mac OS X. While I'm here, fix a typo in the name of json_formating.c and add `--` to its `3c` command lines.
Disallow cast from other checked pointer types to nt_array_ptr in
checked scopes because the source pointer might not point to a
NULL_terminated array. Casting from an unchecked pointer to a
nt_array_ptr pointer should also be prohibited; this has already been
handled as no unchecked pointers are allowed in checked scopes.
Also added a new error message in
clang/include/clang/Basic/DiagnosticSemaKinds.td for casting to
nt_array_ptr in checked scopes.
The test file tests/typechecking/checked_scope_basic.c was updated
with a new function test_cast_to_nt_array_ptr to test
casting to nt_array_ptr.
The change passed the new test code and the regression tests for
checkedc and clang.