-
Notifications
You must be signed in to change notification settings - Fork 28
fix: replace String::from_utf16_lossy with String::from_utf16
#568
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -478,13 +478,18 @@ pub unsafe fn auth_data_to_identity_buffers_w( | |
| let auth_data = unsafe { auth_data.as_ref() }.expect("auth_data pointer should not be null"); | ||
|
|
||
| if !auth_data.package_list.is_null() && auth_data.package_list_length > 0 { | ||
| // SAFETY: `package_list` is not null due to a prior check. | ||
| *package_list = Some(String::from_utf16_lossy(unsafe { | ||
| from_raw_parts( | ||
| auth_data.package_list, | ||
| usize::try_from(auth_data.package_list_length).unwrap(), | ||
| *package_list = Some( | ||
| String::from_utf16( | ||
| // SAFETY: `package_list` is not null due to a prior check. | ||
| unsafe { | ||
| from_raw_parts( | ||
| auth_data.package_list, | ||
| usize::try_from(auth_data.package_list_length).unwrap(), | ||
| ) | ||
| }, | ||
| ) | ||
| })); | ||
|
Comment on lines
+481
to
-487
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. nitpick: Thats’ a lot of nested items. We could consider breaking down things a little bit. |
||
| .map_err(Error::from)?, | ||
| ); | ||
| } | ||
|
|
||
| ( | ||
|
|
@@ -1263,18 +1268,21 @@ mod tests { | |
|
|
||
| assert_eq!( | ||
| "user", | ||
| String::from_utf16_lossy(from_raw_parts((*identity).user, (*identity).user_length as usize)) | ||
| String::from_utf16(from_raw_parts((*identity).user, (*identity).user_length as usize)) | ||
| .expect("user is a correct utf-16 string") | ||
| ); | ||
| assert_eq!( | ||
| "pass", | ||
| String::from_utf16_lossy(from_raw_parts( | ||
| String::from_utf16(from_raw_parts( | ||
| (*identity).password, | ||
| (*identity).password_length as usize | ||
| )) | ||
| .expect("password is a correct utf-16 string") | ||
| ); | ||
| assert_eq!( | ||
| "domain", | ||
| String::from_utf16_lossy(from_raw_parts((*identity).domain, (*identity).domain_length as usize)) | ||
| String::from_utf16(from_raw_parts((*identity).domain, (*identity).domain_length as usize)) | ||
| .expect("domain is a correct utf-16 string") | ||
| ); | ||
|
|
||
| let status = SspiFreeAuthIdentity(identity as *mut _); | ||
|
|
||
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
nitpick:
?should already insert the glue code for the From conversion.note: I highly recommend we don’t
use some::Resultoruse some::Errorbecause the naming is confusing at usage sites. I.e.: for clarity, I think it’s better to use explicitsspi::Resultandsspi::Errorso we have minimal context when reading the code. (This is the suggested style in IronRDP.)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.
🤔
Yes, you are right. I do not know why I added it. There may have been a type inference issue at some point, and I forgot to clean up the code afterward.