Skip to content

Check array literals for null terminators. #397

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

Closed
dtarditi opened this issue Oct 17, 2017 · 1 comment
Closed

Check array literals for null terminators. #397

dtarditi opened this issue Oct 17, 2017 · 1 comment
Assignees

Comments

@dtarditi
Copy link
Member

When an array literal is implicitly converted to a null-terminated array pointer type, we need to check that the array literal has a null terminator.

@dtarditi dtarditi changed the title Checked array literals for null terminators. Check array literals for null terminators. Oct 19, 2017
Prabhuk added a commit that referenced this issue Jul 12, 2018
#397
Partial commit.
Added a call to handle NT_CHECKED initializers. If the type of the declaration requires NT_CHECKED, the last item in the initializer list is validated to make sure it is null (nullptr, NULL, 0 or '\0' depending on what's appropriate).

Pending:
1. Handle all types (Constant char arrays are not handled yet.)
2. Tests (Add tests for ptr to NT_CHECKED types, NT_CHECKED array, Struct that contains one or both of the previous two cases)
3. Error handling. The current version of the compiler crashes if the NT_CHECKED array is not null terminated.
@Prabhuk Prabhuk self-assigned this Jul 17, 2018
Prabhuk pushed a commit to checkedc/checkedc that referenced this issue Jul 24, 2018
…#289)

Related Issue: checkedc/checkedc-clang#397

1. Added test cases for possible ways through which _Nt_initializers arrays can be initialized
2. Added negative test cases (e.g. array initializers without null terminators at the end) for which checkedc clang compiler is expected to report errors
Prabhuk pushed a commit that referenced this issue Jul 24, 2018
…#531)

Related Issue: #397

Added a function to validate _Nt_checked type array initializers. 

If the type of the declaration is _Nt_checked, the last item in the initializer list is validated to make sure it is null (nullptr, NULL, 0 or '\0' depending on what's appropriate).

If the type of the initializer is a string literal, the size of the initializer string is validated to be within the size of the _Nt_checked array that is initialized.

If the type of the initializer is record type (struct, typedef struct, union), has _Nt_checked typed field(s) within the initialized data structure, their initializers are validated as well.

Testing:
Added checkedc tests for _Nt_checked initializers.
Automated tests: DevTest Debug X64 Linux, DevTest Debug x64 Windows, DevTest Debug X86 Windows, DevTest Release Linux X64 LNT
@dtarditi
Copy link
Member Author

This work item is complete. @Prabhuk, thanks!

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

No branches or pull requests

2 participants