File libressl-no-punning.diff of Package libressl
From: Jan Engelhardt <jengelh@inai.de>
Date: 2014-07-12 11:21:03.199722087 +0200
build: resolve compile abort due to type punning and -Werror
gcc-4.8 said, upon `make check`:
biotest.c: In function 'do_bio_get_host_ip_tests':
biotest.c:101:3: error: dereferencing type-punned pointer will
break strict-aliasing rules [-Werror=strict-aliasing]
if (ret && ntohl(*((uint32_t *)ip)) != bgit->ip) {
^
biotest.c:104:8: error: dereferencing type-punned pointer will
break strict-aliasing rules [-Werror=strict-aliasing]
ntohl(*((uint32_t *)ip)), bgit->ip);
^
As "ip" may be not be properly aligned for uint32_t, copy it
to a uint32_t before ntohling.
---
tests/biotest.c | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
Index: libressl-2.0.0/tests/biotest.c
===================================================================
--- libressl-2.0.0.orig/tests/biotest.c
+++ libressl-2.0.0/tests/biotest.c
@@ -77,15 +77,25 @@ struct bio_get_port_test bio_get_port_te
#define N_BIO_GET_PORT_TESTS \
(sizeof(bio_get_port_tests) / sizeof(*bio_get_port_tests))
+#ifndef BUILD_BUG_ON_EXPR
+# define BUILD_BUG_ON_EXPR(condition) (sizeof(char[1 - 2 * !!(condition)]) - 1)
+#endif
+#ifndef BUILD_BUG_ON
+# define BUILD_BUG_ON(condition) ((void)BUILD_BUG_ON_EXPR(condition))
+#endif
+
static int
do_bio_get_host_ip_tests(void)
{
struct bio_get_host_ip_test *bgit;
unsigned char ip[4];
+ uint32_t ipout;
int failed = 0;
size_t i;
int ret;
+ BUILD_BUG_ON(sizeof(ip) != sizeof(ipout));
+
for (i = 0; i < N_BIO_GET_IP_TESTS; i++) {
bgit = &bio_get_host_ip_tests[i];
memset(ip, 0, sizeof(*ip));
@@ -98,10 +108,12 @@ do_bio_get_host_ip_tests(void)
failed = 1;
continue;
}
- if (ret && ntohl(*((uint32_t *)ip)) != bgit->ip) {
+ if (ret &&
+ memcpy(&ipout, ip, sizeof(ip)) != NULL &&
+ ntohl(ipout) != bgit->ip) {
fprintf(stderr, "FAIL: test %zi (\"%s\") returned ip "
"%x != %x\n", i, bgit->input,
- ntohl(*((uint32_t *)ip)), bgit->ip);
+ ntohl(ipout), bgit->ip);
failed = 1;
}
}