Check counter rollover the opposite way

FFFF and 0000 -> prefer 0000
FFFF and 0001 -> prefer 0001
...
FFFF and FFFE -> prefer FFFF

they shouldn't be desync'd (incremental); only the uninitialized case is important to handle.
This commit is contained in:
Kurt
2020-07-02 17:44:03 -05:00
parent 5d8a5ba045
commit afdd40bcee

View File

@@ -35,10 +35,10 @@ public static int CompareFooters(byte[] data, int offset1, int offset2)
private static int CompareCounters(uint counter1, uint counter2)
{
// Uninitialized
if (counter1 == uint.MaxValue && counter2 == 0)
// Uninitialized -- only continue if a rollover case (humanly impossible)
if (counter1 == uint.MaxValue && counter2 != uint.MaxValue - 1)
return Second;
if (counter1 == 0 && counter2 == uint.MaxValue)
if (counter2 == uint.MaxValue && counter1 != uint.MaxValue - 1)
return First;
// Different