From: Thomas Pornin Date: Sat, 19 Aug 2017 13:50:45 +0000 (+0200) Subject: Added intermediate casts to void* to prevent spurious warnings (with Clang and -Wcast... X-Git-Tag: v0.6~26 X-Git-Url: https://bearssl.org/gitweb//home/git/?a=commitdiff_plain;h=8e86598b33f9df81d1f77d6cc32568d9ae119d67;p=BearSSL Added intermediate casts to void* to prevent spurious warnings (with Clang and -Wcast-align). --- diff --git a/src/codec/pemdec.c b/src/codec/pemdec.c index 51e610b..db8f0e6 100644 --- a/src/codec/pemdec.c +++ b/src/codec/pemdec.c @@ -69,7 +69,7 @@ void br_pem_decoder_run(void *t0ctx); #include "inner.h" -#define CTX ((br_pem_decoder_context *)((unsigned char *)t0ctx - offsetof(br_pem_decoder_context, cpu))) +#define CTX ((br_pem_decoder_context *)(void *)((unsigned char *)t0ctx - offsetof(br_pem_decoder_context, cpu))) /* see bearssl_pem.h */ void diff --git a/src/codec/pemdec.t0 b/src/codec/pemdec.t0 index ba4a9e2..d76be44 100644 --- a/src/codec/pemdec.t0 +++ b/src/codec/pemdec.t0 @@ -24,7 +24,7 @@ preamble { #include "inner.h" -#define CTX ((br_pem_decoder_context *)((unsigned char *)t0ctx - offsetof(br_pem_decoder_context, cpu))) +#define CTX ((br_pem_decoder_context *)(void *)((unsigned char *)t0ctx - offsetof(br_pem_decoder_context, cpu))) /* see bearssl_pem.h */ void diff --git a/src/ssl/ssl_hs_client.c b/src/ssl/ssl_hs_client.c index 9d3418b..2faba6a 100644 --- a/src/ssl/ssl_hs_client.c +++ b/src/ssl/ssl_hs_client.c @@ -75,7 +75,7 @@ void br_ssl_hs_client_run(void *t0ctx); /* * This macro evaluates to a pointer to the current engine context. */ -#define ENG ((br_ssl_engine_context *)((unsigned char *)t0ctx - offsetof(br_ssl_engine_context, cpu))) +#define ENG ((br_ssl_engine_context *)(void *)((unsigned char *)t0ctx - offsetof(br_ssl_engine_context, cpu))) @@ -1397,7 +1397,7 @@ br_ssl_hs_client_run(void *t0ctx) /* get16 */ size_t addr = (size_t)T0_POP(); - T0_PUSH(*(uint16_t *)((unsigned char *)ENG + addr)); + T0_PUSH(*(uint16_t *)(void *)((unsigned char *)ENG + addr)); } break; @@ -1405,7 +1405,7 @@ br_ssl_hs_client_run(void *t0ctx) /* get32 */ size_t addr = (size_t)T0_POP(); - T0_PUSH(*(uint32_t *)((unsigned char *)ENG + addr)); + T0_PUSH(*(uint32_t *)(void *)((unsigned char *)ENG + addr)); } break; @@ -1557,7 +1557,7 @@ br_ssl_hs_client_run(void *t0ctx) /* set16 */ size_t addr = (size_t)T0_POP(); - *(uint16_t *)((unsigned char *)ENG + addr) = (uint16_t)T0_POP(); + *(uint16_t *)(void *)((unsigned char *)ENG + addr) = (uint16_t)T0_POP(); } break; @@ -1565,7 +1565,7 @@ br_ssl_hs_client_run(void *t0ctx) /* set32 */ size_t addr = (size_t)T0_POP(); - *(uint32_t *)((unsigned char *)ENG + addr) = (uint32_t)T0_POP(); + *(uint32_t *)(void *)((unsigned char *)ENG + addr) = (uint32_t)T0_POP(); } break; diff --git a/src/ssl/ssl_hs_common.t0 b/src/ssl/ssl_hs_common.t0 index dc025ff..f4ad65b 100644 --- a/src/ssl/ssl_hs_common.t0 +++ b/src/ssl/ssl_hs_common.t0 @@ -34,7 +34,7 @@ preamble { /* * This macro evaluates to a pointer to the current engine context. */ -#define ENG ((br_ssl_engine_context *)((unsigned char *)t0ctx - offsetof(br_ssl_engine_context, cpu))) +#define ENG ((br_ssl_engine_context *)(void *)((unsigned char *)t0ctx - offsetof(br_ssl_engine_context, cpu))) } @@ -112,13 +112,13 @@ cc: get8 ( addr -- val ) { \ Read a 16-bit word from the context (address is offset in context). cc: get16 ( addr -- val ) { size_t addr = (size_t)T0_POP(); - T0_PUSH(*(uint16_t *)((unsigned char *)ENG + addr)); + T0_PUSH(*(uint16_t *)(void *)((unsigned char *)ENG + addr)); } \ Read a 32-bit word from the context (address is offset in context). cc: get32 ( addr -- val ) { size_t addr = (size_t)T0_POP(); - T0_PUSH(*(uint32_t *)((unsigned char *)ENG + addr)); + T0_PUSH(*(uint32_t *)(void *)((unsigned char *)ENG + addr)); } \ Set a byte in the context (address is offset in context). @@ -130,13 +130,13 @@ cc: set8 ( val addr -- ) { \ Set a 16-bit word in the context (address is offset in context). cc: set16 ( val addr -- ) { size_t addr = (size_t)T0_POP(); - *(uint16_t *)((unsigned char *)ENG + addr) = (uint16_t)T0_POP(); + *(uint16_t *)(void *)((unsigned char *)ENG + addr) = (uint16_t)T0_POP(); } \ Set a 32-bit word in the context (address is offset in context). cc: set32 ( val addr -- ) { size_t addr = (size_t)T0_POP(); - *(uint32_t *)((unsigned char *)ENG + addr) = (uint32_t)T0_POP(); + *(uint32_t *)(void *)((unsigned char *)ENG + addr) = (uint32_t)T0_POP(); } \ Define a word that evaluates as an address of a field within the diff --git a/src/ssl/ssl_hs_server.c b/src/ssl/ssl_hs_server.c index 3970d28..5dd30a1 100644 --- a/src/ssl/ssl_hs_server.c +++ b/src/ssl/ssl_hs_server.c @@ -75,7 +75,7 @@ void br_ssl_hs_server_run(void *t0ctx); /* * This macro evaluates to a pointer to the current engine context. */ -#define ENG ((br_ssl_engine_context *)((unsigned char *)t0ctx - offsetof(br_ssl_engine_context, cpu))) +#define ENG ((br_ssl_engine_context *)(void *)((unsigned char *)t0ctx - offsetof(br_ssl_engine_context, cpu))) @@ -1454,7 +1454,7 @@ br_ssl_hs_server_run(void *t0ctx) /* get16 */ size_t addr = (size_t)T0_POP(); - T0_PUSH(*(uint16_t *)((unsigned char *)ENG + addr)); + T0_PUSH(*(uint16_t *)(void *)((unsigned char *)ENG + addr)); } break; @@ -1462,7 +1462,7 @@ br_ssl_hs_server_run(void *t0ctx) /* get32 */ size_t addr = (size_t)T0_POP(); - T0_PUSH(*(uint32_t *)((unsigned char *)ENG + addr)); + T0_PUSH(*(uint32_t *)(void *)((unsigned char *)ENG + addr)); } break; @@ -1635,7 +1635,7 @@ br_ssl_hs_server_run(void *t0ctx) /* set16 */ size_t addr = (size_t)T0_POP(); - *(uint16_t *)((unsigned char *)ENG + addr) = (uint16_t)T0_POP(); + *(uint16_t *)(void *)((unsigned char *)ENG + addr) = (uint16_t)T0_POP(); } break; @@ -1643,7 +1643,7 @@ br_ssl_hs_server_run(void *t0ctx) /* set32 */ size_t addr = (size_t)T0_POP(); - *(uint32_t *)((unsigned char *)ENG + addr) = (uint32_t)T0_POP(); + *(uint32_t *)(void *)((unsigned char *)ENG + addr) = (uint32_t)T0_POP(); } break; diff --git a/src/x509/asn1.t0 b/src/x509/asn1.t0 index d6bb2e4..6732f9d 100644 --- a/src/x509/asn1.t0 +++ b/src/x509/asn1.t0 @@ -198,12 +198,12 @@ cc: set8 ( val addr -- ) { cc: set16 ( val addr -- ) { uint32_t addr = T0_POP(); - *(uint16_t *)((unsigned char *)CTX + addr) = T0_POP(); + *(uint16_t *)(void *)((unsigned char *)CTX + addr) = T0_POP(); } cc: set32 ( val addr -- ) { uint32_t addr = T0_POP(); - *(uint32_t *)((unsigned char *)CTX + addr) = T0_POP(); + *(uint32_t *)(void *)((unsigned char *)CTX + addr) = T0_POP(); } cc: get8 ( addr -- val ) { @@ -213,12 +213,12 @@ cc: get8 ( addr -- val ) { cc: get16 ( addr -- val ) { uint32_t addr = T0_POP(); - T0_PUSH(*(uint16_t *)((unsigned char *)CTX + addr)); + T0_PUSH(*(uint16_t *)(void *)((unsigned char *)CTX + addr)); } cc: get32 ( addr -- val ) { uint32_t addr = T0_POP(); - T0_PUSH(*(uint32_t *)((unsigned char *)CTX + addr)); + T0_PUSH(*(uint32_t *)(void *)((unsigned char *)CTX + addr)); } \ Read an ASN.1 tag. This function returns the "constructed" status diff --git a/src/x509/skey_decoder.c b/src/x509/skey_decoder.c index 4c486d5..f4e43e7 100644 --- a/src/x509/skey_decoder.c +++ b/src/x509/skey_decoder.c @@ -75,7 +75,7 @@ void br_skey_decoder_run(void *t0ctx); #include "inner.h" -#define CTX ((br_skey_decoder_context *)((unsigned char *)t0ctx - offsetof(br_skey_decoder_context, cpu))) +#define CTX ((br_skey_decoder_context *)(void *)((unsigned char *)t0ctx - offsetof(br_skey_decoder_context, cpu))) #define CONTEXT_NAME br_skey_decoder_context /* see bearssl_x509.h */ diff --git a/src/x509/skey_decoder.t0 b/src/x509/skey_decoder.t0 index 336b932..5b59421 100644 --- a/src/x509/skey_decoder.t0 +++ b/src/x509/skey_decoder.t0 @@ -24,7 +24,7 @@ preamble { #include "inner.h" -#define CTX ((br_skey_decoder_context *)((unsigned char *)t0ctx - offsetof(br_skey_decoder_context, cpu))) +#define CTX ((br_skey_decoder_context *)(void *)((unsigned char *)t0ctx - offsetof(br_skey_decoder_context, cpu))) #define CONTEXT_NAME br_skey_decoder_context /* see bearssl_x509.h */ diff --git a/src/x509/x509_decoder.c b/src/x509/x509_decoder.c index 42620c6..8dd970f 100644 --- a/src/x509/x509_decoder.c +++ b/src/x509/x509_decoder.c @@ -75,7 +75,7 @@ void br_x509_decoder_run(void *t0ctx); #include "inner.h" -#define CTX ((br_x509_decoder_context *)((unsigned char *)t0ctx - offsetof(br_x509_decoder_context, cpu))) +#define CTX ((br_x509_decoder_context *)(void *)((unsigned char *)t0ctx - offsetof(br_x509_decoder_context, cpu))) #define CONTEXT_NAME br_x509_decoder_context /* see bearssl_x509.h */ @@ -743,7 +743,7 @@ br_x509_decoder_run(void *t0ctx) /* set32 */ uint32_t addr = T0_POP(); - *(uint32_t *)((unsigned char *)CTX + addr) = T0_POP(); + *(uint32_t *)(void *)((unsigned char *)CTX + addr) = T0_POP(); } break; diff --git a/src/x509/x509_decoder.t0 b/src/x509/x509_decoder.t0 index 1b6089b..0bf276f 100644 --- a/src/x509/x509_decoder.t0 +++ b/src/x509/x509_decoder.t0 @@ -24,7 +24,7 @@ preamble { #include "inner.h" -#define CTX ((br_x509_decoder_context *)((unsigned char *)t0ctx - offsetof(br_x509_decoder_context, cpu))) +#define CTX ((br_x509_decoder_context *)(void *)((unsigned char *)t0ctx - offsetof(br_x509_decoder_context, cpu))) #define CONTEXT_NAME br_x509_decoder_context /* see bearssl_x509.h */ diff --git a/src/x509/x509_minimal.c b/src/x509/x509_minimal.c index a8283e3..ea14ad2 100644 --- a/src/x509/x509_minimal.c +++ b/src/x509/x509_minimal.c @@ -356,7 +356,7 @@ const br_x509_class br_x509_minimal_vtable = { xm_get_pkey }; -#define CTX ((br_x509_minimal_context *)((unsigned char *)t0ctx - offsetof(br_x509_minimal_context, cpu))) +#define CTX ((br_x509_minimal_context *)(void *)((unsigned char *)t0ctx - offsetof(br_x509_minimal_context, cpu))) #define CONTEXT_NAME br_x509_minimal_context #define DNHASH_LEN ((CTX->dn_hash_impl->desc >> BR_HASHDESC_OUT_OFF) & BR_HASHDESC_OUT_MASK) @@ -1444,7 +1444,7 @@ br_x509_minimal_run(void *t0ctx) /* get16 */ uint32_t addr = T0_POP(); - T0_PUSH(*(uint16_t *)((unsigned char *)CTX + addr)); + T0_PUSH(*(uint16_t *)(void *)((unsigned char *)CTX + addr)); } break; @@ -1452,7 +1452,7 @@ br_x509_minimal_run(void *t0ctx) /* get32 */ uint32_t addr = T0_POP(); - T0_PUSH(*(uint32_t *)((unsigned char *)CTX + addr)); + T0_PUSH(*(uint32_t *)(void *)((unsigned char *)CTX + addr)); } break; @@ -1606,7 +1606,7 @@ br_x509_minimal_run(void *t0ctx) /* set16 */ uint32_t addr = T0_POP(); - *(uint16_t *)((unsigned char *)CTX + addr) = T0_POP(); + *(uint16_t *)(void *)((unsigned char *)CTX + addr) = T0_POP(); } break; @@ -1614,7 +1614,7 @@ br_x509_minimal_run(void *t0ctx) /* set32 */ uint32_t addr = T0_POP(); - *(uint32_t *)((unsigned char *)CTX + addr) = T0_POP(); + *(uint32_t *)(void *)((unsigned char *)CTX + addr) = T0_POP(); } break; diff --git a/src/x509/x509_minimal.t0 b/src/x509/x509_minimal.t0 index 2104d2c..bce37ad 100644 --- a/src/x509/x509_minimal.t0 +++ b/src/x509/x509_minimal.t0 @@ -305,7 +305,7 @@ const br_x509_class br_x509_minimal_vtable = { xm_get_pkey }; -#define CTX ((br_x509_minimal_context *)((unsigned char *)t0ctx - offsetof(br_x509_minimal_context, cpu))) +#define CTX ((br_x509_minimal_context *)(void *)((unsigned char *)t0ctx - offsetof(br_x509_minimal_context, cpu))) #define CONTEXT_NAME br_x509_minimal_context #define DNHASH_LEN ((CTX->dn_hash_impl->desc >> BR_HASHDESC_OUT_OFF) & BR_HASHDESC_OUT_MASK) diff --git a/tools/client.c b/tools/client.c index acd8512..3d13510 100644 --- a/tools/client.c +++ b/tools/client.c @@ -72,9 +72,11 @@ host_connect(const char *host, const char *port, int verbose) sa = (struct sockaddr *)p->ai_addr; if (sa->sa_family == AF_INET) { - addr = &((struct sockaddr_in *)sa)->sin_addr; + addr = &((struct sockaddr_in *) + (void *)sa)->sin_addr; } else if (sa->sa_family == AF_INET6) { - addr = &((struct sockaddr_in6 *)sa)->sin6_addr; + addr = &((struct sockaddr_in6 *) + (void *)sa)->sin6_addr; } else { addr = NULL; } diff --git a/tools/server.c b/tools/server.c index cac99c4..8fcf2eb 100644 --- a/tools/server.c +++ b/tools/server.c @@ -75,7 +75,7 @@ host_bind(const char *host, const char *port, int verbose) sa = (struct sockaddr *)p->ai_addr; if (sa->sa_family == AF_INET) { - sa4 = *(struct sockaddr_in *)sa; + memcpy(&sa4, sa, sizeof sa4); sa = (struct sockaddr *)&sa4; sa_len = sizeof sa4; addr = &sa4.sin_addr; @@ -83,7 +83,7 @@ host_bind(const char *host, const char *port, int verbose) sa4.sin_addr.s_addr = INADDR_ANY; } } else if (sa->sa_family == AF_INET6) { - sa6 = *(struct sockaddr_in6 *)sa; + memcpy(&sa6, sa, sizeof sa6); sa = (struct sockaddr *)&sa6; sa_len = sizeof sa6; addr = &sa6.sin6_addr;