[ 
https://issues.apache.org/jira/browse/LUCENE-6409?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14485316#comment-14485316
 ] 

Luc Vanlerberghe commented on LUCENE-6409:
------------------------------------------

While looking over the code, I have some more remarks on Fixed-/LongBitSet that 
should be investigated:
* Harmonize the use of numWords vs. bits.length vs. numBits
** E.g.: cardinality scans up to bits.length, while "or" asserts on 
index<numWords
* Performance: If a BitSet is allocated with n bits, ensureCapacity with the 
same number n shouldn't grow the BitSet
** Either both the constructor and ensureCapacity should allocate a larger 
array than really needed or neither. ensureCapacity contains:
{code}
    if (numBits < bits.length()) {
      return bits;
    } else {
      int numWords = bits2words(numBits);
      long[] arr = bits.getBits();
      if (numWords >= arr.length) {
        arr = ArrayUtil.grow(arr, numWords + 1);
      }
      return new FixedBitSet(arr, arr.length << 6);
    }
{code}
The first "if" will fail and the second "if" will succeed, causing arr to be 
grown to at least 1 more...


>  LongBitSet.ensureCapacity overflows on numBits > Integer.MaxValue 
> -------------------------------------------------------------------
>
>                 Key: LUCENE-6409
>                 URL: https://issues.apache.org/jira/browse/LUCENE-6409
>             Project: Lucene - Core
>          Issue Type: Bug
>          Components: core/other
>            Reporter: Luc Vanlerberghe
>
> LongBitSet.ensureCapacity calculates the number of longs required to store 
> the number of bits correctly and allocates a long[] accordingly, but then 
> shifts the array length (which is an int!) left by 6 bits.  The int should be 
> cast to long *before* performing the shift.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to