Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit01864ad

Browse files
committed
Changed to mutable char* for reading config
1 parenta9a0e7e commit01864ad

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

‎src/thing/Config.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ void Config::SerializeToJson(Stream* output, std::function<void(int size)> handl
2626
root.printTo(*output);
2727
}
2828

29-
voidConfig::ReadFromJson(constchar* string) {
29+
voidConfig::ReadFromJson(char* string) {
3030
DynamicJsonBuffer jsonBuffer;
3131
JsonObject& root = jsonBuffer.parseObject(string);
3232
host = root["host"].asString();

‎src/thing/Config.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ struct Config {
3131
Pins pins;
3232

3333
voidSerializeToJson(Stream* output, std::function<void(int size)> handle_size)const;
34-
voidReadFromJson(constchar* string);
34+
35+
// We need a mutable char array here, otherwise a copy will be made.
36+
voidReadFromJson(char* string);
3537
};
3638

3739
}// namespace thing

‎src/thing/FireThing.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ bool FireThing::ReadConfigFromStorage(Config* config) {
9191
SPIFFS.end();
9292
returnfalse;
9393
}
94-
config->ReadFromJson(cfg.readString().c_str());
94+
char buffer[cfg.size()];
95+
cfg.readBytes(buffer, cfg.size());
96+
config->ReadFromJson(buffer);
9597
debug_("Config read from disk.");
9698
}
9799

‎src/thing/Portal.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,16 @@ void Portal::Start(const Config& config) {
125125
debug_("Config updated called without param.");
126126
return;
127127
}
128-
String config = server_.arg("config");
129-
config_.ReadFromJson(config.c_str());
128+
129+
char* buffer;
130+
{// Scoped to free String memory.
131+
String config = server_.arg("config");
132+
buffer = (char*)malloc(config.length+1());
133+
memcpy(buffer, config.c_str(), config.length()+1);
134+
}
135+
config_.ReadFromJson(buffer);
136+
free(buffer);
137+
130138
callback_(config_);
131139
server_.send(200,"text/plain","");
132140
debug_("config updated.");

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp