zongaro     2002/09/17 14:08:37

  Modified:    java/src/org/apache/xalan/xsltc/dom Tag: XSLTC_DTM
                        BitArray.java
  Log:
  Added assertions to check for out of range bit indices in getBit and setBit.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.3.10.3  +40 -27    
xml-xalan/java/src/org/apache/xalan/xsltc/dom/BitArray.java
  
  Index: BitArray.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/dom/BitArray.java,v
  retrieving revision 1.3.10.2
  retrieving revision 1.3.10.3
  diff -u -r1.3.10.2 -r1.3.10.3
  --- BitArray.java     29 Jul 2002 00:01:27 -0000      1.3.10.2
  +++ BitArray.java     17 Sep 2002 21:08:37 -0000      1.3.10.3
  @@ -91,6 +91,8 @@
        0x00000080, 0x00000040, 0x00000020, 0x00000010,
        0x00000008, 0x00000004, 0x00000002, 0x00000001 };
   
  +    private final static boolean DEBUG_ASSERTIONS = false;
  +    
       /**
        * Constructor. Defines the initial size of the bit array (in bits).
        */
  @@ -98,11 +100,11 @@
        this(32);
       }
   
  -    public BitArray(int size) {
  -     if (size < 32) size = 32;
  -     _bitSize = size;
  -     _intSize = (_bitSize >>> 5) + 1;
  -     _bits = new int[_intSize + 1];
  +    public BitArray(int size) {        
  +        if (size < 32) size = 32;
  +        _bitSize = size;
  +        _intSize = (_bitSize >>> 5) + 1;
  +        _bits = new int[_intSize + 1];
       }
   
       public BitArray(int size, int[] bits) {
  @@ -138,25 +140,32 @@
        * Returns true if the given bit is set
        */
       public final boolean getBit(int bit) {
  -     return((_bits[bit>>>5] & _masks[bit%32]) != 0);
  +        if (DEBUG_ASSERTIONS) {
  +            if (bit >= _bitSize) {
  +                throw new Error(
  +                             "Programmer's assertion in  BitArray.getBit");
  +            }
  +        }
  +
  +        return((_bits[bit>>>5] & _masks[bit%32]) != 0);
       }
   
       /**
        * Returns the next set bit from a given position
        */
       public final int getNextBit(int startBit) {
  -     for (int i = (startBit >>> 5) ; i<=_intSize; i++) {
  -         int bits = _bits[i];
  -         if (bits != 0) {
  -             for (int b = (startBit % 32); b<32; b++) {
  -                 if ((bits & _masks[b]) != 0) {
  -                     return((i << 5) + b);
  -                 }
  -             }
  -         }
  -         startBit = 0;
  -     }
  -     return(DTMAxisIterator.END);
  +        for (int i = (startBit >>> 5) ; i<=_intSize; i++) {
  +            int bits = _bits[i];
  +            if (bits != 0) {
  +                for (int b = (startBit % 32); b<32; b++) {
  +                    if ((bits & _masks[b]) != 0) {
  +                        return((i << 5) + b);
  +                    }
  +                }
  +            }
  +            startBit = 0;
  +        }
  +        return(DTMAxisIterator.END);
       }
   
       /**
  @@ -213,11 +222,18 @@
        * Sets a given bit
        */
       public final void setBit(int bit) {
  -     if (bit >= _bitSize) return;
  -     final int i = (bit >>> 5);
  -     if (i < _first) _first = i;
  -     if (i > _last) _last = i;
  -     _bits[i] |= _masks[bit % 32];
  +        if (DEBUG_ASSERTIONS) {
  +            if (bit >= _bitSize) {
  +                throw new Error(
  +                             "Programmer's assertion in  BitArray.getBit");
  +            }
  +        }
  +
  +        if (bit >= _bitSize) return;
  +        final int i = (bit >>> 5);
  +        if (i < _first) _first = i;
  +        if (i > _last) _last = i;
  +        _bits[i] |= _masks[bit % 32];
       }
   
       /**
  @@ -287,6 +303,3 @@
       }
   
   }
  -
  -
  -    
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to