Change from int to long for values that represent sizes in bit
authorSimon Marchi <simon.marchi@polymtl.ca>
Thu, 10 Oct 2013 18:00:58 +0000 (14:00 -0400)
committerMatthew Khouzam <matthew.khouzam@ericsson.com>
Thu, 17 Oct 2013 18:29:34 +0000 (14:29 -0400)
This fixes parsing of traces with big packets, whose size in bits
overflow an 32-bit int.

Change-Id: I5d2d1ede73e638bdd2a3e5b38a5ee2a053fa5d3a
Signed-off-by: Simon Marchi <simon.marchi@polymtl.ca>
Reviewed-on: https://git.eclipse.org/r/17422
Reviewed-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Tested-by: Hudson CI
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
IP-Clean: Matthew Khouzam <matthew.khouzam@ericsson.com>
Tested-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/io/BitBufferTest.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/io/BitBuffer.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/EnumDefinition.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IntegerDefinition.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StructDefinition.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInput.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/trace/StreamInputPacketIndexEntry.java

index b13dfd1136da80d343f1d3263a8dc869234ea907..90f1fdb78015485ea22b0f01bc4502a8b2cfd00e 100644 (file)
@@ -143,7 +143,7 @@ public class BitBufferTest {
      */
     @Test
     public void testGetPosition() {
-        int result = fixture.position();
+        long result = fixture.position();
 
         assertEquals(1, result);
     }
index 07df16411751b3d91ba44491980adf14b2fe7e3f..1b75d93f4516e5c07b43a3d55c58b3f0471e0ca5 100644 (file)
@@ -46,7 +46,7 @@ public final class BitBuffer {
     // ------------------------------------------------------------------------
 
     private ByteBuffer buf;
-    private int pos;
+    private long pos;
     private ByteOrder byteOrder;
 
     // ------------------------------------------------------------------------
@@ -128,9 +128,9 @@ public final class BitBuffer {
             case BitBuffer.BIT_CHAR:
                 // Byte
                 if (signed) {
-                    val = this.buf.get(this.pos / 8);
+                    val = this.buf.get((int) (this.pos / 8));
                 } else {
-                    val = (this.buf.get(this.pos / 8)) & 0xff;
+                    val = (this.buf.get((int) (this.pos / 8))) & 0xff;
                 }
                 gotIt = true;
                 break;
@@ -138,9 +138,9 @@ public final class BitBuffer {
             case BitBuffer.BIT_SHORT:
                 // Word
                 if (signed) {
-                    val = this.buf.getShort(this.pos / 8);
+                    val = this.buf.getShort((int) (this.pos / 8));
                 } else {
-                    short a = this.buf.getShort(this.pos / 8);
+                    short a = this.buf.getShort((int) (this.pos / 8));
                     val = a & 0xffff;
                 }
                 gotIt = true;
@@ -148,7 +148,7 @@ public final class BitBuffer {
 
             case BitBuffer.BIT_INT:
                 // Double word
-                val = this.buf.getInt(this.pos / 8);
+                val = this.buf.getInt((int) (this.pos / 8));
                 gotIt = true;
                 break;
 
@@ -169,11 +169,11 @@ public final class BitBuffer {
         return val;
     }
 
-    private int getIntBE(int index, int length, boolean signed) {
+    private int getIntBE(long index, int length, boolean signed) {
         assert ((length > 0) && (length <= BIT_INT));
-        int end = index + length;
-        int startByte = index / BIT_CHAR;
-        int endByte = (end + (BIT_CHAR - 1)) / BIT_CHAR;
+        long end = index + length;
+        int startByte = (int) (index / BIT_CHAR);
+        int endByte = (int) ((end + (BIT_CHAR - 1)) / BIT_CHAR);
         int currByte, lshift, cshift, mask, cmask, cache;
         int value = 0;
 
@@ -193,7 +193,7 @@ public final class BitBuffer {
             value |= cmask;
             return value;
         }
-        cshift = index % BIT_CHAR;
+        cshift = (int) (index % BIT_CHAR);
         if (cshift > 0) {
             mask = ~((~0) << (BIT_CHAR - cshift));
             cmask = cache & mask;
@@ -206,7 +206,7 @@ public final class BitBuffer {
             value <<= BIT_CHAR;
             value |= this.buf.get(currByte) & 0xFF;
         }
-        lshift = end % BIT_CHAR;
+        lshift = (int) (end % BIT_CHAR);
         if (lshift > 0) {
             mask = ~((~0) << lshift);
             cmask = this.buf.get(currByte) & 0xFF;
@@ -221,17 +221,17 @@ public final class BitBuffer {
         return value;
     }
 
-    private int getIntLE(int index, int length, boolean signed) {
+    private int getIntLE(long index, int length, boolean signed) {
         assert ((length > 0) && (length <= BIT_INT));
-        int end = index + length;
-        int startByte = index / BIT_CHAR;
-        int endByte = (end + (BIT_CHAR - 1)) / BIT_CHAR;
+        long end = index + length;
+        int startByte = (int) (index / BIT_CHAR);
+        int endByte = (int) ((end + (BIT_CHAR - 1)) / BIT_CHAR);
         int currByte, lshift, cshift, mask, cmask, cache, mod;
         int value = 0;
 
         currByte = endByte - 1;
         cache = buf.get(currByte) & 0xFF;
-        mod = end % BIT_CHAR;
+        mod = (int) (end % BIT_CHAR);
         lshift = (mod > 0) ? mod : BIT_CHAR;
         boolean isNeg = (cache & (1 << (lshift - 1))) != 0;
         if (signed && isNeg) {
@@ -247,7 +247,7 @@ public final class BitBuffer {
             value |= cmask;
             return value;
         }
-        cshift = end % BIT_CHAR;
+        cshift = (int) (end % BIT_CHAR);
         if (cshift > 0) {
             mask = ~((~0) << cshift);
             cmask = cache & mask;
@@ -259,7 +259,7 @@ public final class BitBuffer {
             value <<= BIT_CHAR;
             value |= buf.get(currByte) & 0xFF;
         }
-        lshift = index % BIT_CHAR;
+        lshift = (int) (index % BIT_CHAR);
         if (lshift > 0) {
             mask = ~((~0) << (BIT_CHAR - lshift));
             cmask = buf.get(currByte) & 0xFF;
@@ -307,7 +307,7 @@ public final class BitBuffer {
      *            The value to write
      */
     public void putInt(int length, int value) {
-        final int curPos = this.pos;
+        final long curPos = this.pos;
 
         if (!canRead(length)) {
             throw new BufferOverflowException();
@@ -323,11 +323,11 @@ public final class BitBuffer {
         this.pos += length;
     }
 
-    private void putIntBE(int index, int length, int value) {
+    private void putIntBE(long index, int length, int value) {
         assert ((length > 0) && (length <= BIT_INT));
-        int end = index + length;
-        int startByte = index / BIT_CHAR;
-        int endByte = (end + (BIT_CHAR - 1)) / BIT_CHAR;
+        long end = index + length;
+        int startByte = (int) (index / BIT_CHAR);
+        int endByte = (int) ((end + (BIT_CHAR - 1)) / BIT_CHAR);
         int currByte, lshift, cshift, mask, cmask;
         int correctedValue = value;
 
@@ -342,7 +342,7 @@ public final class BitBuffer {
 
         /* sub byte */
         if (startByte == (endByte - 1)) {
-            lshift = (BIT_CHAR - (end % BIT_CHAR)) % BIT_CHAR;
+            lshift = (int) ((BIT_CHAR - (end % BIT_CHAR)) % BIT_CHAR);
             mask = ~((~0) << lshift);
             if ((index % BIT_CHAR) > 0) {
                 mask |= (~(0)) << (BIT_CHAR - (index % BIT_CHAR));
@@ -360,7 +360,7 @@ public final class BitBuffer {
 
         /* head byte contains MSB */
         currByte = endByte - 1;
-        cshift = end % BIT_CHAR;
+        cshift = (int) (end % BIT_CHAR);
         if (cshift > 0) {
             lshift = BIT_CHAR - cshift;
             mask = ~((~0) << lshift);
@@ -388,11 +388,11 @@ public final class BitBuffer {
         }
     }
 
-    private void putIntLE(int index, int length, int value) {
+    private void putIntLE(long index, int length, int value) {
         assert ((length > 0) && (length <= BIT_INT));
-        int end = index + length;
-        int startByte = index / BIT_CHAR;
-        int endByte = (end + (BIT_CHAR - 1)) / BIT_CHAR;
+        long end = index + length;
+        int startByte = (int) (index / BIT_CHAR);
+        int endByte = (int) ((end + (BIT_CHAR - 1)) / BIT_CHAR);
         int currByte, lshift, cshift, mask, cmask;
         int correctedValue = value;
 
@@ -407,7 +407,7 @@ public final class BitBuffer {
 
         /* sub byte */
         if (startByte == (endByte - 1)) {
-            lshift = index % BIT_CHAR;
+            lshift = (int) (index % BIT_CHAR);
             mask = ~((~0) << lshift);
             if ((end % BIT_CHAR) > 0) {
                 mask |= (~(0)) << (end % BIT_CHAR);
@@ -425,7 +425,7 @@ public final class BitBuffer {
 
         /* head byte */
         currByte = startByte;
-        cshift = index % BIT_CHAR;
+        cshift = (int) (index % BIT_CHAR);
         if (cshift > 0) {
             mask = ~((~0) << cshift);
             cmask = correctedValue << cshift;
@@ -468,7 +468,7 @@ public final class BitBuffer {
             return false;
         }
 
-        if ((this.pos + length) > (this.buf.capacity() * BIT_CHAR)) {
+        if ((this.pos + length) > (((long) this.buf.capacity()) * BIT_CHAR)) {
             return false;
         }
         return true;
@@ -502,7 +502,7 @@ public final class BitBuffer {
      * @param newPosition
      *            The new position of the buffer.
      */
-    public void position(int newPosition) {
+    public void position(long newPosition) {
         this.pos = newPosition;
     }
 
@@ -512,7 +512,7 @@ public final class BitBuffer {
      *
      * @return order The position of the buffer.
      */
-    public int position() {
+    public long position() {
         return this.pos;
     }
 
index 9e6e237a47e2ea94b3ddc28b0f452e23af0c9d10..d057d5a158346da1ecab8a8b34f43c0c9e37da96 100644 (file)
@@ -104,7 +104,7 @@ public class EnumDefinition extends SimpleDatatypeDefinition {
     @Override
     public void read(BitBuffer input) {
         int align = (int) declaration.getAlignment();
-        int pos = input.position() + ((align-(input.position() % align))%align);
+        long pos = input.position() + ((align - (input.position() % align)) % align);
         input.position(pos);
         integerValue.read(input);
         long val = integerValue.getValue();
index f9680ee107687d3f1e82be00073673a379b91f93..7e8701f79561701e5f434aa8e58fb4acf749f939 100644 (file)
@@ -102,7 +102,7 @@ public class IntegerDefinition extends SimpleDatatypeDefinition {
     public void read(BitBuffer input) {
         final long longNegBit = 0x0000000080000000L;
         int align = (int) declaration.getAlignment();
-        int pos = input.position() + ((align - (input.position() % align)) % align);
+        long pos = input.position() + ((align - (input.position() % align)) % align);
         input.position(pos);
         boolean signed = declaration.isSigned();
         int length = declaration.getLength();
index 97b711c6369dcce2c13770e3326cf28fac29007c..4f39e0708b76350871813c9648080918f5a52844 100644 (file)
@@ -92,7 +92,7 @@ public class StructDefinition extends Definition implements IDefinitionScope {
     @Override
     public void read(BitBuffer input) {
         final int align = (int) declaration.getAlignment();
-        int pos = input.position()
+        long pos = input.position()
                 + ((align - (input.position() % align)) % align);
         input.position(pos);
         final List<String> fieldList = declaration.getFieldsList();
index 6b640cb1c91c3dc9df8e8582d5436a761c5c7aa3..d8ad3d6c0a77355aeb26544a1094cebc5ecaeba7 100644 (file)
@@ -396,8 +396,8 @@ public class StreamInput implements IDefinitionScope {
          * If there is no packet context, infer the content and packet size from
          * the file size (assume that there is only one packet and no padding)
          */
-        packetIndex.setContentSizeBits((int) (fileSizeBytes * 8));
-        packetIndex.setPacketSizeBits((int) (fileSizeBytes * 8));
+        packetIndex.setContentSizeBits(fileSizeBytes * 8);
+        packetIndex.setPacketSizeBits(fileSizeBytes * 8);
     }
 
     private void parsePacketContext(long fileSizeBytes,
index 0cb19ab50f60712af2764cb956b0876c3aefab8f..a237357b3e4059b1f67e29dfab35eb81095ab1f7 100644 (file)
@@ -34,17 +34,17 @@ public class StreamInputPacketIndexEntry {
     /**
      * Offset of the data in the packet, in bits
      */
-    private int dataOffsetBits = 0;
+    private long dataOffsetBits = 0;
 
     /**
      * Packet size, in bits
      */
-    private int packetSizeBits = 0;
+    private long packetSizeBits = 0;
 
     /**
      * Content size, in bits
      */
-    private int contentSizeBits = 0;
+    private long contentSizeBits = 0;
 
     /**
      * Begin timestamp
@@ -125,7 +125,7 @@ public class StreamInputPacketIndexEntry {
     /**
      * @return the dataOffsetBits
      */
-    public int getDataOffsetBits() {
+    public long getDataOffsetBits() {
         return dataOffsetBits;
     }
 
@@ -133,14 +133,14 @@ public class StreamInputPacketIndexEntry {
      * @param dataOffsetBits
      *            the dataOffsetBits to set
      */
-    public void setDataOffsetBits(int dataOffsetBits) {
+    public void setDataOffsetBits(long dataOffsetBits) {
         this.dataOffsetBits = dataOffsetBits;
     }
 
     /**
      * @return the packetSizeBits
      */
-    public int getPacketSizeBits() {
+    public long getPacketSizeBits() {
         return packetSizeBits;
     }
 
@@ -148,14 +148,14 @@ public class StreamInputPacketIndexEntry {
      * @param packetSizeBits
      *            the packetSizeBits to set
      */
-    public void setPacketSizeBits(int packetSizeBits) {
+    public void setPacketSizeBits(long packetSizeBits) {
         this.packetSizeBits = packetSizeBits;
     }
 
     /**
      * @return the contentSizeBits
      */
-    public int getContentSizeBits() {
+    public long getContentSizeBits() {
         return contentSizeBits;
     }
 
@@ -163,7 +163,7 @@ public class StreamInputPacketIndexEntry {
      * @param contentSizeBits
      *            the contentSizeBits to set
      */
-    public void setContentSizeBits(int contentSizeBits) {
+    public void setContentSizeBits(long contentSizeBits) {
         this.contentSizeBits = contentSizeBits;
     }
 
This page took 0.035678 seconds and 5 git commands to generate.