Packet with zero data length (#1659)

If you receive a package with a data length of zero, parsePacket returns 0, but rx_buffer will exist. So if another parsePacket with no read access returns to zeros, there is still data that can be read. This example would not work: https://www.arduino.cc/en/Reference/EthernetUDPParsePacket

Also I added a check if rx_buffer exit when you try to flush it.
This commit is contained in:
Schuemi 2018-07-24 19:52:42 +02:00 committed by Me No Dev
parent da798c7db0
commit f1f8d7e306

View File

@ -221,6 +221,7 @@ int WiFiUDP::parsePacket(){
} }
remote_ip = IPAddress(si_other.sin_addr.s_addr); remote_ip = IPAddress(si_other.sin_addr.s_addr);
remote_port = ntohs(si_other.sin_port); remote_port = ntohs(si_other.sin_port);
if (len == 0) return 0;
rx_buffer = new cbuf(len); rx_buffer = new cbuf(len);
rx_buffer->write(buf, len); rx_buffer->write(buf, len);
delete[] buf; delete[] buf;
@ -264,6 +265,7 @@ int WiFiUDP::peek(){
} }
void WiFiUDP::flush(){ void WiFiUDP::flush(){
if(!rx_buffer) return;
cbuf *b = rx_buffer; cbuf *b = rx_buffer;
rx_buffer = 0; rx_buffer = 0;
delete b; delete b;