fix String returned from server::arg() dropping out of scope #253
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
the
String
returned by theserver::arg
methods (likeserver::arg("POWER")
) drops out of scope right after itsc_str()
method is called.I'm using a ESP32. That implementation (https://github.com/espressif/arduino-esp32/blob/2.0.14/libraries/WebServer/src/WebServer.cpp#L549) returns a
String
by value, so once theString
returned byarg()
is out of scope, the underlyingc_str()
pointer becomes invalid.Without this fix, this was causing the web interface to not take updates — by the time the HeatPump library tried to read the various argument strings they were reset.
Fix
I'm not sure that this is a good fix, but it does work: keeping the returned
String
in scope until after thesetSettings
call ensures that the underlyingchar *
buffers aren't cleared.Maybe a better fix would be to update the settings interface to support a String optionally somehow?