Skip to content

Commit fb0642b

Browse files
author
QuickSander
committed
strtok -> strtok_r
1 parent 3fd9f84 commit fb0642b

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/internals/StreamHttpRequest.hpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
#include <Arduino.h>
1919

20+
#include <string.h>
21+
2022
namespace ArduinoHttpServer
2123
{
2224

@@ -90,6 +92,8 @@ class StreamHttpRequest
9092

9193
ResultEnum m_result;
9294
String m_errorDescription;
95+
96+
char *m_lineBufferStrTokContext;
9397
};
9498

9599
}
@@ -110,7 +114,8 @@ ArduinoHttpServer::StreamHttpRequest<MAX_BODY_LENGTH>::StreamHttpRequest(Stream&
110114
m_contentTypeField(),
111115
m_contentLengthField(),
112116
m_result(ResultOk),
113-
m_errorDescription()
117+
m_errorDescription(),
118+
m_lineBufferStrTokContext(0)
114119
{
115120
m_stream.setTimeout(LINE_READ_TIMEOUT_MS);
116121
}
@@ -214,7 +219,7 @@ void ArduinoHttpServer::StreamHttpRequest<MAX_BODY_LENGTH>::parseMethod(char lin
214219
if(m_result!=ResultOk) { return; }
215220

216221
// First strtok call, initialize with cached line buffer.
217-
String token(strtok(lineBuffer, " "));
222+
String token(strtok_r(lineBuffer, " ", &m_lineBufferStrTokContext));
218223

219224
if(token == "GET")
220225
{
@@ -245,7 +250,7 @@ void ArduinoHttpServer::StreamHttpRequest<MAX_BODY_LENGTH>::parseVersion()
245250
{
246251
if(m_result!=ResultOk) { return; }
247252

248-
String version(strtok(0, " "));
253+
String version(strtok_r(0, " ", &m_lineBufferStrTokContext));
249254
int slashPosition = version.lastIndexOf('/');
250255

251256
// String returns unsigned int for length.
@@ -268,7 +273,7 @@ void ArduinoHttpServer::StreamHttpRequest<MAX_BODY_LENGTH>::parseResource()
268273
{
269274
if(m_result!=ResultOk) { return; }
270275

271-
String resource( strtok(0, " ") );
276+
String resource( strtok_r(0, " ", &m_lineBufferStrTokContext) );
272277
m_resource = ArduinoHttpServer::HttpResource(resource);
273278

274279
if (!m_resource.isValid())
@@ -280,7 +285,7 @@ void ArduinoHttpServer::StreamHttpRequest<MAX_BODY_LENGTH>::parseResource()
280285
template <size_t MAX_BODY_LENGTH>
281286
void ArduinoHttpServer::StreamHttpRequest<MAX_BODY_LENGTH>::neglectToken()
282287
{
283-
strtok(0, " ");
288+
strtok_r(0, " ", &m_lineBufferStrTokContext);
284289
}
285290

286291
template <size_t MAX_BODY_LENGTH>

0 commit comments

Comments
 (0)