Skip to content

Commit 4e7d74c

Browse files
committed
add null terminator
1 parent 4268f64 commit 4e7d74c

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

RCMv3/websiteserver.h

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
#define WEBSITESERVER_H
33

44
#include <Arduino.h>
5-
#include <WiFi.h>
65
#include <ESPAsyncWebServer.h>
76
#include <ESPmDNS.h>
87
#include <LittleFS.h>
98
#include <Preferences.h>
9+
#include <WiFi.h>
1010

1111
#include "rcmv3.h"
1212

@@ -218,7 +218,8 @@ 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];
221+
char buf[len + 1];
222+
buf[len] = '\0';
222223
prefs.getBytes("uidata", buf, len);
223224
request->send(200, "application/json", buf);
224225
} else {
@@ -230,9 +231,6 @@ void startWebServer()
230231
server.on("/saveMiscConfigInfo", HTTP_POST, [](AsyncWebServerRequest* request) {
231232
if (request->hasParam("miscConfigInfo", true)) {
232233
const AsyncWebParameter* p = request->getParam("miscConfigInfo", true);
233-
Serial.println("save ");
234-
Serial.println(p->value().c_str());
235-
Serial.println(p->value().length());
236234
prefs.begin("miscConfigInfo", false, nvsPartition);
237235
boolean success = prefs.putBytes("miscConfigInfo", p->value().c_str(), p->value().length());
238236
prefs.end();
@@ -250,11 +248,8 @@ void startWebServer()
250248
prefs.begin("miscConfigInfo", true, nvsPartition);
251249
if (prefs.isKey("miscConfigInfo")) {
252250
size_t len = prefs.getBytesLength("miscConfigInfo"); // Preferences library allows long byte arrays but limits strings
253-
char buf[len+1];
251+
char buf[len + 1];
254252
buf[len] = '\0';
255-
Serial.println("load ");
256-
Serial.println(buf);
257-
prefs.getBytes("miscConfigInfo", buf, len);
258253
request->send(200, "application/json", buf);
259254
} else {
260255
request->send(200, "application/json", "{}");

0 commit comments

Comments
 (0)