Disallow explicit cast to nt_array_ptr in checked scopes (#391)#626
Merged
dtarditi merged 2 commits intocheckedc:masterfrom Jul 18, 2019
jiezhoucs:issue-391-cast-to-nt_array
Merged
Disallow explicit cast to nt_array_ptr in checked scopes (#391)#626dtarditi merged 2 commits intocheckedc:masterfrom jiezhoucs:issue-391-cast-to-nt_array
dtarditi merged 2 commits intocheckedc:masterfrom
jiezhoucs:issue-391-cast-to-nt_array
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.
dtarditi
reviewed
Jul 9, 2019
Member
dtarditi
left a comment
There was a problem hiding this comment.
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) { |
Member
There was a problem hiding this comment.
Could you use the function isCheckedPointerNtArrayType for testing whether a type is or is not an nt_array_ptr type?
Contributor
Author
There was a problem hiding this comment.
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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.