Skip to content

Commit 343f7df

Browse files
committed
Cherry-pick fixes to Arduino Core for our stable branch.
everslick/emonio-fw#168
1 parent b2048de commit 343f7df

File tree

7 files changed

+19
-17
lines changed

7 files changed

+19
-17
lines changed

Diff for: cores/esp32/Print.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ size_t Print::printf(const char *format, ...)
6363
len = vsnprintf(temp, len+1, format, arg);
6464
write((uint8_t*)temp, len);
6565
va_end(arg);
66-
if(len > 64){
66+
if(len >= sizeof(loc_buf)){
6767
delete[] temp;
6868
}
6969
return len;

Diff for: cores/esp32/base64.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ extern "C" {
3838
String base64::encode(uint8_t * data, size_t length)
3939
{
4040
// base64 needs more size then the source data
41-
size_t size = ((length * 1.6f) + 1);
41+
size_t size = base64_encode_expected_len(length) + 1;
4242
char * buffer = (char *) malloc(size);
4343
if(buffer) {
4444
base64_encodestate _state;

Diff for: cores/esp32/esp32-hal-uart.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ int log_printf(const char *format, ...)
420420
vsnprintf(temp, len+1, format, arg);
421421
#if !CONFIG_DISABLE_HAL_LOCKS
422422
if(_uart_bus_array[s_uart_debug_nr].lock){
423-
while (xSemaphoreTake(_uart_bus_array[s_uart_debug_nr].lock, portMAX_DELAY) != pdPASS);
423+
xSemaphoreTake(_uart_bus_array[s_uart_debug_nr].lock, portMAX_DELAY);
424424
ets_printf("%s", temp);
425425
xSemaphoreGive(_uart_bus_array[s_uart_debug_nr].lock);
426426
} else {
@@ -430,7 +430,7 @@ int log_printf(const char *format, ...)
430430
ets_printf("%s", temp);
431431
#endif
432432
va_end(arg);
433-
if(len > 64){
433+
if(len >= sizeof(loc_buf)){
434434
free(temp);
435435
}
436436
return len;

Diff for: cores/esp32/libb64/cencode.c

-9
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,10 @@ For details, see http://sourceforge.net/projects/libb64
77

88
#include "cencode.h"
99

10-
const int CHARS_PER_LINE = 72;
11-
1210
void base64_init_encodestate(base64_encodestate* state_in)
1311
{
1412
state_in->step = step_A;
1513
state_in->result = 0;
16-
state_in->stepcount = 0;
1714
}
1815

1916
char base64_encode_value(char value_in)
@@ -68,12 +65,6 @@ int base64_encode_block(const char* plaintext_in, int length_in, char* code_out,
6865
*codechar++ = base64_encode_value(result);
6966
result = (fragment & 0x03f) >> 0;
7067
*codechar++ = base64_encode_value(result);
71-
72-
++(state_in->stepcount);
73-
if (state_in->stepcount == CHARS_PER_LINE/4) {
74-
*codechar++ = '\n';
75-
state_in->stepcount = 0;
76-
}
7768
}
7869
}
7970
/* control should not reach here */

Diff for: libraries/HTTPClient/src/HTTPClient.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,10 @@ int HTTPClient::writeToStreamDataBlock(Stream * stream, int size)
10421042
readBytes = buff_size;
10431043
}
10441044

1045+
// stop if no more reading
1046+
if (readBytes == 0)
1047+
break;
1048+
10451049
// read data
10461050
int bytesRead = _tcp->readBytes(buff, readBytes);
10471051

Diff for: libraries/WiFi/src/WiFiClient.cpp

+10-3
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ class WiFiClientRxBuffer {
5858
{
5959
if(!_buffer){
6060
_buffer = (uint8_t *)malloc(_size);
61+
if(!_buffer) {
62+
log_e("Not enough memory to allocate buffer");
63+
_failed = true;
64+
return 0;
65+
}
6166
}
6267
if(_fill && _pos == _fill){
6368
_fill = 0;
@@ -67,8 +72,10 @@ class WiFiClientRxBuffer {
6772
return 0;
6873
}
6974
int res = recv(_fd, _buffer + _fill, _size - _fill, MSG_DONTWAIT);
70-
if (res < 0 && errno != EWOULDBLOCK) {
71-
_failed = true;
75+
if (res < 0) {
76+
if (errno != EWOULDBLOCK) {
77+
_failed = true;
78+
}
7279
return 0;
7380
}
7481
_fill += res;
@@ -397,7 +404,7 @@ int WiFiClient::peek()
397404

398405
int WiFiClient::available()
399406
{
400-
if(!_connected) {
407+
if(!_rxBuffer) {
401408
return 0;
402409
}
403410
int res = _rxBuffer->available();

Diff for: libraries/WiFi/src/WiFiGeneric.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ static void _start_network_event_task(){
9090
}
9191
}
9292
if(!_network_event_task_handle){
93-
xTaskCreatePinnedToCore(_network_event_task, "network_event", 4096, NULL, 2, &_network_event_task_handle, ARDUINO_RUNNING_CORE);
93+
xTaskCreatePinnedToCore(_network_event_task, "network_event", 4096, NULL, ESP_TASKD_EVENT_PRIO - 1, &_network_event_task_handle, ARDUINO_RUNNING_CORE);
9494
if(!_network_event_task_handle){
9595
log_e("Network Event Task Start Failed!");
9696
return;

0 commit comments

Comments
 (0)