1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-21 10:26:06 +03:00

Correct out of bounds condition and remove an unnecessary cast (#5924)

C arrays are 0 indexed, accordingly writing to array[255] actually writes to the 256th position, which is naturally out of bounds of a 255 item array. increasing the size of the array to 256 corrects that error. Also, 0 is an int and requires a cast into a char, '\0' is just a cleaner (a more syntactically pedantic) way to achieve the same end.
This commit is contained in:
ufocia 2019-03-27 19:27:20 -05:00 committed by Earle F. Philhower, III
parent 2e75e88c49
commit f139519061

View File

@ -35,7 +35,7 @@ Once we have libraries in place we need to create a ``WiFiUDP`` object. Then we
WiFiUDP Udp;
unsigned int localUdpPort = 4210;
char incomingPacket[255];
char incomingPacket[256];
char replyPacket[] = "Hi there! Got the message :-)";
Wi-Fi Connection
@ -68,7 +68,7 @@ Waiting for incoming UDP packed is done by the following code:
int len = Udp.read(incomingPacket, 255);
if (len > 0)
{
incomingPacket[len] = 0;
incomingPacket[len] = '\0';
}
Serial.printf("UDP packet contents: %s\n", incomingPacket);