Skip to content

Commit 50d5112

Browse files
ci(pre-commit): Apply automatic fixes
1 parent a9fc5c1 commit 50d5112

File tree

1 file changed

+23
-26
lines changed

1 file changed

+23
-26
lines changed

src/AsyncJson.cpp

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
#if ASYNC_JSON_SUPPORT == 1
77

88
typedef struct {
9-
size_t length; // the size we can write into "content", not including null termination
10-
uint8_t content[1]; // this will be of size "content-length" + 1 byte to guarantee that the content is null terminated. null termination is needed for ArduinoJson 5
9+
size_t length; // the size we can write into "content", not including null termination
10+
uint8_t content
11+
[1]; // this will be of size "content-length" + 1 byte to guarantee that the content is null terminated. null termination is needed for ArduinoJson 5
1112
} AsyncJsonResponseBuffer;
1213

1314
#if ARDUINOJSON_VERSION_MAJOR == 5
@@ -125,24 +126,23 @@ void AsyncCallbackJsonWebHandler::handleRequest(AsyncWebServerRequest *request)
125126
}
126127
// this is not a GET
127128
// check if json body is too large, if it is, don't deserialize
128-
if (request->contentLength() > _maxContentLength)
129-
{
129+
if (request->contentLength() > _maxContentLength) {
130130
request->send(413);
131131
return;
132132
}
133133

134134
// try to parse body as JSON
135-
if (request->_tempObject != NULL) // see if we succeeded allocating a buffer earlier
135+
if (request->_tempObject != NULL) // see if we succeeded allocating a buffer earlier
136136
{
137-
AsyncJsonResponseBuffer * buffer = (AsyncJsonResponseBuffer*)request->_tempObject;
137+
AsyncJsonResponseBuffer *buffer = (AsyncJsonResponseBuffer *)request->_tempObject;
138138
#if ARDUINOJSON_VERSION_MAJOR == 5
139139
DynamicJsonBuffer jsonBuffer;
140-
buffer->content[buffer->length] = '\0'; // null terminate, assume we allocated one extra char
140+
buffer->content[buffer->length] = '\0'; // null terminate, assume we allocated one extra char
141141
// parse can only get null terminated strings as parameters
142142
JsonVariant json = jsonBuffer.parse(buffer->content);
143143
if (json.success()) {
144144
#elif ARDUINOJSON_VERSION_MAJOR == 6
145-
DynamicJsonDocument jsonBuffer(this->maxJsonBufferSize); // content with length > this->maxJsonBufferSize might not get deserialized
145+
DynamicJsonDocument jsonBuffer(this->maxJsonBufferSize); // content with length > this->maxJsonBufferSize might not get deserialized
146146
DeserializationError error = deserializeJson(jsonBuffer, buffer->content, buffer->length);
147147
if (!error) {
148148
JsonVariant json = jsonBuffer.as<JsonVariant>();
@@ -170,46 +170,43 @@ void AsyncCallbackJsonWebHandler::handleRequest(AsyncWebServerRequest *request)
170170

171171
void AsyncCallbackJsonWebHandler::handleBody(AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total) {
172172
if (_onRequest) {
173-
if (index == 0) // on first piece
173+
if (index == 0) // on first piece
174174
{
175175
// check nobody has already allocated the buffer
176-
if (request->_tempObject != NULL)
177-
{
176+
if (request->_tempObject != NULL) {
178177
#ifdef ESP32
179178
log_e("Temp object already in use");
180179
#endif
181-
return; // do nothing else here, handleRequest will return a HTTP error
180+
return; // do nothing else here, handleRequest will return a HTTP error
182181
}
183182
// check total size is valid
184-
if (total >= _maxContentLength)
185-
{
186-
return; // do nothing else here, handleRequest will return a HTTP error
183+
if (total >= _maxContentLength) {
184+
return; // do nothing else here, handleRequest will return a HTTP error
187185
}
188186
// allocate buffer
189-
request->_tempObject = calloc(1, sizeof(AsyncJsonResponseBuffer) + total); // normally _tempObject will be "free"ed by the destructor of the request, but can release earlier if desired.
190-
if (request->_tempObject == NULL) { // if allocation failed
187+
request->_tempObject = calloc(
188+
1, sizeof(AsyncJsonResponseBuffer) + total
189+
); // normally _tempObject will be "free"ed by the destructor of the request, but can release earlier if desired.
190+
if (request->_tempObject == NULL) { // if allocation failed
191191
#ifdef ESP32
192192
log_e("Failed to allocate");
193193
#endif
194-
return; // do nothing else here, handleRequest will return a HTTP error
194+
return; // do nothing else here, handleRequest will return a HTTP error
195195
}
196-
((AsyncJsonResponseBuffer*)request->_tempObject)->length = total; // store the size of allocation we made into _tempObject
196+
((AsyncJsonResponseBuffer *)request->_tempObject)->length = total; // store the size of allocation we made into _tempObject
197197
}
198198

199199
// add data to the buffer if the buffer exists
200200
if (request->_tempObject != NULL) {
201-
AsyncJsonResponseBuffer * buffer = (AsyncJsonResponseBuffer*)request->_tempObject;
201+
AsyncJsonResponseBuffer *buffer = (AsyncJsonResponseBuffer *)request->_tempObject;
202202
// check if the buffer is the right size so we don't write out of bounds
203-
if (buffer->length >= total && buffer->length >= index + len)
204-
{
203+
if (buffer->length >= total && buffer->length >= index + len) {
205204
memcpy(buffer->content + index, data, len);
206-
}
207-
else
208-
{
205+
} else {
209206
#ifdef ESP32
210207
log_e("Bad size of temp buffer");
211208
#endif
212-
return; // do nothing else here
209+
return; // do nothing else here
213210
}
214211
}
215212
}

0 commit comments

Comments
 (0)