Win32: modified hid_winapi_get_container_id() for consistency
Make use of hid_internal_get_devnode_property() method.
This method is not meant to be called frequently so I think we can disregard this 8 byte malloc.
Actually, there is one more issue with the new implementation: no more explicit check for the buffer size.
It is highly unlikely that WinAPI will report a DEVPROP_TYPE_GUID but len of smaller than sizeof(GUID), but I like it much better if there is no implicit assumptions in the code.
It is highly unlikely that WinAPI will report a DEVPROP_TYPE_GUID but len of smaller than sizeof(GUID)
According to the documentation, this should not be a problem:
| Property data type | Property value size requirement |
|---|---|
| A fixed-length base-data-type value | The specified size of the supplied data must be the number of bytes in the base data type. |
https://docs.microsoft.com/en-us/windows-hardware/drivers/install/property-value-requirements
Set the PropertyType parameter to DEVPROP_TYPE_GUID, set the PropertyBuffer parameter to a pointer to a buffer that contains a GUID value, and set the PropertyBufferSize parameter to sizeof(GUID).
https://docs.microsoft.com/en-us/windows-hardware/drivers/install/devprop-type-guid
According to the documentation
Unfortunately I've personally seen cases when WinAPI didn't behave as per documentation.
My consern stands:
- when we pass a buffer that is bigger than an API uses - that's fine;
- if we ask how large buffer API needs, allocate memory for it, and then don't actually check its size and try to read it - that is a potential issue;