Skip to content

Commit d0efecf

Browse files
committed
The byte array element when shifted is only in an 'int' scope I believe,
so when it's shifted by more than 24, it goes off the end. My solution is to break in two parts and then shift them on top once they're in a long scope. git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/io/trunk@140433 13f79535-47bb-0310-9956-ffa450edef68
1 parent b62e9c2 commit d0efecf

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

src/java/org/apache/commons/io/EndianUtils.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
* Origin of code: Apache Avalon (Excalibur)
6565
*
6666
* @author <a href="mailto:peter@apache.org">Peter Donald</a>
67-
* @version CVS $Revision: 1.5 $ $Date: 2003/11/27 02:58:10 $
67+
* @version CVS $Revision: 1.6 $ $Date: 2003/11/27 04:07:09 $
6868
*/
6969
public final class EndianUtils
7070
{
@@ -250,14 +250,17 @@ public static void writeSwappedLong( final byte[] data, final int offset, final
250250
*/
251251
public static long readSwappedLong( final byte[] data, final int offset )
252252
{
253-
return (long)( ( ( data[ offset + 0 ] & 0xff ) << 0 ) +
253+
long ln = (long)( ( ( data[ offset + 0 ] & 0xff ) << 0 ) );
254+
long low = (long)( ( ( data[ offset + 0 ] & 0xff ) << 0 ) +
254255
( ( data[ offset + 1 ] & 0xff ) << 8 ) +
255256
( ( data[ offset + 2 ] & 0xff ) << 16 ) +
256-
( ( data[ offset + 3 ] & 0xff ) << 24 ) +
257-
( ( data[ offset + 4 ] & 0xff ) << 32 ) +
258-
( ( data[ offset + 5 ] & 0xff ) << 40 ) +
259-
( ( data[ offset + 6 ] & 0xff ) << 48 ) +
260-
( ( data[ offset + 7 ] & 0xff ) << 56 ) );
257+
( ( data[ offset + 3 ] & 0xff ) << 24 ) );
258+
long high = (long)(
259+
( ( data[ offset + 4 ] & 0xff ) << 0 ) +
260+
( ( data[ offset + 5 ] & 0xff ) << 8 ) +
261+
( ( data[ offset + 6 ] & 0xff ) << 16 ) +
262+
( ( data[ offset + 7 ] & 0xff ) << 24 ) );
263+
return low + (high << 32);
261264
}
262265

263266
/**

0 commit comments

Comments
 (0)