Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Dec 22, 2022

Conversation

alastaira
Copy link

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.

Fixed strlen to strlen_P when accessing variable type array stored in PROGMEM.
@fredilarsen fredilarsen merged commit 37bdc2a into fredilarsen:master Dec 22, 2022
@fredilarsen
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants