From a73c98a3abd2dc20145325436cefa2705c0db8f1 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Sun, 6 Nov 2011 22:05:03 +0100 Subject: osmocom: Address warning about aliasing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We alias the uint8_t buf[..] to a uint16_t* which is violating the aliases rule of C. Use an explicit memcpy to copy the first two byte of the buffer. GCC 4.6.2 (debian) is clever enough to use a normal load does not generate a memcpy call. osmocon.c: In function ‘un_tool_read’: osmocon.c:1239:2: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] --- src/host/osmocon/osmocon.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/host/osmocon') diff --git a/src/host/osmocon/osmocon.c b/src/host/osmocon/osmocon.c index 189984fb..5f289928 100644 --- a/src/host/osmocon/osmocon.c +++ b/src/host/osmocon/osmocon.c @@ -1236,7 +1236,8 @@ static int un_tool_read(struct osmo_fd *fd, unsigned int flags) c += rc; } - length = ntohs(*(uint16_t*)buf); + memcpy(&length, buf, sizeof length); + length = ntohs(length); c = 0; while(c < length) { -- cgit v1.2.3