Refactor property value lookups in Windows to use a safe lookup function#241
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a helper function lookup_i_property_value to refactor and safely lookup properties from a WinRT property map, avoiding potential crashes from invalid casts. A critical issue was identified where using a template parameter for PropertyMap makes try_as a dependent template member function call, which requires the template keyword to compile under standard-compliant compilers. It is recommended to make lookup_i_property_value a non-template function with fully qualified WinRT types to prevent compilation failures and template bloat.
There was a problem hiding this comment.
Pull request overview
Refactors Windows DeviceInformation property retrieval to centralize IPropertyValue lookups behind a helper, aiming to avoid unsafe casts and improve resilience when property types don’t match expectations.
Changes:
- Added a reusable
lookup_i_property_value(...)helper for property lookups. - Updated device watcher “Added” handling to use the helper for
DeviceAddress. - Updated
OnDeviceInfoReceivedandBluetoothLeWatcherReceivedto use the helper forIsConnectable,DeviceAddress,IsPaired, andSignalStrength.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…pointer crash on Windows when a BLE device is unpaired during an active scan.
7a2916c to
63caf06
Compare
…andling and ensure safe retrieval of IPropertyValue. This change replaces the previous template-based approach with a more robust implementation that catches exceptions and logs errors appropriately.
This pull request refactors the way BLE device property values are accessed in the Windows plugin, improving error handling and code maintainability. The main change is the introduction of a helper function,
lookup_i_property_value, which standardizes property access and logging for missing or invalid properties. This function is then used throughout the codebase to replace direct property lookups, resulting in safer and more readable code.