From 75e6afc32859de540fe229c4d8238a7d8448cca4 Mon Sep 17 00:00:00 2001 From: KlausHustede Date: Thu, 18 Aug 2022 20:08:52 +0200 Subject: [PATCH] fix possible problems in struct (byte) alignment --- tools/esp8266/defines.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tools/esp8266/defines.h b/tools/esp8266/defines.h index 339ef89e..006555de 100644 --- a/tools/esp8266/defines.h +++ b/tools/esp8266/defines.h @@ -109,15 +109,16 @@ typedef enum { // ToDo: to be verified by field tests #define SER_DEBUG_LEN 1 // uint8_t #define SER_INTERVAL_LEN 2 // uint16_t - +#pragma pack(push) // push current alignment to stack +#pragma pack(1) // set alignment to 1 byte boundary typedef struct { char broker[MQTT_ADDR_LEN]; uint16_t port; char user[MQTT_USER_LEN]; char pwd[MQTT_PWD_LEN]; char topic[MQTT_TOPIC_LEN]; -} mqttConfig_t; - +} /*__attribute__((__packed__))*/ mqttConfig_t; +#pragma pack(pop) // restore original alignment from stack typedef struct { char deviceName[DEVNAME_LEN]; @@ -126,6 +127,8 @@ typedef struct { char stationPwd[PWD_LEN]; } sysConfig_t; +#pragma pack(push) // push current alignment to stack +#pragma pack(1) // set alignment to 1 byte boundary typedef struct { // nrf24 uint16_t sendInterval; @@ -146,7 +149,8 @@ typedef struct { uint16_t serialInterval; bool serialShowIv; bool serialDebug; -} config_t; +} /*__attribute__((__packed__))*/ config_t; +#pragma pack(pop) // restore original alignment from stack #define CFG_MQTT_LEN MQTT_ADDR_LEN + 2 + MQTT_USER_LEN + MQTT_PWD_LEN +MQTT_TOPIC_LEN