mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +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:
parent
2e75e88c49
commit
f139519061
@ -35,7 +35,7 @@ Once we have libraries in place we need to create a ``WiFiUDP`` object. Then we
|
|||||||
|
|
||||||
WiFiUDP Udp;
|
WiFiUDP Udp;
|
||||||
unsigned int localUdpPort = 4210;
|
unsigned int localUdpPort = 4210;
|
||||||
char incomingPacket[255];
|
char incomingPacket[256];
|
||||||
char replyPacket[] = "Hi there! Got the message :-)";
|
char replyPacket[] = "Hi there! Got the message :-)";
|
||||||
|
|
||||||
Wi-Fi Connection
|
Wi-Fi Connection
|
||||||
@ -68,7 +68,7 @@ Waiting for incoming UDP packed is done by the following code:
|
|||||||
int len = Udp.read(incomingPacket, 255);
|
int len = Udp.read(incomingPacket, 255);
|
||||||
if (len > 0)
|
if (len > 0)
|
||||||
{
|
{
|
||||||
incomingPacket[len] = 0;
|
incomingPacket[len] = '\0';
|
||||||
}
|
}
|
||||||
Serial.printf("UDP packet contents: %s\n", incomingPacket);
|
Serial.printf("UDP packet contents: %s\n", incomingPacket);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user