fredilarsen / ModuleInterface

Easy config and value sync between IoT modules, database and web pages
Other
71 stars 12 forks source link

Correct strlen to strlen_P when accessing PROGMEM in ModuleVariable.h #14

Closed alastaira closed 1 year ago

alastaira commented 2 years ago

Hi! I was unable to compile any of the examples for an ESP8266 board (a Wemos D1 Mini, to be specific) - a memory fault appeared to be causing an infinite reset when attempting to set the contract (which I found odd since it's the same board depicted in the images accompanying the https://github.com/fredilarsen/ModuleInterface/tree/master/examples/WebPage )

After some digging through the code, I believe I have found the problem: In ModuleVariable.cpp, variable type names are stored in a PROGMEM char array:

const char ModuleVariableTypeNames[] PROGMEM = "--b1u1u2u4i1i2i4f4";

However, the length of this array is accessed using strlen() in the get_type() function:

uint8_t len = (uint8_t) strlen(get_mv_type_names()) / 2;

This appears to compile and run ok under AVR architecture (even though it shouldn't), but causes a memory fault on ESP8266 boards. The attached PR fixes this issue by using the strlen_P() function intead.

fredilarsen commented 1 year ago

Thank you for the find and the fix. Really appreciated.