Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Off by one error in Packet::CanWriteToPacket #9361

Closed
JGRennison opened this issue Jun 12, 2021 · 0 comments
Closed

Off by one error in Packet::CanWriteToPacket #9361

JGRennison opened this issue Jun 12, 2021 · 0 comments

Comments

@JGRennison
Copy link
Contributor

@JGRennison JGRennison commented Jun 12, 2021

Version of OpenTTD

master (at least since a2051ba)

Details

Packet::CanWriteToPacket treats Packet::limit as an exclusive bound on the packet size, such that the packet size must always be < the limit.
Other functions such as Packet::Send_bytes and Packet::ParsePacketSize treat Packet::limit as an inclusive bound on the packet size, such that the packet size must always be <= the limit.

The latter interpretation would make more sense as the "correct" behaviour, so it would seem better to correct Packet::CanWriteToPacket to match the others instead of the other way around?

If data to send is sized to fill the packet limit exactly using the latter interpretation of the limit (I made this assumption before noticing the discrepancy) an assertion is triggered.

rubidium42 added a commit to rubidium42/OpenTTD that referenced this issue Jun 13, 2021
Previously it did not allow writing a byte to a packet that was of size limit - 1 anymore.
rubidium42 added a commit that referenced this issue Jun 13, 2021
Previously it did not allow writing a byte to a packet that was of size limit - 1 anymore.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

1 participant