What's Wrong With the Code - 01
Contents
| |
What's wrong with the code?
On line 8, we have a comparison length > max which will return an error if the length of the data exceeds the buffer size.
However, we are comparing an unsigned short to a short.
If get_network_short(sockfd) (line 6) returns a value greater than 65535 / 2, for example 32768, then due to length being a signed variable the value stored will actually be negative.
Upon comparison, we’ll actually be comparing -32768 > max, which will always return false.
Hence, the code to raise the bad length error will never be called!