Skip to content

Commit 172a88d

Browse files
ci(pre-commit): Apply automatic fixes
1 parent 2070e49 commit 172a88d

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

src/AsyncJson.cpp

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -120,20 +120,19 @@ void AsyncCallbackJsonWebHandler::handleRequest(AsyncWebServerRequest *request)
120120
}
121121
// this is not a GET
122122
// check if body is too large, if it is, don't parse
123-
if (request->contentLength() > _maxContentLength)
124-
{
123+
if (request->contentLength() > _maxContentLength) {
125124
request->send(413);
126125
return;
127126
}
128127

129128
// try to parse body as JSON
130-
if (request->_tempObject != NULL)
131-
{
132-
size_t dataSize = min(request->contentLength(), request->_tempSize); // smaller value of contentLength or the size of the buffer. normally those should match.
129+
if (request->_tempObject != NULL) {
130+
size_t dataSize =
131+
min(request->contentLength(), request->_tempSize); // smaller value of contentLength or the size of the buffer. normally those should match.
133132
#if ARDUINOJSON_VERSION_MAJOR == 5
134133
DynamicJsonBuffer jsonBuffer;
135-
uint8_t * p = (uint8_t *)(request->_tempObject);
136-
p[dataSize] = '\0'; // null terminate, assume we allocated one extra char
134+
uint8_t *p = (uint8_t *)(request->_tempObject);
135+
p[dataSize] = '\0'; // null terminate, assume we allocated one extra char
137136
// parse can only get null terminated strings as parameters
138137
JsonVariant json = jsonBuffer.parse(p);
139138
if (json.success()) {
@@ -156,32 +155,29 @@ void AsyncCallbackJsonWebHandler::handleRequest(AsyncWebServerRequest *request)
156155
}
157156
// there is no body, no buffer or we had an error parsing the body
158157
request->send(400);
159-
} else { // if no _onRequest
158+
} else { // if no _onRequest
160159
request->send(500);
161160
}
162161
}
163162

164163
void AsyncCallbackJsonWebHandler::handleBody(AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total) {
165164
if (_onRequest) {
166-
if (total > 0 && request->_tempObject == NULL && total < _maxContentLength) { // if request content length is valid size and we have no content buffer yet
167-
request->_tempObject = malloc(total + 1); // allocate one additional byte so we can null terminate this buffer (needed for ArduinoJson 5)
168-
if (request->_tempObject == NULL) { // if allocation failed
165+
if (total > 0 && request->_tempObject == NULL && total < _maxContentLength) { // if request content length is valid size and we have no content buffer yet
166+
request->_tempObject = malloc(total + 1); // allocate one additional byte so we can null terminate this buffer (needed for ArduinoJson 5)
167+
if (request->_tempObject == NULL) { // if allocation failed
169168
#ifdef ESP32
170169
log_e("Failed to allocate");
171170
#endif
172171
request->abort();
173172
return;
174173
}
175-
request->_tempSize = total; // store the size of allocation we made into _tempSize
174+
request->_tempSize = total; // store the size of allocation we made into _tempSize
176175
}
177176
if (request->_tempObject != NULL) {
178177
// check if the buffer is the right size so we don't write out of bounds
179-
if (request->_tempSize >= total)
180-
{
178+
if (request->_tempSize >= total) {
181179
memcpy((uint8_t *)(request->_tempObject) + index, data, len);
182-
}
183-
else
184-
{
180+
} else {
185181
#ifdef ESP32
186182
log_e("Bad size of temp buffer");
187183
#endif

0 commit comments

Comments
 (0)