lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From synhers...@apache.org
Subject [01/12] lucenenet git commit: Added maxSize >= 0 check.
Date Tue, 17 Feb 2015 17:29:43 GMT
Repository: lucenenet
Updated Branches:
  refs/heads/master b84ad8cc0 -> f1a2b5046


Added maxSize >= 0 check.


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

Branch: refs/heads/master
Commit: 9c38decabb5dbf4180045b4e4d1477ad5f801341
Parents: a947b92
Author: Guido Tagliavini Ponce <t-gupon@microsoft.com>
Authored: Wed Feb 11 14:37:41 2015 -0800
Committer: Guido Tagliavini Ponce <t-gupon@microsoft.com>
Committed: Wed Feb 11 14:37:41 2015 -0800

----------------------------------------------------------------------
 src/Lucene.Net.Core/Util/PriorityQueue.cs | 42 +++++++++++++++-----------
 1 file changed, 25 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/9c38deca/src/Lucene.Net.Core/Util/PriorityQueue.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Util/PriorityQueue.cs b/src/Lucene.Net.Core/Util/PriorityQueue.cs
index bd06be0..f601de8 100644
--- a/src/Lucene.Net.Core/Util/PriorityQueue.cs
+++ b/src/Lucene.Net.Core/Util/PriorityQueue.cs
@@ -45,33 +45,41 @@ namespace Lucene.Net.Util
         public PriorityQueue(int maxSize, bool prepopulate)
         {
             int heapSize;
-            if (0 == maxSize)
+            if (maxSize < 0)
             {
-                // We allocate 1 extra to avoid if statement in top()
-                heapSize = 2;
+                throw new System.ArgumentException("maxSize must be >= 0; got: " + maxSize);
             }
             else
             {
-                if (maxSize > ArrayUtil.MAX_ARRAY_LENGTH)
+                if (0 == maxSize)
                 {
-                    // Don't wrap heapSize to -1, in this case, which
-                    // causes a confusing NegativeArraySizeException.
-                    // Note that very likely this will simply then hit
-                    // an OOME, but at least that's more indicative to
-                    // caller that this values is too big.  We don't +1
-                    // in this case, but it's very unlikely in practice
-                    // one will actually insert this many objects into
-                    // the PQ:
-                    // Throw exception to prevent confusing OOME:
-                    throw new System.ArgumentException("maxSize must be <= " + ArrayUtil.MAX_ARRAY_LENGTH
+ "; got: " + maxSize);
+                    // We allocate 1 extra to avoid if statement in top()
+                    heapSize = 2;
                 }
                 else
                 {
-                    // NOTE: we add +1 because all access to heap is
-                    // 1-based not 0-based.  heap[0] is unused.
-                    heapSize = maxSize + 1;
+                    if (maxSize >= ArrayUtil.MAX_ARRAY_LENGTH)
+                    {
+                        // Don't wrap heapSize to -1, in this case, which
+                        // causes a confusing NegativeArraySizeException.
+                        // Note that very likely this will simply then hit
+                        // an OOME, but at least that's more indicative to
+                        // caller that this values is too big.  We don't +1
+                        // in this case, but it's very unlikely in practice
+                        // one will actually insert this many objects into
+                        // the PQ:
+                        // Throw exception to prevent confusing OOME:
+                        throw new System.ArgumentException("maxSize must be < " + ArrayUtil.MAX_ARRAY_LENGTH
+ "; got: " + maxSize);
+                    }
+                    else
+                    {
+                        // NOTE: we add +1 because all access to heap is
+                        // 1-based not 0-based.  heap[0] is unused.
+                        heapSize = maxSize + 1;
+                    }
                 }
             }
+            
             // T is unbounded type, so this unchecked cast works always:
             T[] h = new T[heapSize];
             this.Heap = h;


Mime
View raw message