Skip to content
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

Merged
merged 2 commits into from
Jul 18, 2019
Merged

Disallow explicit cast to nt_array_ptr in checked scopes (#391) #626

merged 2 commits into from
Jul 18, 2019

Conversation

jiezhoucs
Copy link
Contributor

@jiezhoucs jiezhoucs commented Jul 9, 2019

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.

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.
Copy link
Member

@dtarditi dtarditi left a 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.

// 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) {
Copy link
Member

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?

Copy link
Contributor Author

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.
Copy link
Member

@dtarditi dtarditi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good - thanks!

@dtarditi dtarditi merged commit e13fcff into checkedc:master Jul 18, 2019
mgrang pushed a commit that referenced this pull request Sep 27, 2019
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.
sulekhark pushed a commit that referenced this pull request Jul 8, 2021
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants