]> git.openfabrics.org - ~shefty/ibacm.git/commitdiff
ibacm: Eliminate strict aliasing compiler warnings
authorSean Hefty <sean.hefty@intel.com>
Sat, 22 Mar 2014 03:30:17 +0000 (20:30 -0700)
committerSean Hefty <sean.hefty@intel.com>
Tue, 8 Apr 2014 22:46:08 +0000 (15:46 -0700)
Use local variables and memcpy to defeat the
compiler warning: dereferencing type-punned
pointer will break strict-aliasing rules

Signed-off-by: Sean Hefty <sean.hefty@intel.com>
src/acm.c

index c133ef95b09b0ce77f4df682ae5b0cfc409b7857..a6b4cd20064597adebe459d480c8a51ff2649b11 100644 (file)
--- a/src/acm.c
+++ b/src/acm.c
@@ -1625,13 +1625,15 @@ static void acm_process_timeouts(void)
        DLIST_ENTRY *entry;
        struct acm_send_msg *msg;
        struct acm_resolve_rec *rec;
+       struct acm_mad *mad;
        
        while (!DListEmpty(&timeout_list)) {
                entry = timeout_list.Next;
                DListRemove(entry);
 
                msg = container_of(entry, struct acm_send_msg, entry);
-               rec = (struct acm_resolve_rec *) ((struct acm_mad *) msg->data)->data;
+               mad = (struct acm_mad *) &msg->data[0];
+               rec = (struct acm_resolve_rec *) mad->data;
 
                acm_format_name(0, log_data, sizeof log_data,
                                rec->dest_type, rec->dest, sizeof rec->dest);
@@ -2925,7 +2927,7 @@ static int acm_parse_osm_fullv1_paths(FILE *f, uint64_t *lid2guid, struct acm_ep
        char s[128];
        char *p, *ptr, *p_guid, *p_lid;
        uint64_t guid;
-       uint16_t lid, dlid;
+       uint16_t lid, dlid, net_dlid;
        int sl, mtu, rate;
        int ret = 1, i;
        uint8_t addr[ACM_MAX_ADDRESS];
@@ -2988,6 +2990,7 @@ static int acm_parse_osm_fullv1_paths(FILE *f, uint64_t *lid2guid, struct acm_ep
                        break;
 
                dlid = strtoul(p, NULL, 0);
+               net_dlid = htons(dlid);
 
                p = strtok_r(NULL, ":", &ptr);
                if (!p)
@@ -3018,7 +3021,7 @@ static int acm_parse_osm_fullv1_paths(FILE *f, uint64_t *lid2guid, struct acm_ep
                        memset(addr, 0, ACM_MAX_ADDRESS);
                        if (i == 0) {
                                addr_type = ACM_ADDRESS_LID;
-                               *((uint16_t *) addr) = htons(dlid);
+                               memcpy(addr, &net_dlid, sizeof net_dlid);
                        } else {
                                addr_type = ACM_ADDRESS_GID;
                                memcpy(addr, &dgid, sizeof(dgid));
@@ -3032,7 +3035,7 @@ static int acm_parse_osm_fullv1_paths(FILE *f, uint64_t *lid2guid, struct acm_ep
                        dest->path.sgid = sgid;
                        dest->path.slid = htons(ep->port->lid);
                        dest->path.dgid = dgid;
-                       dest->path.dlid = htons(dlid);
+                       dest->path.dlid = net_dlid;
                        dest->path.reversible_numpath = IBV_PATH_RECORD_REVERSIBLE;
                        dest->path.pkey = htons(ep->pkey);
                        dest->path.mtu = (uint8_t) mtu;