Skip to content
This repository has been archived by the owner on Dec 18, 2018. It is now read-only.

Commit

Permalink
Remove unnecessary check
Browse files Browse the repository at this point in the history
  • Loading branch information
benaadams committed Jan 10, 2017
1 parent 3297a9a commit 4436860
Showing 1 changed file with 4 additions and 4 deletions.
Expand Up @@ -253,9 +253,9 @@ public static unsafe void ValidateHeaderCharacters(string headerCharacters)
}

// Non-vector testing:
// Flag > 0x007f => Use value directly, already flagged
// Flag 0x7f => Add 0x0001 to each char so DEL (0x7f) will set a high bit
// Flag < 0x20 => Sub 0x0020 from each char so high bit will be set in previous char bit
// Flag > 0x007f => All but highest bit picked up by 0x7f flagging, highest bit picked up by < 0x20 flagging
// Bitwise | or the above three together
// Bitwise & and each char with 0xff80; result should be 0 if all tests pass
if (offset + sizeof(ulong) <= length)
Expand All @@ -264,7 +264,7 @@ public static unsafe void ValidateHeaderCharacters(string headerCharacters)
{
var stringUlong = (ulong*)(pHeader + offset);
offset += sizeof(ulong);
if (((*stringUlong | (*stringUlong + 0x0001000100010001UL) | (*stringUlong - 0x0020002000200020UL)) & 0xff80ff80ff80ff80UL) != 0)
if ((((*stringUlong + 0x0001000100010001UL) | (*stringUlong - 0x0020002000200020UL)) & 0xff80ff80ff80ff80UL) != 0)
{
ThrowInvalidHeaderCharacter(pHeader + offset, sizeof(ulong));
}
Expand All @@ -274,7 +274,7 @@ public static unsafe void ValidateHeaderCharacters(string headerCharacters)
{
var stringUint = (uint*)(pHeader + offset);
offset += sizeof(uint);
if (((*stringUint | (*stringUint + 0x00010001u) | (*stringUint - 0x00200020u)) & 0xff80ff80u) != 0)
if ((((*stringUint + 0x00010001u) | (*stringUint - 0x00200020u)) & 0xff80ff80u) != 0)
{
ThrowInvalidHeaderCharacter(pHeader + offset, sizeof(uint));
}
Expand All @@ -283,7 +283,7 @@ public static unsafe void ValidateHeaderCharacters(string headerCharacters)
{
var stringUshort = (ushort*)(pHeader + offset);
offset += sizeof(ushort);
if (((*stringUshort | (*stringUshort + 0x0001u) | (*stringUshort - 0x0020u)) & 0xff80u) != 0)
if ((((*stringUshort + 0x0001u) | (*stringUshort - 0x0020u)) & 0xff80u) != 0)
{
ThrowInvalidHeaderCharacter(pHeader + offset, sizeof(ushort));
}
Expand Down

0 comments on commit 4436860

Please sign in to comment.