Skip to content

Commit e3e25da

Browse files
committed
fix bug in WiFiClient::write_P/ESP8266WebServer::sendContent_P introduced few minutes ago when changing memccpy_P to memcpy_P
1 parent 82748a8 commit e3e25da

File tree

1 file changed

+13
-18
lines changed

1 file changed

+13
-18
lines changed

libraries/ESP8266WiFi/src/WiFiClient.cpp

+13-18
Original file line numberDiff line numberDiff line change
@@ -186,24 +186,19 @@ size_t WiFiClient::write_P(PGM_P buf, size_t size)
186186

187187
char chunkUnit[WIFICLIENT_MAX_PACKET_SIZE + 1];
188188
chunkUnit[WIFICLIENT_MAX_PACKET_SIZE] = '\0';
189-
while (buf != NULL)
190-
{
191-
size_t chunkUnitLen;
192-
PGM_P chunkNext;
193-
chunkNext = (PGM_P)memcpy_P((void*)chunkUnit, (PGM_VOID_P)buf, WIFICLIENT_MAX_PACKET_SIZE);
194-
if (chunkNext == NULL)
195-
{
196-
// no terminator, more data available
197-
buf += WIFICLIENT_MAX_PACKET_SIZE;
198-
chunkUnitLen = WIFICLIENT_MAX_PACKET_SIZE;
199-
}
200-
else
201-
{
202-
// reached terminator
203-
chunkUnitLen = chunkNext - buf;
204-
buf = NULL;
205-
}
206-
if (size < WIFICLIENT_MAX_PACKET_SIZE) chunkUnitLen = size;
189+
size_t remaining_size = size;
190+
191+
while (buf != NULL && remaining_size > 0) {
192+
size_t chunkUnitLen = WIFICLIENT_MAX_PACKET_SIZE;
193+
194+
if (remaining_size < WIFICLIENT_MAX_PACKET_SIZE) chunkUnitLen = remaining_size;
195+
// due to the memcpy signature, lots of casts are needed
196+
memcpy_P((void*)chunkUnit, (PGM_VOID_P)buf, chunkUnitLen);
197+
198+
buf += chunkUnitLen;
199+
remaining_size -= chunkUnitLen;
200+
201+
// write is so overloaded, had to use the cast to get it pick the right one
207202
_client->write((const char*)chunkUnit, chunkUnitLen);
208203
}
209204
return size;

0 commit comments

Comments
 (0)