Skip to content

Commit

Permalink
Structure Alignement on linked list for ESP8266
Browse files Browse the repository at this point in the history
  • Loading branch information
hallard committed May 9, 2016
1 parent a812605 commit bd040bc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/LibTeleinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions src/LibTeleinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -78,6 +81,8 @@ struct _ValueList
char * value; // value
};

#pragma pack(pop)

// Library state machine
enum _State_e {
TINFO_INIT, // We're in init
Expand Down

0 comments on commit bd040bc

Please sign in to comment.