-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Fix SubText ctor parameter verification. #78989
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,9 +22,9 @@ public SubText(SourceText text, TextSpan span) | |
| throw new ArgumentNullException(nameof(text)); | ||
| } | ||
|
|
||
| // span.Start and span.End are valid wrt eachother by nature of being passed in as a TextSpan, | ||
| // so there is no need to verify span.Start against text.Length or span.End against zero. | ||
|
Member
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. I don't follow how this is true. I can absolutely construct a bad
Member
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. a textspan itself prevents the end from being before the start. so a text span's start/end always represent at least a legal range where end >= start. given that. you only ened to validate that the start of this text span is not before the start of the text, and the end of the text span is not after the end of the text.
Member
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. Thanks for the clarification!
Contributor
Author
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. In that case I might need to change this. I'm curious as to what mechanism would allow creation of the object such that the TextSpan ctor lets the object creation proceed while violating these constraints. Is it through serialization which sets the backing Start/Length properties through reflection? *** Edit: this comment was made before I saw Cyrus's response |
||
| if (span.Start < 0 | ||
| || span.Start >= text.Length | ||
| || span.End < 0 | ||
| || span.End > text.Length) | ||
| { | ||
| throw new ArgumentOutOfRangeException(nameof(span)); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.