fea961a
From 008c60a31d6e130d07c55751ef52ccfebac0b19b Mon Sep 17 00:00:00 2001
fea961a
From: Sandro Mani <manisandro@gmail.com>
fea961a
Date: Tue, 27 Jan 2015 10:42:16 +0100
fea961a
Subject: [PATCH] -Wstrict-aliasing fixes
fea961a
fea961a
---
fea961a
 src/libambit/device_driver_common.c | 9 ++++++---
fea961a
 1 file changed, 6 insertions(+), 3 deletions(-)
fea961a
fea961a
diff --git a/src/libambit/device_driver_common.c b/src/libambit/device_driver_common.c
fea961a
index 951ac33..859efb3 100644
fea961a
--- a/src/libambit/device_driver_common.c
fea961a
+++ b/src/libambit/device_driver_common.c
fea961a
@@ -24,6 +24,7 @@
fea961a
 #include "debug.h"
fea961a
 
fea961a
 #include <stdlib.h>
fea961a
+#include <string.h>
fea961a
 
fea961a
 /*
fea961a
  * Local definitions
fea961a
@@ -70,23 +71,25 @@ int libambit_device_driver_date_time_set(ambit_object_t *object, struct tm *tm)
fea961a
 {
fea961a
     uint8_t date_data[8] = { 0x00, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00 };
fea961a
     uint8_t time_data[8];
fea961a
+    uint16_t year = htole16(1900 + tm->tm_year);
fea961a
+    uint16_t sec = htole16(1000*tm->tm_sec);
fea961a
     int ret = -1;
fea961a
 
fea961a
     LOG_INFO("Writing date and time to clock");
fea961a
 
fea961a
     // Set date
fea961a
-    *(uint16_t*)(&date_data[0]) = htole16(1900 + tm->tm_year);
fea961a
+    memcpy(&date_data[0], &year, sizeof(uint16_t));
fea961a
     date_data[2] = 1 + tm->tm_mon;
fea961a
     date_data[3] = tm->tm_mday;
fea961a
     // byte[4-7] unknown (but set to 0x28000000 in moveslink)
fea961a
 
fea961a
     // Set time (+date)
fea961a
-    *(uint16_t*)(&time_data[0]) = htole16(1900 + tm->tm_year);
fea961a
+    memcpy(&time_data[0], &year, sizeof(uint16_t));
fea961a
     time_data[2] = 1 + tm->tm_mon;
fea961a
     time_data[3] = tm->tm_mday;
fea961a
     time_data[4] = tm->tm_hour;
fea961a
     time_data[5] = tm->tm_min;
fea961a
-    *(uint16_t*)(&time_data[6]) = htole16(1000*tm->tm_sec);
fea961a
+    memcpy(&time_data[6], &sec, sizeof(uint16_t));
fea961a
 
fea961a
     if (libambit_protocol_command(object, ambit_command_date, date_data, sizeof(date_data), NULL, NULL, 0) == 0 &&
fea961a
         libambit_protocol_command(object, ambit_command_time, time_data, sizeof(time_data), NULL, NULL, 0) == 0) {
fea961a
-- 
fea961a
2.2.2
fea961a