
findbugs - issue #30
32 bit int shifted by 56 bits in read8(RandomAccessFile) in IconExe.java
Bug report generated from FindBugs 32 bit int shifted by 56 bits in read8(RandomAccessFile)
In class org.eclipse.equinox.internal.p2.swt.tools.IconExe In method read8(RandomAccessFile) Shifted by 56 bits Local variable named b7 At IconExe.java:[line 703]
Relevant source code: 699: int b4 = raf.readByte() & 0xFF; 700: int b5 = raf.readByte() & 0xFF; 701: int b6 = raf.readByte() & 0xFF; 702: int b7 = raf.readByte() & 0xFF; 703: return b7 << 56 | b6 << 48 | b5 << 40 | b4 << 32 | b3 << 24 | b2 << 16 | b1 << 8 | b0; 704: } 705: static void write4(RandomAccessFile raf, int value) throws IOException { 706: raf.write(value & 0xFF); 707: raf.write((value >> 8) & 0xFF);
Bug pattern explanation: The code performs shift of a 32 bit int by a constant amount outside the range 0..31. The effect of this is to use the lower 5 bits of the integer value to decide how much to shift by (e.g., shifting by 40 bits is the same as shifting by 8 bits, and shifting by 32 bits is the same as shifting by zero bits). This probably isn't want was expected, and it at least confusing.
FindBugs issue identifier (do not modify or remove): cd7ea7a84ba76dc27b4db4189e1443d6
Comment #1
Posted on Feb 17, 2010 by Happy Giraffe(No comment was entered for this change.)
Status: Invalid
Labels:
FindBugsGenerated