-
Notifications
You must be signed in to change notification settings - Fork 13.3k
SNTP: configTime server cannot reference temporary char pointer #7056
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
Comments
You're right, configTime saves a pointer to the received string. It was meant for const char strings, and not for temporary strings. For the rare cases where a configurable server is needed, the user can maintain the lifetime of the string. |
I think my main problem was that it is never stated anywhere, Arduino/libraries/ArduinoOTA/ArduinoOTA.cpp Lines 79 to 81 in 50a491b
Arduino/libraries/ArduinoOTA/ArduinoOTA.h Line 74 in 50a491b
Which can be the approach here, either having static String inside setServer(), or static String array[3] in time.cpp Or, considering most common approach with hard-coded server string that is never changed, maybe just
Which I sort-of like better. edit: typos |
This is still opened. |
Could be both, just to retain the ability to hold pointers manually. // use this if your char pointers persist for the duration of the program. implementation detail!
void blah(const char* a, const char* b, const char* c);
// use this if your strings are deleted after this block ends
void blah(String a, String b, String c) {
static String _a;
static String _b;
static String _c;
_a = std::move(a);
_b = std::move(b);
_c = std::move(c);
blah(_a.c_str(), _b.c_str(), _c.c_str());
} |
Basic Infos
Platform
Settings in IDE
Problem Description
With this piece of code below:
Arduino/cores/esp8266/time.cpp
Line 61 in 63b73bf
If user does something like:
Because lwip only stores a pointer
https://git.savannah.nongnu.org/cgit/lwip.git/tree/src/apps/sntp/sntp.c?h=STABLE-2_1_x#n876
Pointer becomes garbage after some time.
Library example is not affected
MCVE Sketch
Debug Messages
The text was updated successfully, but these errors were encountered: