Fix label name corruption + ESP32
Fixed buffer corruption added ESP32 compatibility
This commit is contained in:
parent
ee5e5ddfc3
commit
d5ae0803e0
|
@ -124,7 +124,7 @@ Input : -
|
||||||
Output : -
|
Output : -
|
||||||
Comments: -
|
Comments: -
|
||||||
====================================================================== */
|
====================================================================== */
|
||||||
uint8_t TInfo::clearBuffer()
|
void TInfo::clearBuffer()
|
||||||
{
|
{
|
||||||
// Clear our buffer, set index to 0
|
// Clear our buffer, set index to 0
|
||||||
memset(_recv_buff, 0, TINFO_BUFSIZE);
|
memset(_recv_buff, 0, TINFO_BUFSIZE);
|
||||||
|
@ -209,10 +209,10 @@ ValueList * TInfo::valueAdd(char * name, char * value, uint8_t checksum, uint8_t
|
||||||
// go to next node
|
// go to next node
|
||||||
me = me->next;
|
me = me->next;
|
||||||
|
|
||||||
// Check if we already have this LABEL
|
// Check if we already have this LABEL (same name AND same size)
|
||||||
if (strncmp(me->name, name, lgname) == 0) {
|
if (lgname==strlen(me->name) && strncmp(me->name, name, lgname)==0) {
|
||||||
// Already got also this value, return US
|
// Already got also this value return US
|
||||||
if (strncmp(me->value, value, lgvalue) == 0) {
|
if (lgvalue==strlen(me->value) && strncmp(me->value, value, lgvalue) == 0) {
|
||||||
*flags |= TINFO_FLAGS_EXIST;
|
*flags |= TINFO_FLAGS_EXIST;
|
||||||
me->flags = *flags;
|
me->flags = *flags;
|
||||||
return ( me );
|
return ( me );
|
||||||
|
@ -223,7 +223,7 @@ ValueList * TInfo::valueAdd(char * name, char * value, uint8_t checksum, uint8_t
|
||||||
// Do we have enought space to hold new value ?
|
// Do we have enought space to hold new value ?
|
||||||
if (strlen(me->value) >= lgvalue ) {
|
if (strlen(me->value) >= lgvalue ) {
|
||||||
// Copy it
|
// Copy it
|
||||||
strncpy(me->value, value , lgvalue );
|
strlcpy(me->value, value , lgvalue );
|
||||||
me->checksum = checksum ;
|
me->checksum = checksum ;
|
||||||
|
|
||||||
// That's all
|
// That's all
|
||||||
|
@ -248,11 +248,11 @@ ValueList * TInfo::valueAdd(char * name, char * value, uint8_t checksum, uint8_t
|
||||||
// + Name + '\0'
|
// + Name + '\0'
|
||||||
// + Value + '\0'
|
// + Value + '\0'
|
||||||
size_t size ;
|
size_t size ;
|
||||||
#ifdef ESP8266
|
#if defined (ESP8266) || defined (ESP32)
|
||||||
lgname = ESP8266_allocAlign(lgname+1); // Align name buffer
|
lgname = ESP_allocAlign(lgname+1); // Align name buffer
|
||||||
lgvalue = ESP8266_allocAlign(lgvalue+1); // Align value buffer
|
lgvalue = ESP_allocAlign(lgvalue+1); // Align value buffer
|
||||||
// Align the whole structure
|
// Align the whole structure
|
||||||
size = ESP8266_allocAlign( sizeof(ValueList) + lgname + lgvalue ) ;
|
size = ESP_allocAlign( sizeof(ValueList) + lgname + lgvalue ) ;
|
||||||
#else
|
#else
|
||||||
size = sizeof(ValueList) + lgname + 1 + lgvalue + 1 ;
|
size = sizeof(ValueList) + lgname + 1 + lgvalue + 1 ;
|
||||||
#endif
|
#endif
|
||||||
|
@ -421,12 +421,12 @@ char * TInfo::valueGet(char * name, char * value)
|
||||||
me = me->next;
|
me = me->next;
|
||||||
|
|
||||||
// Check if we match this LABEL
|
// Check if we match this LABEL
|
||||||
if (strncmp(me->name, name, lgname) == 0) {
|
if (lgname==strlen(me->name) && strncmp(me->name, name, lgname)==0) {
|
||||||
// this one has a value ?
|
// this one has a value ?
|
||||||
if (me->value) {
|
if (me->value) {
|
||||||
// copy to dest buffer
|
// copy to dest buffer
|
||||||
uint8_t lgvalue = strlen(me->value);
|
uint8_t lgvalue = strlen(me->value);
|
||||||
strncpy(value, me->value , lgvalue );
|
strlcpy(value, me->value , lgvalue );
|
||||||
return ( value );
|
return ( value );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -471,17 +471,19 @@ uint8_t TInfo::valuesDump(void)
|
||||||
TI_Debug(index) ;
|
TI_Debug(index) ;
|
||||||
TI_Debug(F(") ")) ;
|
TI_Debug(F(") ")) ;
|
||||||
|
|
||||||
if (me->name)
|
if (me->name) {
|
||||||
TI_Debug(me->name) ;
|
TI_Debug(me->name) ;
|
||||||
else
|
} else {
|
||||||
TI_Debug(F("NULL")) ;
|
TI_Debug(F("NULL")) ;
|
||||||
|
}
|
||||||
|
|
||||||
TI_Debug(F("=")) ;
|
TI_Debug(F("=")) ;
|
||||||
|
|
||||||
if (me->value)
|
if (me->value) {
|
||||||
TI_Debug(me->value) ;
|
TI_Debug(me->value) ;
|
||||||
else
|
} else {
|
||||||
TI_Debug(F("NULL")) ;
|
TI_Debug(F("NULL")) ;
|
||||||
|
}
|
||||||
|
|
||||||
TI_Debug(F(" '")) ;
|
TI_Debug(F(" '")) ;
|
||||||
TI_Debug(me->checksum) ;
|
TI_Debug(me->checksum) ;
|
||||||
|
@ -491,12 +493,15 @@ uint8_t TInfo::valuesDump(void)
|
||||||
if ( me->flags) {
|
if ( me->flags) {
|
||||||
TI_Debug(F("Flags:0x"));
|
TI_Debug(F("Flags:0x"));
|
||||||
TI_Debugf("%02X =>", me->flags);
|
TI_Debugf("%02X =>", me->flags);
|
||||||
if ( me->flags & TINFO_FLAGS_EXIST)
|
if ( me->flags & TINFO_FLAGS_EXIST) {
|
||||||
TI_Debug(F("Exist ")) ;
|
TI_Debug(F("Exist ")) ;
|
||||||
if ( me->flags & TINFO_FLAGS_UPDATED)
|
}
|
||||||
|
if ( me->flags & TINFO_FLAGS_UPDATED) {
|
||||||
TI_Debug(F("Updated ")) ;
|
TI_Debug(F("Updated ")) ;
|
||||||
if ( me->flags & TINFO_FLAGS_ADDED)
|
}
|
||||||
|
if ( me->flags & TINFO_FLAGS_ADDED) {
|
||||||
TI_Debug(F("New ")) ;
|
TI_Debug(F("New ")) ;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TI_Debugln() ;
|
TI_Debugln() ;
|
||||||
|
@ -570,8 +575,7 @@ Comments: return '\0' in case of error
|
||||||
====================================================================== */
|
====================================================================== */
|
||||||
unsigned char TInfo::calcChecksum(char *etiquette, char *valeur)
|
unsigned char TInfo::calcChecksum(char *etiquette, char *valeur)
|
||||||
{
|
{
|
||||||
uint8_t i ;
|
uint8_t sum = ' '; // Somme des codes ASCII du message + un espace
|
||||||
uint8_t sum = ' '; // Somme des codes ASCII du message + un espace
|
|
||||||
|
|
||||||
// avoid dead loop, always check all is fine
|
// avoid dead loop, always check all is fine
|
||||||
if (etiquette && valeur) {
|
if (etiquette && valeur) {
|
||||||
|
@ -643,7 +647,7 @@ ValueList * TInfo::checkLine(char * pline)
|
||||||
char checksum;
|
char checksum;
|
||||||
char buff[TINFO_BUFSIZE];
|
char buff[TINFO_BUFSIZE];
|
||||||
uint8_t flags = TINFO_FLAGS_NONE;
|
uint8_t flags = TINFO_FLAGS_NONE;
|
||||||
boolean err = true ; // Assume error
|
//boolean err = true ; // Assume error
|
||||||
int len ; // Group len
|
int len ; // Group len
|
||||||
|
|
||||||
if (pline==NULL)
|
if (pline==NULL)
|
||||||
|
@ -657,7 +661,7 @@ ValueList * TInfo::checkLine(char * pline)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
// Get our own working copy
|
// Get our own working copy
|
||||||
strncpy( buff, _recv_buff, len+1);
|
strlcpy( buff, _recv_buff, len+1);
|
||||||
|
|
||||||
p = &buff[0];
|
p = &buff[0];
|
||||||
ptok = p; // for sure we start with token name
|
ptok = p; // for sure we start with token name
|
||||||
|
@ -832,6 +836,8 @@ _State_e TInfo::process(char c)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return _state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -67,12 +67,11 @@
|
||||||
#define TI_Debugflush
|
#define TI_Debugflush
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ESP8266
|
#if defined (ESP8266) || defined (ESP32)
|
||||||
// For 4 bytes Aligment boundaries
|
// For 4 bytes Aligment boundaries
|
||||||
#define ESP8266_allocAlign(size) ((size + 3) & ~((size_t) 3))
|
#define ESP_allocAlign(size) ((size + 3) & ~((size_t) 3))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#pragma pack(push) // push current alignment to stack
|
#pragma pack(push) // push current alignment to stack
|
||||||
#pragma pack(1) // set alignment to 1 byte boundary
|
#pragma pack(1) // set alignment to 1 byte boundary
|
||||||
|
|
||||||
|
@ -133,7 +132,7 @@ class TInfo
|
||||||
unsigned char calcChecksum(char *etiquette, char *valeur) ;
|
unsigned char calcChecksum(char *etiquette, char *valeur) ;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint8_t clearBuffer();
|
void clearBuffer();
|
||||||
ValueList * valueAdd (char * name, char * value, uint8_t checksum, uint8_t * flags);
|
ValueList * valueAdd (char * name, char * value, uint8_t checksum, uint8_t * flags);
|
||||||
boolean valueRemove (char * name);
|
boolean valueRemove (char * name);
|
||||||
boolean valueRemoveFlagged(uint8_t flags);
|
boolean valueRemoveFlagged(uint8_t flags);
|
||||||
|
|
Loading…
Reference in New Issue