1
0
Fork 0

Unity: Use UInt16.MaxValue rather than hardcoding 65536

Unity provides constants that reflect the maximum value of integer types,
use it for checking the checksum overflow rather than using 65536 directly.
This makes the intent more clear.
This commit is contained in:
Teo-CD 2023-12-16 12:30:30 +00:00
parent 91dae1be7e
commit 610ccc630a

View file

@ -99,7 +99,8 @@ public class Arduino_Com : MonoBehaviour
} while (checksumRead < 2); } while (checksumRead < 2);
// Implicit type of the sum is 4 bytes, so the overflow doesn't occur. Compute manually. // Implicit type of the sum is 4 bytes, so the overflow doesn't occur. Compute manually.
if (65536 - (BitConverter.ToUInt16(checksum) + ComputeChecksum(_pageBuffer)) == 0) if ((UInt16.MaxValue + 1) -
(BitConverter.ToUInt16(checksum) + ComputeChecksum(_pageBuffer)) == 0)
{ {
// Checksum valid, write it out to the cart. // Checksum valid, write it out to the cart.
_cart.Write(_pageBuffer); _cart.Write(_pageBuffer);