wchar: remove panic() and give a best-effort version of the broken string, in worst case an empty string#19
Open
haakonnessjoen wants to merge 1 commit intosstallion:masterfrom
Open
Conversation
…n worst case an empty string
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
We have experienced some usb devices where for example the serial number have been garbled by a firmware bug, so the serial string contains invalid wide characters, and the panic in this file could then crash the program using this library without any simple way of handling the panic.
I am arguing against having panic() in this function as the source data is usually from a device and not something the library authors or the user of this library has control over. So I am providing this non-intrusive patch, that tries the normal way first, and then if it encounters an error converting the string, it tries to convert as many as possible, ignoring any errors it encounters, and if the whole string is just illegal characters, it will return an empty string.