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

More Robust Null Terminator Handling #52

Merged
merged 1 commit into from Oct 11, 2020
Merged

More Robust Null Terminator Handling #52

merged 1 commit into from Oct 11, 2020

Conversation

bigmstone
Copy link
Contributor

@bigmstone bigmstone commented Oct 9, 2020

In most recent SteamVR beta OpenXR calls can return values with multiple
null terminators. This will cause the existing solution to remove only
the final terminator. This commit adds a more robust check to truncate
on the first occurrence of null terminator.

Closes #47

Copy link
Owner

@Ralith Ralith left a comment

Choose a reason for hiding this comment

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

Steam too, now? Argh. Thanks.

openxr/src/lib.rs Outdated Show resolved Hide resolved
@bigmstone
Copy link
Contributor Author

bigmstone commented Oct 9, 2020

@Ralith this wasn't historically a problem (for me) but started in SteamVR beta 1.15.2

@bigmstone bigmstone requested a review from Ralith October 10, 2020 00:20
// Strip null byte
bytes.truncate(bytes.len() - 1);
// Truncate at first null byte
let first_nt = bytes.iter().position(|&x| x == 0).expect("missing null");
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
let first_nt = bytes.iter().position(|&x| x == 0).expect("missing null");
let first_nt = bytes.iter().rposition(|&x| x != 0).expect("missing null") + 1;

Makes more sense to search from the end.

In most recent SteamVR beta OpenXR calls can return values with multiple
null terminators. This will cause the existing solution to remove only
the final terminator. This commit adds a more robust check to truncate
on the first occurrence of null terminator.
Copy link
Owner

@Ralith Ralith left a comment

Choose a reason for hiding this comment

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

Thanks!

@Ralith Ralith merged commit 091e291 into Ralith:master Oct 11, 2020
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.

get_str doesn't reliably strip null bytes
2 participants