diff mbox series

[v2] wpa_supplicant: Fix arithmetic on void pointer

Message ID 1570607973-12911-1-git-send-email-jesus.manzano@galgus.net
State Accepted
Headers show
Series [v2] wpa_supplicant: Fix arithmetic on void pointer | expand

Commit Message

Jesus Fernandez Manzano Oct. 9, 2019, 7:59 a.m. UTC
When using void pointers in calculations, the behaviour is undefined.
Arithmetic operations on 'void *' is a GNU C extension,
which defines the 'sizeof(void)' to be 1.

This change improves portability of the code.

Signed-off-by: Jesus Fernandez Manzano <jesus.manzano@galgus.net>
---
 wpa_supplicant/wpa_priv.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Jouni Malinen Oct. 25, 2019, 4:52 p.m. UTC | #1
On Wed, Oct 09, 2019 at 09:59:33AM +0200, Jesus Fernandez Manzano wrote:
> When using void pointers in calculations, the behaviour is undefined.
> Arithmetic operations on 'void *' is a GNU C extension,
> which defines the 'sizeof(void)' to be 1.
> 
> This change improves portability of the code.

Thanks, applied.
diff mbox series

Patch

diff --git a/wpa_supplicant/wpa_priv.c b/wpa_supplicant/wpa_priv.c
index b3ad45e..423911f 100644
--- a/wpa_supplicant/wpa_priv.c
+++ b/wpa_supplicant/wpa_priv.c
@@ -598,7 +598,7 @@  static void wpa_priv_cmd_l2_send(struct wpa_priv_interface *iface,
 	}
 
 	dst_addr = buf;
-	os_memcpy(&proto, buf + ETH_ALEN, 2);
+	os_memcpy(&proto, (char *)buf + ETH_ALEN, 2);
 
 	if (!wpa_priv_allowed_l2_proto(proto)) {
 		wpa_printf(MSG_DEBUG, "Refused l2_packet send for ethertype "
@@ -607,7 +607,7 @@  static void wpa_priv_cmd_l2_send(struct wpa_priv_interface *iface,
 	}
 
 	res = l2_packet_send(iface->l2[idx], dst_addr, proto,
-			     buf + ETH_ALEN + 2, len - ETH_ALEN - 2);
+			     (unsigned char *)buf + ETH_ALEN + 2, len - ETH_ALEN - 2);
 	wpa_printf(MSG_DEBUG, "L2 send[idx=%d]: res=%d", idx, res);
 }