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:
trotFunky 2023-12-16 14:10:28 +00:00
parent aa610666bd
commit ba6b31dbf2

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);