git: b728765f88dd - stable/13 - bhyve: Address warnings about potential unaligned accesses in fwctl.c

From: John Baldwin <jhb_at_FreeBSD.org>
Date: Thu, 26 Jan 2023 19:48:05 UTC
The branch stable/13 has been updated by jhb:

URL: https://cgit.FreeBSD.org/src/commit/?id=b728765f88dde5b5454fac44dee2f7057d5bd85f

commit b728765f88dde5b5454fac44dee2f7057d5bd85f
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2022-11-11 15:01:27 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2023-01-26 19:43:26 +0000

    bhyve: Address warnings about potential unaligned accesses in fwctl.c
    
    This silences some warning about potential unaligned accesses.  No
    functional change intended.
    
    MFC after:      1 week
    Reviewed by:    corvink, jhb
    Differential Revision:  https://reviews.freebsd.org/D37288
    
    (cherry picked from commit f64f34380925a4ddaf1c140c35f46408b74110ac)
---
 usr.sbin/bhyve/fwctl.c | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/usr.sbin/bhyve/fwctl.c b/usr.sbin/bhyve/fwctl.c
index 46010513b66a..f74380a426b2 100644
--- a/usr.sbin/bhyve/fwctl.c
+++ b/usr.sbin/bhyve/fwctl.c
@@ -88,20 +88,17 @@ static struct op_info *ops[OP_MAX+1];
 
 /* Return 0-padded uint32_t */
 static uint32_t
-fwctl_send_rest(uint32_t *data, size_t len)
+fwctl_send_rest(uint8_t *data, size_t len)
 {
 	union {
 		uint8_t c[4];
 		uint32_t w;
 	} u;
-	uint8_t *cdata;
 	size_t i;
 
-	cdata = (uint8_t *) data;
 	u.w = 0;
-
-	for (i = 0, u.w = 0; i < len; i++)
-		u.c[i] = *cdata++;
+	for (i = 0; i < len; i++)
+		u.c[i] = *data++;
 
 	return (u.w);
 }
@@ -203,7 +200,7 @@ static void
 fget_data(uint32_t data, uint32_t len __unused)
 {
 
-	*((uint32_t *) &fget_str[fget_cnt]) = data;
+	memcpy(&fget_str[fget_cnt], &data, sizeof(data));
 	fget_cnt += sizeof(uint32_t);
 }
 
@@ -401,7 +398,7 @@ fwctl_request(uint32_t value)
 static int
 fwctl_response(uint32_t *retval)
 {
-	uint32_t *dp;
+	uint8_t *dp;
 	ssize_t remlen;
 
 	switch(rinfo.resp_count) {
@@ -425,10 +422,9 @@ fwctl_response(uint32_t *retval)
 		break;
 	default:
 		remlen = rinfo.resp_size - rinfo.resp_off;
-		dp = (uint32_t *)
-		    ((uint8_t *)rinfo.resp_biov->iov_base + rinfo.resp_off);
+		dp = (uint8_t *)rinfo.resp_biov->iov_base + rinfo.resp_off;
 		if (remlen >= (ssize_t)sizeof(uint32_t)) {
-			*retval = *dp;
+			memcpy(retval, dp, sizeof(uint32_t));
 		} else if (remlen > 0) {
 			*retval = fwctl_send_rest(dp, remlen);
 		}