e - wireless module - remove horrible memcpy with offsetof magic

while it technically wuld work, this memcpy here is fragile and the
moment some struct members changed it'd fall apart and have fields all
misaligned etc. in fact using offsetof means it might over-copy a bit
extra due to alignment of the connect_cb vs method in Connman_Service.
so manually aissgne the fields in the func instead to be far safer.

if anything this should become a sub-struct with a type that can then
be properly copied even if things change.

@fix
This commit is contained in:
Carsten Haitzler 2016-04-13 20:28:27 +09:00
parent 119a0629f2
commit 90a4ad88b7
1 changed files with 5 additions and 1 deletions

View File

@ -251,8 +251,12 @@ _connman_service_convert(Connman_Service *cs)
Wireless_Network *wn;
wn = E_NEW(Wireless_Network, 1);
memcpy(wn, &cs->path, offsetof(Wireless_Network, connect_cb));
wn->path = cs->path;
wn->name = cs->name;
wn->security = cs->security;
wn->state = _connman_wifi_state_convert(cs->state);
wn->type = cs->type;
wn->strength = cs->strength;
wn->connect_cb = _connman_service_connect;
return wn;
}