From bd040bc227e5f949bd75eb57da35f6f56cbefc1f Mon Sep 17 00:00:00 2001 From: Charles Date: Mon, 9 May 2016 14:09:58 +0200 Subject: [PATCH] Structure Alignement on linked list for ESP8266 --- src/LibTeleinfo.cpp | 17 +++++++++++++---- src/LibTeleinfo.h | 5 +++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/LibTeleinfo.cpp b/src/LibTeleinfo.cpp index d572c84..e366ae3 100644 --- a/src/LibTeleinfo.cpp +++ b/src/LibTeleinfo.cpp @@ -247,13 +247,22 @@ ValueList * TInfo::valueAdd(char * name, char * value, uint8_t checksum, uint8_t // Our linked list structure sizeof(ValueList) // + Name + '\0' // + Value + '\0' - size_t size = sizeof(ValueList) + lgname + 1 + lgvalue + 1 ; + size_t size ; + #ifdef ESP8266 + lgname = xPortWantedSizeAlign(lgname+1); // Align name buffer + lgvalue = xPortWantedSizeAlign(lgvalue+1); // Align value buffer + // Align the whole structure + size = xPortWantedSizeAlign( sizeof(ValueList) + lgname + lgvalue ) ; + #else + size = sizeof(ValueList) + lgname + 1 + lgvalue + 1 ; + #endif + // Create new node with size to store strings if ((newNode = (ValueList *) malloc(size) ) == NULL) return ( (ValueList *) NULL ); - else - // get our buffer Safe - memset(newNode, 0, size); + + // get our buffer Safe + memset(newNode, 0, size); // Put the new node on the list me->next = newNode; diff --git a/src/LibTeleinfo.h b/src/LibTeleinfo.h index 970d9f4..5263ac0 100644 --- a/src/LibTeleinfo.h +++ b/src/LibTeleinfo.h @@ -67,6 +67,9 @@ #define TI_Debugflush #endif +#pragma pack(push) // push current alignment to stack +#pragma pack(1) // set alignment to 1 byte boundary + // Linked list structure containing all values received typedef struct _ValueList ValueList; struct _ValueList @@ -78,6 +81,8 @@ struct _ValueList char * value; // value }; +#pragma pack(pop) + // Library state machine enum _State_e { TINFO_INIT, // We're in init