Skip to content

README example: prevent segmentation fault and mixture of printf/wprintf#470

Merged
Youw merged 4 commits intolibusb:masterfrom
endolith:example_changes
Oct 21, 2022
Merged

README example: prevent segmentation fault and mixture of printf/wprintf#470
Youw merged 4 commits intolibusb:masterfrom
endolith:example_changes

Conversation

@endolith
Copy link
Copy Markdown
Contributor

@endolith endolith commented Oct 20, 2022

When no device is connected (or user doesn't have permission to access
device), hid_open returns NULL. If NULL is passed to
hid_get_manufacturer_string(), it crashes with SIGSEGV, which could be
confusing to newcomers trying to get example to work.

wprintf and printf aren't compatible in the same stream

Now it's more similar to https://github.com/libusb/hidapi/blob/master/hidtest/test.c#L129

Closes: #469

It was printing only the first character.

https://devblogs.microsoft.com/oldnewthing/20190830-00/?p=102823

"If you want your code to work both on runtimes that use the Windows
classic printf rules as well as those that use C standard printf rules,
you can limit yourself to %hs for narrow strings and %ls for wide
strings, and you’ll get consistent results regardless of whether the
format string was passed to sprintf or wsprintf."
When no device is connected (or user doesn't have permission to access
device), hid_open returns NULL.  If NULL is passed to
hid_get_manufacturer_string(), it crashes with SIGSEGV, which could be
confusing to newcomers trying to get example to work.
wprintf and printf aren't compatible in the same stream
Comment thread README.md
@Youw Youw merged commit 1312cc3 into libusb:master Oct 21, 2022
fengjixuchui added a commit to fengjixuchui/hidapi that referenced this pull request Oct 21, 2022
README: prevent segmentation fault and mixture of printf/wprintf (libusb#470)
@endolith endolith deleted the example_changes branch October 21, 2022 11:41
endolith added a commit to endolith/hidapi that referenced this pull request Oct 21, 2022
@mcuee mcuee added the documentation Improvements or additions to documentation label Dec 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants