Skip to content
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

fix: Stop lonely hyphens from causing panic #411

Merged
merged 1 commit into from
Feb 4, 2016
Merged

fix: Stop lonely hyphens from causing panic #411

merged 1 commit into from
Feb 4, 2016

Conversation

cite-reader
Copy link
Contributor

The method starts_with as implemented for the OsStrExt2 trait on
OsStr assumed that the needle given is shorter than the haystack. When
this is not the case, the method panics due to an attempted
out-of-bounds access on the byte representation of self. Problematic
if, say, an end-user gives us "-" and the library tries to see if that
starts with "--".

Fortunately, slices already implement a starts_with method, and we can
delegate to it.

This does create a semantics change: if both self and the needle
have length 0, this implementation will return true, but the old
implementation would return false. Based on the test suite still
passing, acknowledging the vacuous truth doesn't seem to cause any
problems.

Fixes #410

The method `starts_with` as implemented for the `OsStrExt2` trait on
`OsStr` assumed that the needle given is shorter than the haystack. When
this is not the case, the method panics due to an attempted
out-of-bounds access on the byte representation of `self`. Problematic
if, say, an end-user gives us `"-"` and the library tries to see if that
starts with `"--"`.

Fortunately, slices already implement a `starts_with` method, and we can
delegate to it.

This *does* create a semantics change: if both `self` and the needle
have length 0, this implementation will return `true`, but the old
implementation would return `false`. Based on the test suite still
passing, acknowledging the vacuous truth doesn't seem to cause any
problems.

Fixes #410
@yo-bot
Copy link

yo-bot commented Feb 3, 2016

Thanks for the pull request, and welcome! The team is excited to review your changes, and you should hear from @kbknapp (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@kbknapp
Copy link
Member

kbknapp commented Feb 4, 2016

Looks great, thanks!

I'll add your name to #389

@homu r+

@homu
Copy link
Contributor

homu commented Feb 4, 2016

📌 Commit 85b1146 has been approved by kbknapp

homu added a commit that referenced this pull request Feb 4, 2016
fix: Stop lonely hyphens from causing panic

The method `starts_with` as implemented for the `OsStrExt2` trait on
`OsStr` assumed that the needle given is shorter than the haystack. When
this is not the case, the method panics due to an attempted
out-of-bounds access on the byte representation of `self`. Problematic
if, say, an end-user gives us `"-"` and the library tries to see if that
starts with `"--"`.

Fortunately, slices already implement a `starts_with` method, and we can
delegate to it.

This *does* create a semantics change: if both `self` and the needle
have length 0, this implementation will return `true`, but the old
implementation would return `false`. Based on the test suite still
passing, acknowledging the vacuous truth doesn't seem to cause any
problems.

Fixes #410
homu added a commit that referenced this pull request Feb 4, 2016
fix: Stop lonely hyphens from causing panic

The method `starts_with` as implemented for the `OsStrExt2` trait on
`OsStr` assumed that the needle given is shorter than the haystack. When
this is not the case, the method panics due to an attempted
out-of-bounds access on the byte representation of `self`. Problematic
if, say, an end-user gives us `"-"` and the library tries to see if that
starts with `"--"`.

Fortunately, slices already implement a `starts_with` method, and we can
delegate to it.

This *does* create a semantics change: if both `self` and the needle
have length 0, this implementation will return `true`, but the old
implementation would return `false`. Based on the test suite still
passing, acknowledging the vacuous truth doesn't seem to cause any
problems.

Fixes #410
@homu
Copy link
Contributor

homu commented Feb 4, 2016

⌛ Testing commit 85b1146 with merge 355a5fd...

@homu
Copy link
Contributor

homu commented Feb 4, 2016

☀️ Test successful - status

@homu homu merged commit 85b1146 into clap-rs:master Feb 4, 2016
@cite-reader cite-reader deleted the hyphen-doesnt-panic branch February 4, 2016 19:06
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

Successfully merging this pull request may close these issues.

4 participants