Skip to content

Commit f139519

Browse files
ufociaearlephilhower
authored andcommitted
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.
1 parent 2e75e88 commit f139519

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

doc/esp8266wifi/udp-examples.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Once we have libraries in place we need to create a ``WiFiUDP`` object. Then we
3535
3636
WiFiUDP Udp;
3737
unsigned int localUdpPort = 4210;
38-
char incomingPacket[255];
38+
char incomingPacket[256];
3939
char replyPacket[] = "Hi there! Got the message :-)";
4040
4141
Wi-Fi Connection
@@ -68,7 +68,7 @@ Waiting for incoming UDP packed is done by the following code:
6868
int len = Udp.read(incomingPacket, 255);
6969
if (len > 0)
7070
{
71-
incomingPacket[len] = 0;
71+
incomingPacket[len] = '\0';
7272
}
7373
Serial.printf("UDP packet contents: %s\n", incomingPacket);
7474

0 commit comments

Comments
 (0)