Parcourir la source

Pointer alignment is acceptable

The h_addr_list is an array of pointers to network addresses for the host
in network byte order and it terminated by a null pointer. It is safe to
cast the address to a in_addr (which is effectively a uint32_t). However
we must cast it though void* to tell the compiler that we are OK with
the 1 byte alignment of the char pointer to a uint32_t pointer.
Matt Clarkson il y a 10 ans
Parent
commit
2feecee701
1 fichiers modifiés avec 1 ajouts et 1 suppressions
  1. 1 1
      src/civetweb.c

+ 1 - 1
src/civetweb.c

@@ -4580,7 +4580,7 @@ static SOCKET conn2(struct mg_context *ctx /* may be null */,
 		memset(&sain, '\0', sizeof(sain));
 		sain.sin_family = AF_INET;
 		sain.sin_port = htons((uint16_t)port);
-		sain.sin_addr = *(struct in_addr *)he->h_addr_list[0];
+		sain.sin_addr = *(struct in_addr *)(void*)he->h_addr_list[0];
 		if (connect(sock, (struct sockaddr *)&sain, sizeof(sain)) != 0) {
 			snprintf(ebuf,
 			         ebuf_len,