Skip to content

Conversation

@patrykstefanski
Copy link

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

@patrykstefanski patrykstefanski self-assigned this Aug 13, 2025
@patrykstefanski patrykstefanski added the clang:bounds-safety Issue relating to the experimental -fbounds-safety feature in Clang label Aug 13, 2025
@patrykstefanski patrykstefanski force-pushed the eng/pstefanski/PR-156006635 branch from 1c9cc8d to f2adef0 Compare August 14, 2025 17:29
@patrykstefanski patrykstefanski force-pushed the eng/pstefanski/PR-156006635 branch from f2adef0 to eee3ae8 Compare August 15, 2025 23:45

sbn_void(sb, n);
sbn_void(sbn, n);
}

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_int and sun_void;
  • passing __counted/sized_by_or_null pointers to std::span
  • passing __counted/sized_by_or_null pointers to the 1st and 2nd parameters of snprintf functions

Copy link
Author

Choose a reason for hiding this comment

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

  • unsafe cases of cbn_int and sun_void;

Added.

  • passing __counted/sized_by_or_null pointers to std::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_null pointers to the 1st and 2nd parameters of snprintf functions

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.

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
@patrykstefanski patrykstefanski force-pushed the eng/pstefanski/PR-156006635 branch from eee3ae8 to dd57b56 Compare September 23, 2025 03:09
Copy link

@ziqingluo-90 ziqingluo-90 left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks!

@patrykstefanski
Copy link
Author

@swift-ci test llvm

@patrykstefanski patrykstefanski merged commit c86fc87 into swiftlang:next Sep 25, 2025
0 of 2 checks passed
@patrykstefanski patrykstefanski deleted the eng/pstefanski/PR-156006635 branch September 25, 2025 21:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:bounds-safety Issue relating to the experimental -fbounds-safety feature in Clang

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants