-
Notifications
You must be signed in to change notification settings - Fork 184
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
Fixes for errors in the "array_ptr" interfaces to some libc functions declared in checkedc_extensions.h, and removal of the conditional in the snprintf declaration in stdio_checked.h #456
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1976224
Modified some of the Checked-C-specific declarations of libc functions
sulekhark 65cf998
Missed adding the modified header files.
sulekhark 803d67e
Added the _Where clause to more closely resemble the snprintf declara…
sulekhark 0a96348
Improvements to the test case.
sulekhark 6379dce
Incorporated review comments.
sulekhark 8926440
Merge branch 'master' into issues_449_450
sulekhark File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Tests for calling functions declared in checkedc_extensions.h | ||
// | ||
// The following lines are for the LLVM test harness: | ||
// | ||
// RUN: %clang -o %t.exe %s %checkedc_target_flags | ||
// RUN: %checkedc_rununder %t.exe | ||
|
||
// expected-no-diagnostics | ||
|
||
#pragma CHECKED_SCOPE on | ||
|
||
#include <stddef.h> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can these headers be listed alphabetically? |
||
#include <checkedc_extensions.h> | ||
#include <stdio.h> | ||
|
||
// A function with an interface similar to snprintf but without the variable | ||
// number of arguments. The purpose is to test such a call interface in checked | ||
// scope. | ||
void iface(char * restrict s : itype(restrict _Nt_array_ptr<char>) count(n-1), | ||
size_t n _Where n > 0, | ||
const char * restrict src : itype(restrict _Nt_array_ptr<const char>)) { | ||
return; | ||
} | ||
|
||
|
||
void iface_array_ptr(char * restrict s : itype(restrict _Array_ptr<char>) count(n), | ||
size_t n, | ||
const char * restrict src : itype(restrict _Array_ptr<const char>)) { | ||
// Enclosing the call to iface in an unchecked block to be able to pass an | ||
// argument of type _Array_ptr<char> and bounds count(n) whose corresponding | ||
// parameter has the interface type _Nt_array_ptr<char> and bounds count(n-1). | ||
// This avoids the compiler error: passing '_Array_ptr<char> restrict' to | ||
// parameter of incompatible type '_Nt_array_ptr<char>'. | ||
_Unchecked{ iface(s, n, src); } | ||
} | ||
|
||
|
||
|
||
void iface_test1(_Array_ptr<char> p : count(len), size_t len) { | ||
|
||
char buf _Checked[50]; | ||
iface_array_ptr(buf, 50, "Hello world"); | ||
iface_array_ptr(buf, 0, "Hello world"); | ||
|
||
iface_array_ptr(p, len, "Hello world"); | ||
iface_array_ptr(p, 0, "Hello world"); | ||
} | ||
|
||
void iface_test2(_Nt_array_ptr<char> p : count(len), size_t len) { | ||
char buf _Nt_checked[50]; | ||
iface(buf, 50, "Hello world"); | ||
|
||
iface(p, len + 1, "Hello world"); | ||
} | ||
|
||
void test3(_Array_ptr<char> buf : count(len), size_t len) { | ||
_Unchecked{ snprintf_array_ptr(buf, len, "Hello world - 3"); } | ||
} | ||
|
||
int main(void) { | ||
char buf _Checked[50]; | ||
test3(buf, 50) ; | ||
char buf1 _Checked[50]; | ||
test3(buf1, 50) ; | ||
int res = strncmp_array_ptr(buf, buf1, 50); | ||
_Unchecked {printf("res: %d buf: %s buf1: %s\n", res, buf, buf1);} | ||
} |
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.
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.
Can these headers be listed alphabetically?