Structure Alignement on linked list for ESP8266

This commit is contained in:
Charles 2016-05-09 14:09:58 +02:00
parent a8126052a4
commit bd040bc227
2 changed files with 18 additions and 4 deletions

View File

@ -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;

View File

@ -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