REFACTOR: Add parentheses to avoid non-obvious precedence.

This commit is contained in:
2017-12-20 17:38:12 +00:00
parent 35dec4dad3
commit 3c843c3b06
8 changed files with 25 additions and 25 deletions

View File

@@ -148,7 +148,7 @@ namespace DiscImageChef.Checksums
} }
for(int i = 0; i < fileStream.Length; i++) for(int i = 0; i < fileStream.Length; i++)
localhashInt = (ushort)((localhashInt >> 8) ^ localTable[fileStream.ReadByte() ^ localhashInt & 0xff]); localhashInt = (ushort)((localhashInt >> 8) ^ localTable[fileStream.ReadByte() ^ (localhashInt & 0xff)]);
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian; BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
hash = BigEndianBitConverter.GetBytes(localhashInt); hash = BigEndianBitConverter.GetBytes(localhashInt);
@@ -200,7 +200,7 @@ namespace DiscImageChef.Checksums
} }
for(int i = 0; i < len; i++) for(int i = 0; i < len; i++)
localhashInt = (ushort)((localhashInt >> 8) ^ localTable[data[i] ^ localhashInt & 0xff]); localhashInt = (ushort)((localhashInt >> 8) ^ localTable[data[i] ^ (localhashInt & 0xff)]);
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian; BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
hash = BigEndianBitConverter.GetBytes(localhashInt); hash = BigEndianBitConverter.GetBytes(localhashInt);

View File

@@ -73,7 +73,7 @@ namespace DiscImageChef.Checksums
/// <param name="len">Length of buffer to hash.</param> /// <param name="len">Length of buffer to hash.</param>
public void Update(byte[] data, uint len) public void Update(byte[] data, uint len)
{ {
for(int i = 0; i < len; i++) hashInt = (hashInt >> 8) ^ table[data[i] ^ hashInt & 0xff]; for(int i = 0; i < len; i++) hashInt = (hashInt >> 8) ^ table[data[i] ^ (hashInt & 0xff)];
} }
/// <summary> /// <summary>
@@ -148,7 +148,7 @@ namespace DiscImageChef.Checksums
} }
for(int i = 0; i < fileStream.Length; i++) for(int i = 0; i < fileStream.Length; i++)
localhashInt = (localhashInt >> 8) ^ localTable[fileStream.ReadByte() ^ localhashInt & 0xff]; localhashInt = (localhashInt >> 8) ^ localTable[fileStream.ReadByte() ^ (localhashInt & 0xff)];
localhashInt ^= CRC32_SEED; localhashInt ^= CRC32_SEED;
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian; BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
@@ -200,7 +200,7 @@ namespace DiscImageChef.Checksums
localTable[i] = entry; localTable[i] = entry;
} }
for(int i = 0; i < len; i++) localhashInt = (localhashInt >> 8) ^ localTable[data[i] ^ localhashInt & 0xff]; for(int i = 0; i < len; i++) localhashInt = (localhashInt >> 8) ^ localTable[data[i] ^ (localhashInt & 0xff)];
localhashInt ^= CRC32_SEED; localhashInt ^= CRC32_SEED;
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian; BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;

View File

@@ -72,7 +72,7 @@ namespace DiscImageChef.Checksums
/// <param name="len">Length of buffer to hash.</param> /// <param name="len">Length of buffer to hash.</param>
public void Update(byte[] data, uint len) public void Update(byte[] data, uint len)
{ {
for(int i = 0; i < len; i++) hashInt = (hashInt >> 8) ^ table[data[i] ^ hashInt & 0xff]; for(int i = 0; i < len; i++) hashInt = (hashInt >> 8) ^ table[data[i] ^ (hashInt & 0xff)];
} }
/// <summary> /// <summary>
@@ -147,7 +147,7 @@ namespace DiscImageChef.Checksums
} }
for(int i = 0; i < fileStream.Length; i++) for(int i = 0; i < fileStream.Length; i++)
localhashInt = (localhashInt >> 8) ^ localTable[(ulong)fileStream.ReadByte() ^ localhashInt & 0xffL]; localhashInt = (localhashInt >> 8) ^ localTable[(ulong)fileStream.ReadByte() ^ (localhashInt & 0xffL)];
localhashInt ^= CRC64_SEED; localhashInt ^= CRC64_SEED;
BigEndianBitConverter.IsLittleEndian = BigEndianBitConverter.IsLittleEndian; BigEndianBitConverter.IsLittleEndian = BigEndianBitConverter.IsLittleEndian;
@@ -199,7 +199,7 @@ namespace DiscImageChef.Checksums
localTable[i] = entry; localTable[i] = entry;
} }
for(int i = 0; i < len; i++) localhashInt = (localhashInt >> 8) ^ localTable[data[i] ^ localhashInt & 0xff]; for(int i = 0; i < len; i++) localhashInt = (localhashInt >> 8) ^ localTable[data[i] ^ (localhashInt & 0xff)];
localhashInt ^= CRC64_SEED; localhashInt ^= CRC64_SEED;
BigEndianBitConverter.IsLittleEndian = BigEndianBitConverter.IsLittleEndian; BigEndianBitConverter.IsLittleEndian = BigEndianBitConverter.IsLittleEndian;

View File

@@ -608,7 +608,7 @@ namespace DiscImageChef.Core.Devices.Report
{ {
#pragma warning disable IDE0004 // Cast is necessary, otherwise incorrect value is created #pragma warning disable IDE0004 // Cast is necessary, otherwise incorrect value is created
physicalsectorsize = physicalsectorsize =
(uint)(logicalsectorsize * (1 << ataId.PhysLogSectorSize & 0xF)); (uint)(logicalsectorsize * ((1 << ataId.PhysLogSectorSize) & 0xF));
#pragma warning restore IDE0004 // Cast is necessary, otherwise incorrect value is created #pragma warning restore IDE0004 // Cast is necessary, otherwise incorrect value is created
} }
else physicalsectorsize = logicalsectorsize; else physicalsectorsize = logicalsectorsize;

View File

@@ -233,8 +233,8 @@ namespace DiscImageChef.Decoders.Floppy
byte b1 = buffer[51 * 3 - i]; byte b1 = buffer[51 * 3 - i];
byte b2 = buffer[51 * 2 - i]; byte b2 = buffer[51 * 2 - i];
byte b3 = buffer[51 - i]; byte b3 = buffer[51 - i];
byte b4 = (byte)(((b1 & 2) << 1 | (b2 & 2) | (b3 & 2) >> 1) & 0xFF); byte b4 = (byte)((((b1 & 2) << 1) | (b2 & 2) | ((b3 & 2) >> 1)) & 0xFF);
byte b5 = (byte)(((b1 & 1) << 2 | (b2 & 1) << 1 | (b3 & 1)) & 0xFF); byte b5 = (byte)((((b1 & 1) << 2) | ((b2 & 1) << 1) | (b3 & 1)) & 0xFF);
output[250 - 5 * i] = (byte)(((buffer[i + 51 * 3 + 1] << 3) | ((b1 >> 2) & 0x7)) & 0xFF); output[250 - 5 * i] = (byte)(((buffer[i + 51 * 3 + 1] << 3) | ((b1 >> 2) & 0x7)) & 0xFF);
output[251 - 5 * i] = (byte)(((buffer[i + 51 * 4 + 1] << 3) | ((b2 >> 2) & 0x7)) & 0xFF); output[251 - 5 * i] = (byte)(((buffer[i + 51 * 4 + 1] << 3) | ((b2 >> 2) & 0x7)) & 0xFF);
output[252 - 5 * i] = (byte)(((buffer[i + 51 * 5 + 1] << 3) | ((b3 >> 2) & 0x7)) & 0xFF); output[252 - 5 * i] = (byte)(((buffer[i + 51 * 5 + 1] << 3) | ((b3 >> 2) & 0x7)) & 0xFF);
@@ -270,18 +270,18 @@ namespace DiscImageChef.Decoders.Floppy
if(i < 86) if(i < 86)
{ {
output[i] |= (byte)((buffer[i] & 1) << 1 & 0xFF); output[i] |= (byte)(((buffer[i] & 1) << 1) & 0xFF);
output[i] |= (byte)((buffer[i] & 2) >> 1 & 0xFF); output[i] |= (byte)(((buffer[i] & 2) >> 1) & 0xFF);
} }
else if(i < 86 * 2) else if(i < 86 * 2)
{ {
output[i] |= (byte)((buffer[i - 86] & 4) >> 1 & 0xFF); output[i] |= (byte)(((buffer[i - 86] & 4) >> 1) & 0xFF);
output[i] |= (byte)((buffer[i - 86] & 8) >> 3 & 0xFF); output[i] |= (byte)(((buffer[i - 86] & 8) >> 3) & 0xFF);
} }
else else
{ {
output[i] |= (byte)((buffer[i - 86 * 2] & 0x10) >> 3 & 0xFF); output[i] |= (byte)(((buffer[i - 86 * 2] & 0x10) >> 3) & 0xFF);
output[i] |= (byte)((buffer[i - 86 * 2] & 0x20) >> 5 & 0xFF); output[i] |= (byte)(((buffer[i - 86 * 2] & 0x20) >> 5) & 0xFF);
} }
} }

View File

@@ -508,13 +508,13 @@ namespace DiscImageChef.DiscImages
DateTime start = DateTime.Now; DateTime start = DateTime.Now;
extents = new ExtentsULong(); extents = new ExtentsULong();
extentsOff = new Dictionary<ulong, ulong>(); extentsOff = new Dictionary<ulong, ulong>();
bool current = (bitmap[0] & 1 << (int)(0 % 8)) != 0; bool current = (bitmap[0] & (1 << (int)(0 % 8))) != 0;
ulong blockOff = 0; ulong blockOff = 0;
ulong extentStart = 0; ulong extentStart = 0;
for(ulong i = 1; i <= localHeader.qwBlocksCount; i++) for(ulong i = 1; i <= localHeader.qwBlocksCount; i++)
{ {
bool next = (bitmap[i / 8] & 1 << (int)(i % 8)) != 0; bool next = (bitmap[i / 8] & (1 << (int)(i % 8))) != 0;
// Flux // Flux
if(next != current) if(next != current)
@@ -572,7 +572,7 @@ namespace DiscImageChef.DiscImages
throw new ArgumentOutOfRangeException(nameof(sectorAddress), throw new ArgumentOutOfRangeException(nameof(sectorAddress),
string.Format("Sector address {0} not found", sectorAddress)); string.Format("Sector address {0} not found", sectorAddress));
if((bitmap[sectorAddress / 8] & 1 << (int)(sectorAddress % 8)) == 0) return new byte[ImageInfo.SectorSize]; if((bitmap[sectorAddress / 8] & (1 << (int)(sectorAddress % 8))) == 0) return new byte[ImageInfo.SectorSize];
byte[] sector; byte[] sector;
@@ -618,7 +618,7 @@ namespace DiscImageChef.DiscImages
bool allEmpty = true; bool allEmpty = true;
for(uint i = 0; i < length; i++) for(uint i = 0; i < length; i++)
{ {
if((bitmap[sectorAddress / 8] & 1 << (int)(sectorAddress % 8)) != 0) if((bitmap[sectorAddress / 8] & (1 << (int)(sectorAddress % 8))) != 0)
{ {
allEmpty = false; allEmpty = false;
break; break;

View File

@@ -105,9 +105,9 @@ namespace DiscImageChef
public static ulong Swap(ulong x) public static ulong Swap(ulong x)
{ {
x = (x & 0x00000000FFFFFFFF) << 32 | (x & 0xFFFFFFFF00000000) >> 32; x = ((x & 0x00000000FFFFFFFF) << 32) | ((x & 0xFFFFFFFF00000000) >> 32);
x = (x & 0x0000FFFF0000FFFF) << 16 | (x & 0xFFFF0000FFFF0000) >> 16; x = ((x & 0x0000FFFF0000FFFF) << 16) | ((x & 0xFFFF0000FFFF0000) >> 16);
x = (x & 0x00FF00FF00FF00FF) << 8 | (x & 0xFF00FF00FF00FF00) >> 8; x = ((x & 0x00FF00FF00FF00FF) << 8) | ((x & 0xFF00FF00FF00FF00) >> 8);
return x; return x;
} }

View File

@@ -72,7 +72,7 @@ namespace DiscImageChef.Tests.Devices
sb.AppendFormat("Status: {0}", DecodeATAStatus(registers.status)).AppendLine(); sb.AppendFormat("Status: {0}", DecodeATAStatus(registers.status)).AppendLine();
sb.AppendFormat("Error: {0}", DecodeATAStatus(registers.error)).AppendLine(); sb.AppendFormat("Error: {0}", DecodeATAStatus(registers.error)).AppendLine();
sb.AppendFormat("Device: {0}", (registers.deviceHead >> 4) & 0x01).AppendLine(); sb.AppendFormat("Device: {0}", (registers.deviceHead >> 4) & 0x01).AppendLine();
sb.AppendFormat("Cylinder: {0}", registers.cylinderHigh << 8 + registers.cylinderLow).AppendLine(); sb.AppendFormat("Cylinder: {0}", registers.cylinderHigh << (8 + registers.cylinderLow)).AppendLine();
sb.AppendFormat("Head: {0}", registers.deviceHead & 0xF).AppendLine(); sb.AppendFormat("Head: {0}", registers.deviceHead & 0xF).AppendLine();
sb.AppendFormat("Sector: {0}", registers.sector).AppendLine(); sb.AppendFormat("Sector: {0}", registers.sector).AppendLine();
sb.AppendFormat("Count: {0}", registers.sectorCount).AppendLine(); sb.AppendFormat("Count: {0}", registers.sectorCount).AppendLine();