Repository navigation
windows: deduplicate bounded string getters - #865
Merged
Merged
Conversation
Replace HIDAPI_WCSNCPY and the three repeated getter implementations with one bounded copy helper. The old wcsncpy_s/lstrcpynW paths did not define behavior for a NULL individual string. The shared helper returns an empty string in that case while preserving the existing NULL device-info error. It copies at most maxlen - 1 WCHARs with HIDAPI_MEMCPY, always terminates the result, and keeps the existing truncation behavior. Assisted-by: deepseek-harness:deepseek-flash
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.
Replace the duplicated Windows string getters and
HIDAPI_WCSNCPYwith one bounded copy helper.There is one intended behavior change with this however, a NULL individual device-info string now returns an empty string with success, instead of relying on undefined
wcsncpy_s/lstrcpynWbehavior. NULL device-info can happen while*dupfunction or other path and currently isn't guarded for failure indifferently in CRT or no-CRT, ideally later an alloc failure in device object creation should be turned into failed object creation which is out of scope for this change. NULLdevice_infostill returns-1, and truncation behavior is unchanged.Tested before/after against a connected DualSense for normal and no-CRT builds. Return codes and output strings were byte-identical across maxlen values 0, 1, 2, 4, 8, 16, 32, 64, 128, and 256.
The code that is used for testing