Changeset 6124


Ignore:
Timestamp:
04/14/10 11:49:47 (10 years ago)
Author:
curtis
Message:

Add explicit bounds checking to unpackBytes.
Makes for nicer error messages, but I did not check the effect on performance.
(We may need to remove the bounds check if it hurts performance too much.)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/components/common/src/loci/common/DataTools.java

    r6072 r6124  
    496496   * Translates nBytes of the given long and places the result in the 
    497497   * given byte array. 
     498   * 
     499   * @throws IllegalArgumentException 
     500   *   if the specified indices fall outside the buffer 
    498501   */ 
    499502  public static void unpackBytes(long value, byte[] buf, int ndx, 
    500503    int nBytes, boolean little) 
    501504  { 
     505    if (buf.length < ndx + nBytes) { 
     506      throw new IllegalArgumentException("Invalid indices: buf.length=" + 
     507        buf.length + ", ndx=" + ndx + ", nBytes=" + nBytes); 
     508    } 
    502509    if (little) { 
    503510      for (int i=0; i<nBytes; i++) { 
Note: See TracChangeset for help on using the changeset viewer.