I'm updating QNEthernet's handling of `EthernetUDP:arsePacket()` to return -1 if there's no packet available instead of zero. This allows for zero-length packets. However, I've seen examples that do things like this:
Negative values are implicitly converted to a Boolean value of true. This means that the change might break code, even though the spec specifically says that `parsePacket()` is supposed to return the packet size. (See: https://www.arduino.cc/reference/en/libraries/ethernet/ethernetudp.parsepacket/) To me this means that zero is an acceptable return value for zero-length packets, and -1 is an acceptable return value for "no packet available".
I'm wondering how much code is out there that uses the `if (packetSize)` form?
Code:
int packetSize = udp.parsePacket();
if (packetSize) { // <-- This is not correct
// ...do something...
}
Negative values are implicitly converted to a Boolean value of true. This means that the change might break code, even though the spec specifically says that `parsePacket()` is supposed to return the packet size. (See: https://www.arduino.cc/reference/en/libraries/ethernet/ethernetudp.parsepacket/) To me this means that zero is an acceptable return value for zero-length packets, and -1 is an acceptable return value for "no packet available".
I'm wondering how much code is out there that uses the `if (packetSize)` form?