Skip to content

Commit 9e76276

Browse files
committed
add more NULL prt checks in strtok_r
Conflicts: libraries/SD/src/SD.cpp libraries/SD/src/SD.h
2 parents d050ced + 5c3508f commit 9e76276

File tree

7 files changed

+76
-69
lines changed

7 files changed

+76
-69
lines changed

hardware/esp8266com/esp8266/cores/esp8266/core_esp8266_timer.c

+6-13
Original file line numberDiff line numberDiff line change
@@ -30,39 +30,32 @@ void timer1_isr_handler(void *para){
3030
if(timer1_user_cb) timer1_user_cb();
3131
}
3232

33-
extern void __timer1_isr_init(){
33+
void timer1_isr_init(){
3434
ETS_FRC_TIMER1_INTR_ATTACH(timer1_isr_handler, NULL);
3535
}
3636

37-
extern void __timer1_attachInterrupt(void (*userFunc)(void)) {
37+
void timer1_attachInterrupt(void (*userFunc)(void)) {
3838
timer1_user_cb = userFunc;
3939
ETS_FRC1_INTR_ENABLE();
4040
}
4141

42-
extern void __timer1_detachInterrupt() {
42+
void timer1_detachInterrupt() {
4343
timer1_user_cb = 0;
4444
TEIE &= ~TEIE1;//edge int disable
4545
ETS_FRC1_INTR_DISABLE();
4646
}
4747

48-
extern void __timer1_enable(uint8_t divider, uint8_t int_type, uint8_t reload){
48+
void timer1_enable(uint8_t divider, uint8_t int_type, uint8_t reload){
4949
T1C = (1 << TCTE) | ((divider & 3) << TCPD) | ((int_type & 1) << TCIT) | ((reload & 1) << TCAR);
5050
T1I = 0;
5151
}
5252

53-
extern void __timer1_write(uint32_t ticks){
53+
void timer1_write(uint32_t ticks){
5454
T1L = ((ticks) & 0x7FFFFF);
5555
if((T1C & (1 << TCIT)) == 0) TEIE |= TEIE1;//edge int enable
5656
}
5757

58-
extern void __timer1_disable(){
58+
void timer1_disable(){
5959
T1C = 0;
6060
T1I = 0;
6161
}
62-
63-
extern void timer1_isr_init(void) __attribute__ ((weak, alias("__timer1_isr_init")));
64-
extern void timer1_detachInterrupt(void) __attribute__ ((weak, alias("__timer1_detachInterrupt")));
65-
extern void timer1_disable(void) __attribute__ ((weak, alias("__timer1_disable")));
66-
extern void timer1_attachInterrupt(void (*userFunc)(void)) __attribute__ ((weak, alias("__timer1_attachInterrupt")));
67-
extern void timer1_write(uint32_t ticks) __attribute__ ((weak, alias("__timer1_write")));
68-
extern void timer1_enable(uint8_t divider, uint8_t int_type, uint8_t reload) __attribute__ ((weak, alias("__timer1_enable")));

hardware/esp8266com/esp8266/cores/esp8266/libc_replacements.c

+10-1
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ char* ICACHE_FLASH_ATTR strtok_r(char * str, const char * delimiters, char ** te
175175
uint32_t size = 0;
176176

177177
if(str == NULL) {
178+
if(temp == NULL) {
179+
return NULL;
180+
}
178181
start = *temp;
179182
} else {
180183
start = str;
@@ -184,6 +187,10 @@ char* ICACHE_FLASH_ATTR strtok_r(char * str, const char * delimiters, char ** te
184187
return NULL;
185188
}
186189

190+
if(delimiters == NULL) {
191+
return NULL;
192+
}
193+
187194
end = start;
188195

189196
while(1) {
@@ -211,7 +218,9 @@ char* ICACHE_FLASH_ATTR strtok_r(char * str, const char * delimiters, char ** te
211218
}
212219

213220
char* ICACHE_FLASH_ATTR strtok(char * str, const char * delimiters) {
214-
return strtok_r(str, delimiters, NULL);
221+
static char * ret = NULL;
222+
ret = strtok_r(str, delimiters, &ret);
223+
return ret;
215224
}
216225

217226
int strcasecmp(const char * str1, const char * str2) {

hardware/esp8266com/esp8266/libraries/ESP8266WiFi/src/WiFiServer.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ void WiFiServer::begin()
7575

7676
extern "C" uint32_t esp_micros_at_task_start();
7777

78+
bool WiFiServer::hasClient(){
79+
if (_unclaimed) return true;
80+
return false;
81+
}
82+
7883
WiFiClient WiFiServer::available(byte* status)
7984
{
8085
static uint32_t lastPollTime = 0;

hardware/esp8266com/esp8266/libraries/ESP8266WiFi/src/WiFiServer.h

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class WiFiServer : public Server {
4444
public:
4545
WiFiServer(uint16_t port);
4646
WiFiClient available(uint8_t* status = NULL);
47+
bool hasClient();
4748
void begin();
4849
virtual size_t write(uint8_t);
4950
virtual size_t write(const uint8_t *buf, size_t size);

hardware/esp8266com/esp8266/libraries/ESP8266WiFi/src/include/ClientContext.h

+45-52
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,39 @@ class ClientContext {
3939
tcp_sent(pcb, &_s_sent);
4040
tcp_err(pcb, &_s_error);
4141
}
42-
42+
43+
err_t abort(){
44+
if(_pcb) {
45+
DEBUGV(":abort\r\n");
46+
tcp_arg(_pcb, NULL);
47+
tcp_sent(_pcb, NULL);
48+
tcp_recv(_pcb, NULL);
49+
tcp_err(_pcb, NULL);
50+
tcp_abort(_pcb);
51+
_pcb = 0;
52+
}
53+
return ERR_ABRT;
54+
}
55+
56+
err_t close(){
57+
err_t err = ERR_OK;
58+
if(_pcb) {
59+
DEBUGV(":close\r\n");
60+
tcp_arg(_pcb, NULL);
61+
tcp_sent(_pcb, NULL);
62+
tcp_recv(_pcb, NULL);
63+
tcp_err(_pcb, NULL);
64+
err = tcp_close(_pcb);
65+
if(err != ERR_OK) {
66+
DEBUGV(":tc err %d\r\n", err);
67+
tcp_abort(_pcb);
68+
err = ERR_ABRT;
69+
}
70+
_pcb = 0;
71+
}
72+
return err;
73+
}
74+
4375
~ClientContext() {
4476
}
4577

@@ -58,22 +90,11 @@ class ClientContext {
5890
}
5991

6092
void unref() {
61-
err_t err;
6293
DEBUGV(":ur %d\r\n", _refcnt);
6394
if(--_refcnt == 0) {
6495
flush();
65-
if(_pcb) {
66-
tcp_arg(_pcb, NULL);
67-
tcp_sent(_pcb, NULL);
68-
tcp_recv(_pcb, NULL);
69-
tcp_err(_pcb, NULL);
70-
err = tcp_close(_pcb);
71-
if(err != ERR_OK) {
72-
DEBUGV(":tc err %d\r\n", err);
73-
tcp_abort(_pcb);
74-
}
75-
_pcb = 0;
76-
}
96+
close();
97+
if(_discard_cb) _discard_cb(_discard_cb_arg, this);
7798
delete this;
7899
}
79100
}
@@ -179,6 +200,13 @@ class ClientContext {
179200

180201
private:
181202

203+
err_t _sent(tcp_pcb* pcb, uint16_t len) {
204+
DEBUGV(":sent %d\r\n", len);
205+
_size_sent -= len;
206+
if(_size_sent == 0 && _send_waiting) esp_schedule();
207+
return ERR_OK;
208+
}
209+
182210
void _consume(size_t size) {
183211
ptrdiff_t left = _rx_buf->len - _rx_buf_offset - size;
184212
if(left > 0) {
@@ -204,21 +232,8 @@ class ClientContext {
204232

205233
if(pb == 0) // connection closed
206234
{
207-
DEBUGV(":rcl\r\n");
208-
tcp_arg(pcb, NULL);
209-
tcp_sent(pcb, NULL);
210-
tcp_recv(pcb, NULL);
211-
tcp_err(pcb, NULL);
212-
// int error = tcp_close(pcb);
213-
// if (error != ERR_OK)
214-
{
215-
DEBUGV(":rcla\r\n");
216-
tcp_abort(pcb);
217-
_pcb = 0;
218-
return ERR_ABRT;
219-
}
220-
_pcb = 0;
221-
return ERR_OK;
235+
DEBUGV(":rcla\r\n");
236+
return abort();
222237
}
223238

224239
if(_rx_buf) {
@@ -231,27 +246,12 @@ class ClientContext {
231246
_rx_buf = pb;
232247
_rx_buf_offset = 0;
233248
}
234-
// tcp_recved(pcb, received);
235-
// pbuf_free(pb);
236249
return ERR_OK;
237250
}
238251

239252
void _error(err_t err) {
240253
DEBUGV(":er %d\r\n", err);
241-
242-
if(_pcb) {
243-
tcp_arg(_pcb, NULL);
244-
tcp_sent(_pcb, NULL);
245-
tcp_recv(_pcb, NULL);
246-
tcp_err(_pcb, NULL);
247-
err = tcp_close(_pcb);
248-
if(err != ERR_OK) {
249-
DEBUGV(":tc err %d\r\n", err);
250-
tcp_abort(_pcb);
251-
}
252-
}
253-
_pcb = 0;
254-
254+
close();
255255
if(_size_sent && _send_waiting) {
256256
esp_schedule();
257257
}
@@ -261,13 +261,6 @@ class ClientContext {
261261
return ERR_OK;
262262
}
263263

264-
err_t _sent(tcp_pcb* pcb, uint16_t len) {
265-
DEBUGV(":sent %d\r\n", len);
266-
_size_sent -= len;
267-
if(_size_sent == 0 && _send_waiting) esp_schedule();
268-
return ERR_OK;
269-
}
270-
271264
static err_t _s_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *pb, err_t err) {
272265
return reinterpret_cast<ClientContext*>(arg)->_recv(tpcb, pb, err);
273266
}

libraries/SD/src/SD.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -326,15 +326,21 @@ boolean callback_rmdir(SdFile& parentDir, char *filePathComponent,
326326
return true;
327327
}
328328

329-
boolean SDClass::begin(uint8_t csPin, uint32_t sckRateID) {
329+
330+
331+
/* Implementation of class used to create `SDCard` object. */
332+
333+
334+
335+
boolean SDClass::begin(uint8_t csPin, uint32_t speed) {
330336
/*
331337
332338
Performs the initialisation required by the sdfatlib library.
333339
334340
Return true if initialization succeeds, false otherwise.
335341
336342
*/
337-
return card.init(sckRateID, csPin) &&
343+
return card.init(speed, csPin) &&
338344
volume.init(card) &&
339345
root.openRoot(volume);
340346
}

libraries/SD/src/SD.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class SDClass {
6565
public:
6666
// This needs to be called to set up the connection to the SD card
6767
// before other methods are used.
68-
boolean begin(uint8_t csPin = SD_CHIP_SELECT_PIN, uint32_t sckRateID = SPI_FULL_SPEED);
68+
boolean begin(uint8_t csPin = SD_CHIP_SELECT_PIN, uint32_t speed = SPI_HALF_SPEED);
6969

7070
// Open the specified file/directory with the supplied mode (e.g. read or
7171
// write, etc). Returns a File object for interacting with the file.

0 commit comments

Comments
 (0)