Browse Source

fixed unaligned pointer access to packed member

pdesc.c:233:2: warning: converting a packed ‘icmp_echo_packet_t’ pointer (alignment 1)
               to a ‘uint16_t’ {aka ‘short unsigned int’} pointer (alignment 2) may result
               in an unaligned pointer value [-Waddress-of-packed-member]
  233 |  pkt->checksum     = htons(calc_icmp_checksum((uint16_t*)pkt, pkt_len));
      |  ^~~
lns 2 years ago
parent
commit
c3bd138805
1 changed files with 3 additions and 1 deletions
  1. 3 1
      src/pdesc.c

+ 3 - 1
src/pdesc.c

@@ -197,6 +197,7 @@ int queue_packet(int sock_fd, proxy_desc_t *cur, char *buf, size_t bufsiz,
 	icmp_echo_packet_t *pkt   = 0;
 	ping_tunnel_pkt_t *pt_pkt = 0;
 	uint16_t ack_val;
+	uint8_t * icmp_chksm_ptr;
 
 	assert(sock_fd >= 0);
 	assert(cur);
@@ -230,7 +231,8 @@ int queue_packet(int sock_fd, proxy_desc_t *cur, char *buf, size_t bufsiz,
 	/* Copy user data */
 	if (buf && bufsiz > 0)
 		memcpy(pt_pkt->data, buf, bufsiz);
-	pkt->checksum     = htons(calc_icmp_checksum((uint16_t*)pkt, pkt_len));
+	icmp_chksm_ptr	  = (uint8_t*)pkt;
+	pkt->checksum     = htons(calc_icmp_checksum((uint16_t*)icmp_chksm_ptr, pkt_len));
 
 	/* Send it! */
 	pt_log(kLog_sendrecv, "Send: %4d [%4d] bytes "