git commit: Fix potential index out of bound error in RangeTombstoneList (+test)

2013-07-15 Thread slebresne
Updated Branches:
  refs/heads/cassandra-1.2 fa327aa69 - f5b224cf9


Fix potential index out of bound error in RangeTombstoneList (+test)


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/f5b224cf
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/f5b224cf
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/f5b224cf

Branch: refs/heads/cassandra-1.2
Commit: f5b224cf9aa0f319d51078ef4b78d55e36613963
Parents: fa327aa
Author: Sylvain Lebresne sylv...@datastax.com
Authored: Mon Jul 15 10:33:34 2013 +0200
Committer: Sylvain Lebresne sylv...@datastax.com
Committed: Mon Jul 15 10:33:34 2013 +0200

--
 .../apache/cassandra/db/RangeTombstoneList.java | 13 +++
 .../cassandra/db/RangeTombstoneListTest.java| 37 
 2 files changed, 44 insertions(+), 6 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/cassandra/blob/f5b224cf/src/java/org/apache/cassandra/db/RangeTombstoneList.java
--
diff --git a/src/java/org/apache/cassandra/db/RangeTombstoneList.java 
b/src/java/org/apache/cassandra/db/RangeTombstoneList.java
index 0a761cd..e7ec119 100644
--- a/src/java/org/apache/cassandra/db/RangeTombstoneList.java
+++ b/src/java/org/apache/cassandra/db/RangeTombstoneList.java
@@ -201,8 +201,9 @@ public class RangeTombstoneList implements 
IterableRangeTombstone
 i++;
 }
 }
+// Addds the remaining ones from tombstones if any (not that 
insertFrom will increment size if relevant).
 for (; j  tombstones.size; j++)
-insertFrom((i++) - 1, tombstones.starts[j], 
tombstones.ends[j], tombstones.markedAts[j], tombstones.delTimes[j]);
+insertFrom(size - 1, tombstones.starts[j], tombstones.ends[j], 
tombstones.markedAts[j], tombstones.delTimes[j]);
 }
 }
 
@@ -374,7 +375,7 @@ public class RangeTombstoneList implements 
IterableRangeTombstone
 /*
  * Inserts a new element whose start should be inserted at index i. This 
method
  * assumes that:
- *   - starts[i] = start.
+ *   - starts[i] = start
  *   - start  starts[i+1] or there is no i+1 element.
  */
 private void insertFrom(int i, ByteBuffer start, ByteBuffer end, long 
markedAt, int delTime)
@@ -388,12 +389,12 @@ public class RangeTombstoneList implements 
IterableRangeTombstone
 /*
  * We have elt(i) = [s_i, e_i]@t_i and want to insert X = [s, e]@t, 
knowing that s_i  s  s_i+1.
  * We can have 3 cases:
- *  - s = e_i  e = e_i: we're fully contained in i.
- *  - s = e_i  e  e_i: we rewrite X to X1=[s, e_i]@t + X2=[e_i, 
e]@t. X1 is fully contained
+ *  - s  e_i  e = e_i: we're fully contained in i.
+ *  - s  e_i  e  e_i: we rewrite X to X1=[s, e_i]@t + X2=[e_i, 
e]@t. X1 is fully contained
  * in i and X2 is the insertAfter() case for i.
- *  - s  e_i: we're in the insertAfter() case for i.
+ *  - s = e_i: we're in the insertAfter() case for i.
  */
-if (comparator.compare(start, ends[i]) = 0)
+if (comparator.compare(start, ends[i])  0)
 {
 if (comparator.compare(end, ends[i]) = 0)
 {

http://git-wip-us.apache.org/repos/asf/cassandra/blob/f5b224cf/test/unit/org/apache/cassandra/db/RangeTombstoneListTest.java
--
diff --git a/test/unit/org/apache/cassandra/db/RangeTombstoneListTest.java 
b/test/unit/org/apache/cassandra/db/RangeTombstoneListTest.java
index 39f9e6c..67e3623 100644
--- a/test/unit/org/apache/cassandra/db/RangeTombstoneListTest.java
+++ b/test/unit/org/apache/cassandra/db/RangeTombstoneListTest.java
@@ -205,6 +205,43 @@ public class RangeTombstoneListTest
 }
 
 @Test
+public void addAllSequentialTest()
+{
+RangeTombstoneList l1 = new RangeTombstoneList(cmp, 0);
+l1.add(rt(3, 5, 2));
+
+RangeTombstoneList l2 = new RangeTombstoneList(cmp, 0);
+l2.add(rt(5, 7, 7));
+
+l1.addAll(l2);
+
+IteratorRangeTombstone iter = l1.iterator();
+assertRT(rt(3, 5, 2), iter.next());
+assertRT(rt(5, 7, 7), iter.next());
+
+assert !iter.hasNext();
+}
+
+@Test
+public void addAllIncludedTest()
+{
+RangeTombstoneList l1 = new RangeTombstoneList(cmp, 0);
+l1.add(rt(3, 10, 5));
+
+RangeTombstoneList l2 = new RangeTombstoneList(cmp, 0);
+l2.add(rt(4, 5, 2));
+l2.add(rt(5, 7, 3));
+l2.add(rt(7, 9, 4));
+
+l1.addAll(l2);
+
+IteratorRangeTombstone iter = l1.iterator();
+assertRT(rt(3, 10, 5), iter.next());
+
+assert !iter.hasNext();
+}

[1/2] git commit: Fix potential index out of bound error in RangeTombstoneList (+test)

2013-07-15 Thread slebresne
Updated Branches:
  refs/heads/trunk 20c0baf08 - 4df6c2875


Fix potential index out of bound error in RangeTombstoneList (+test)


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/f5b224cf
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/f5b224cf
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/f5b224cf

Branch: refs/heads/trunk
Commit: f5b224cf9aa0f319d51078ef4b78d55e36613963
Parents: fa327aa
Author: Sylvain Lebresne sylv...@datastax.com
Authored: Mon Jul 15 10:33:34 2013 +0200
Committer: Sylvain Lebresne sylv...@datastax.com
Committed: Mon Jul 15 10:33:34 2013 +0200

--
 .../apache/cassandra/db/RangeTombstoneList.java | 13 +++
 .../cassandra/db/RangeTombstoneListTest.java| 37 
 2 files changed, 44 insertions(+), 6 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/cassandra/blob/f5b224cf/src/java/org/apache/cassandra/db/RangeTombstoneList.java
--
diff --git a/src/java/org/apache/cassandra/db/RangeTombstoneList.java 
b/src/java/org/apache/cassandra/db/RangeTombstoneList.java
index 0a761cd..e7ec119 100644
--- a/src/java/org/apache/cassandra/db/RangeTombstoneList.java
+++ b/src/java/org/apache/cassandra/db/RangeTombstoneList.java
@@ -201,8 +201,9 @@ public class RangeTombstoneList implements 
IterableRangeTombstone
 i++;
 }
 }
+// Addds the remaining ones from tombstones if any (not that 
insertFrom will increment size if relevant).
 for (; j  tombstones.size; j++)
-insertFrom((i++) - 1, tombstones.starts[j], 
tombstones.ends[j], tombstones.markedAts[j], tombstones.delTimes[j]);
+insertFrom(size - 1, tombstones.starts[j], tombstones.ends[j], 
tombstones.markedAts[j], tombstones.delTimes[j]);
 }
 }
 
@@ -374,7 +375,7 @@ public class RangeTombstoneList implements 
IterableRangeTombstone
 /*
  * Inserts a new element whose start should be inserted at index i. This 
method
  * assumes that:
- *   - starts[i] = start.
+ *   - starts[i] = start
  *   - start  starts[i+1] or there is no i+1 element.
  */
 private void insertFrom(int i, ByteBuffer start, ByteBuffer end, long 
markedAt, int delTime)
@@ -388,12 +389,12 @@ public class RangeTombstoneList implements 
IterableRangeTombstone
 /*
  * We have elt(i) = [s_i, e_i]@t_i and want to insert X = [s, e]@t, 
knowing that s_i  s  s_i+1.
  * We can have 3 cases:
- *  - s = e_i  e = e_i: we're fully contained in i.
- *  - s = e_i  e  e_i: we rewrite X to X1=[s, e_i]@t + X2=[e_i, 
e]@t. X1 is fully contained
+ *  - s  e_i  e = e_i: we're fully contained in i.
+ *  - s  e_i  e  e_i: we rewrite X to X1=[s, e_i]@t + X2=[e_i, 
e]@t. X1 is fully contained
  * in i and X2 is the insertAfter() case for i.
- *  - s  e_i: we're in the insertAfter() case for i.
+ *  - s = e_i: we're in the insertAfter() case for i.
  */
-if (comparator.compare(start, ends[i]) = 0)
+if (comparator.compare(start, ends[i])  0)
 {
 if (comparator.compare(end, ends[i]) = 0)
 {

http://git-wip-us.apache.org/repos/asf/cassandra/blob/f5b224cf/test/unit/org/apache/cassandra/db/RangeTombstoneListTest.java
--
diff --git a/test/unit/org/apache/cassandra/db/RangeTombstoneListTest.java 
b/test/unit/org/apache/cassandra/db/RangeTombstoneListTest.java
index 39f9e6c..67e3623 100644
--- a/test/unit/org/apache/cassandra/db/RangeTombstoneListTest.java
+++ b/test/unit/org/apache/cassandra/db/RangeTombstoneListTest.java
@@ -205,6 +205,43 @@ public class RangeTombstoneListTest
 }
 
 @Test
+public void addAllSequentialTest()
+{
+RangeTombstoneList l1 = new RangeTombstoneList(cmp, 0);
+l1.add(rt(3, 5, 2));
+
+RangeTombstoneList l2 = new RangeTombstoneList(cmp, 0);
+l2.add(rt(5, 7, 7));
+
+l1.addAll(l2);
+
+IteratorRangeTombstone iter = l1.iterator();
+assertRT(rt(3, 5, 2), iter.next());
+assertRT(rt(5, 7, 7), iter.next());
+
+assert !iter.hasNext();
+}
+
+@Test
+public void addAllIncludedTest()
+{
+RangeTombstoneList l1 = new RangeTombstoneList(cmp, 0);
+l1.add(rt(3, 10, 5));
+
+RangeTombstoneList l2 = new RangeTombstoneList(cmp, 0);
+l2.add(rt(4, 5, 2));
+l2.add(rt(5, 7, 3));
+l2.add(rt(7, 9, 4));
+
+l1.addAll(l2);
+
+IteratorRangeTombstone iter = l1.iterator();
+assertRT(rt(3, 10, 5), iter.next());
+
+assert !iter.hasNext();
+}
+
+@Test