Skip to content

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
bitfocusas:pr/wchar-issue
Open

wchar: remove panic() and give a best-effort version of the broken string, in worst case an empty string#19
haakonnessjoen wants to merge 1 commit intosstallion:masterfrom
bitfocusas:pr/wchar-issue

Conversation

@haakonnessjoen
Copy link
Copy Markdown

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.

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.

1 participant