-
Notifications
You must be signed in to change notification settings - Fork 351
[-Wunsafe-buffer-usage] Relax passing to __counted_by_or_null() #11170
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
[-Wunsafe-buffer-usage] Relax passing to __counted_by_or_null() #11170
Conversation
clang/test/SemaCXX/warn-unsafe-buffer-usage-count-attributed-pointer-argument.cpp
Outdated
Show resolved
Hide resolved
1c9cc8d to
f2adef0
Compare
clang/test/SemaCXX/warn-unsafe-buffer-usage-count-attributed-pointer-argument.cpp
Outdated
Show resolved
Hide resolved
f2adef0 to
eee3ae8
Compare
|
|
||
| sbn_void(sb, n); | ||
| sbn_void(sbn, n); | ||
| } |
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 we add more tests:
- unsafe cases of
cbn_intandsun_void; - passing
__counted/sized_by_or_nullpointers tostd::span - passing
__counted/sized_by_or_nullpointers to the 1st and 2nd parameters ofsnprintffunctions
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.
- unsafe cases of
cbn_intandsun_void;
Added.
- passing
__counted/sized_by_or_nullpointers tostd::span
Added and those can be imho allowed, since std::span constructor checks for size being 0 if the pointer is nullptr.
- passing
__counted/sized_by_or_nullpointers to the 1st and 2nd parameters ofsnprintffunctions
Added a few tests for snprintf and friends if they are annotated. For the unannotated snprintf, right now passing __counted_by_or_null() is allowed, but probably shouldn't. WDYT? In any case, we could fix this in another PR.
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.
According to cppreference snprintf, it is ok to pass nullptr to snprintf as long as size is 0. So we are good.
Relax restrictions when passing to __counted_by_or_null()/__sized_by_or_null() parameters: - Allow the dependent count var to be anything. - Allow passing from non-null variant to *_or_null(), but do warn for passing *_or_null() to non-null variant. rdar://156006635
eee3ae8 to
dd57b56
Compare
ziqingluo-90
left a comment
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.
LGTM! Thanks!
|
@swift-ci test llvm |
Relax restrictions when passing to
__counted_by_or_null()/__sized_by_or_null() parameters:
rdar://156006635