Skip to content

Commit 71874db

Browse files
committed
add one to length
1 parent 222b647 commit 71874db

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

RCMv3/websiteserver.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ void startWebServer()
158158
if (request->hasParam("UIdata", true)) {
159159
const AsyncWebParameter* p = request->getParam("UIdata", true);
160160
prefs.begin("uiSettings", false, nvsPartition);
161-
boolean success = prefs.putBytes("uidata", p->value().c_str(), p->value().length());
161+
boolean success = prefs.putBytes("uidata", p->value().c_str(), p->value().length() + 1);
162162
prefs.end();
163163
if (success) {
164164
request->send(200, "text/plain", "OK");
@@ -218,8 +218,7 @@ void startWebServer()
218218
prefs.begin("uiSettings", true, nvsPartition);
219219
if (prefs.isKey("uidata")) {
220220
size_t len = prefs.getBytesLength("uidata"); // Preferences library allows long byte arrays but limits strings
221-
char buf[len + 1];
222-
buf[len] = '\0';
221+
char buf[len];
223222
prefs.getBytes("uidata", buf, len);
224223
request->send(200, "application/json", buf);
225224
} else {
@@ -232,7 +231,7 @@ void startWebServer()
232231
if (request->hasParam("miscConfigInfo", true)) {
233232
const AsyncWebParameter* p = request->getParam("miscConfigInfo", true);
234233
prefs.begin("miscConfigInfo", false, nvsPartition);
235-
boolean success = prefs.putBytes("miscConfigInfo", p->value().c_str(), p->value().length());
234+
boolean success = prefs.putBytes("miscConfigInfo", p->value().c_str(), p->value().length() + 1);
236235
prefs.end();
237236
if (success) {
238237
request->send(200, "text/plain", "OK");
@@ -248,8 +247,7 @@ void startWebServer()
248247
prefs.begin("miscConfigInfo", true, nvsPartition);
249248
if (prefs.isKey("miscConfigInfo")) {
250249
size_t len = prefs.getBytesLength("miscConfigInfo"); // Preferences library allows long byte arrays but limits strings
251-
char buf[len + 1];
252-
buf[len] = '\0';
250+
char buf[len];
253251
request->send(200, "application/json", buf);
254252
} else {
255253
request->send(200, "application/json", "{}");

0 commit comments

Comments
 (0)