Module Name:    src
Committed By:   christos
Date:           Wed Aug 17 10:08:43 UTC 2011

Modified Files:
        src/lib/libisns: Makefile isns_pdu.h isns_util.h

Log Message:
fix gcc aliasing issues.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/lib/libisns/Makefile
cvs rdiff -u -r1.1.1.1 -r1.2 src/lib/libisns/isns_pdu.h \
    src/lib/libisns/isns_util.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libisns/Makefile
diff -u src/lib/libisns/Makefile:1.2 src/lib/libisns/Makefile:1.3
--- src/lib/libisns/Makefile:1.2	Mon Jun 20 22:32:55 2011
+++ src/lib/libisns/Makefile	Wed Aug 17 06:08:43 2011
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.2 2011/06/21 02:32:55 mrg Exp $
+#	$NetBSD: Makefile,v 1.3 2011/08/17 10:08:43 christos Exp $
 
 .include <bsd.own.mk>
 
@@ -14,7 +14,3 @@
 WARNS=	4
 
 .include <bsd.lib.mk>
-
-.if ${HAVE_GCC} >= 45
-COPTS.isns_pdu.c+=	-fno-strict-aliasing
-.endif

Index: src/lib/libisns/isns_pdu.h
diff -u src/lib/libisns/isns_pdu.h:1.1.1.1 src/lib/libisns/isns_pdu.h:1.2
--- src/lib/libisns/isns_pdu.h:1.1.1.1	Sat Jan 15 20:22:50 2011
+++ src/lib/libisns/isns_pdu.h	Wed Aug 17 06:08:43 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: isns_pdu.h,v 1.1.1.1 2011/01/16 01:22:50 agc Exp $	*/
+/*	$NetBSD: isns_pdu.h,v 1.2 2011/08/17 10:08:43 christos Exp $	*/
 
 /*-
  * Copyright (c) 2004,2009 The NetBSD Foundation, Inc.
@@ -37,8 +37,10 @@
 #define _ISNS_PDU_H_
 
 #include <pthread.h>
+#include <string.h>
 
 #include "isns_defs.h"
+#include "isns_util.h"
 
 #define ISNSP_VERSION		(0x0001)
 
@@ -101,32 +103,36 @@
 /*
  * TLV buffer access/manipulation-related macros.
  */
-#define ISNS_TLV_HDR_SIZE	8
+#define ISNS_TLV_HDR_SIZE	(sizeof(uint32_t) * 2)
 
 #define ISNS_PAD4_LEN(n)	(uint32_t)(((n)+3) & ~0x03)
 #define ISNS_PAD4_BYTES(n)	((4 - ((n) & 0x03)) & 0x03)
 
-#define ISNS_TLV_TAG_REF(_buf)					\
- 	(*(uint32_t *)(void *)(_buf))
-#define ISNS_TLV_GET_TAG(_buf)					\
-	isns_ntohl(ISNS_TLV_TAG_REF(_buf))
-#define ISNS_TLV_SET_TAG(_buf, _tag)				\
-	do {							\
-    		ISNS_TLV_TAG_REF(_buf) = isns_htonl(_tag);	\
-	} while (/* CONSTCOND */0)
-
-#define ISNS_TLV_LEN_REF(_buf)					\
-	(*(uint32_t *)(void *)((uint8_t *)(_buf)+4))
-#define ISNS_TLV_GET_LEN(_buf)					\
-	isns_ntohl(ISNS_TLV_LEN_REF(_buf))
-#define ISNS_TLV_SET_LEN(_buf, _len)				\
-	do {							\
-		ISNS_TLV_LEN_REF(_buf) = isns_htonl(_len);	\
-	} while (/* CONSTCOND */0)
-
-#define ISNS_TLV_DATA_PTR(_buf)					\
-	((void *)((uint8_t *)(_buf)+8))
-
+static inline uint32_t ISNS_TLV_GET_TAG(const void *buf) {
+	uint32_t tag;
+	memcpy(&tag, buf, sizeof(tag));
+	return isns_ntohl(tag);
+}
+
+static inline void ISNS_TLV_SET_TAG(void *buf, uint32_t tag) {
+	tag = isns_htonl(tag);
+	memcpy(buf, &tag, sizeof(tag));
+}
+
+static inline uint32_t ISNS_TLV_GET_LEN(const void *buf) {
+	uint32_t len;
+	memcpy(&len, (const uint8_t *)buf + sizeof(len), sizeof(len));
+	return isns_ntohl(len);
+}
+
+static inline void ISNS_TLV_SET_LEN(void *buf, uint32_t len) {
+	len = isns_htonl(len);
+	memcpy((uint8_t *)buf + sizeof(len), &len, sizeof(len));
+}
+
+static inline void *ISNS_TLV_DATA_PTR(void *buf) {
+	return (uint8_t *)buf + ISNS_TLV_HDR_SIZE;
+}
 
 /*
  * ISNS transaction and PDU structs.
Index: src/lib/libisns/isns_util.h
diff -u src/lib/libisns/isns_util.h:1.1.1.1 src/lib/libisns/isns_util.h:1.2
--- src/lib/libisns/isns_util.h:1.1.1.1	Sat Jan 15 20:22:50 2011
+++ src/lib/libisns/isns_util.h	Wed Aug 17 06:08:43 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: isns_util.h,v 1.1.1.1 2011/01/16 01:22:50 agc Exp $	*/
+/*	$NetBSD: isns_util.h,v 1.2 2011/08/17 10:08:43 christos Exp $	*/
 
 /*-
  * Copyright (c) 2004,2009 The NetBSD Foundation, Inc.
@@ -48,6 +48,7 @@
 #define ARRAY_ELEMS(a)	(sizeof(a)/sizeof((a)[0]))
 
 
+struct isns_config_s;
 int isns_issue_cmd(struct isns_config_s *, uint8_t);
 int isns_issue_cmd_with_data(struct isns_config_s *, uint8_t,
     uint8_t *, int);

Reply via email to