Elizabeth Figura (@zfigura) commented about programs/plugplay/main.c:
+void __cdecl plugplay_send_event( DWORD event_code, const device_broadcast *data ) { struct listener *listener;
- struct event *event;
- const WCHAR *name_src = NULL;
- DWORD str_size = 0;
- BroadcastSystemMessageW( 0, NULL, WM_DEVICECHANGE, code, (LPARAM)data );
- BroadcastSystemMessageW( 0, NULL, WM_DEVICECHANGE, DBT_DEVNODES_CHANGED, 0 );
- TRACE( "(%#lx, %s)\n", event_code, debugstr_device_broadcast( data ) );
- EnterCriticalSection( &plugplay_cs );
- switch(data->devicetype)
- {
- case DBT_DEVTYP_HANDLE:
name_src = data->event.handle.name;
The logic surrounding "name_src" in this function seems awkwardly structured. The point is apparently to deep-copy the structure contents, but the two arms have different fields, and trying to unify one of the strings is unidiomatic and I don't think really saves you anything. Rather, I think this function should
(1) convert to DEV_BROADCAST_DEVICEINTERFACE_W and broadcast (2) deep-copy the struct (3) queue the copied struct
as three separate and subsequent operations. (2) should probably also be a helper function.