Changeset 54563b0


Ignore:
Timestamp:
Aug 23, 2014 11:49:34 PM (6 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
04ad7de
Parents:
593779b5
Message:

catch swapped args

File:
1 edited

Legend:

Unmodified
Added
Removed
  • core/java/src/net/i2p/data/DataHelper.java

    r593779b5 r54563b0  
    629629     * @param value value to write out, non-negative
    630630     * @param rawStream stream to write to
    631      * @param numBytes number of bytes to write the number into (padding as necessary)
    632      * @throws DataFormatException if value is negative
     631     * @param numBytes number of bytes to write the number into, 1-8 (padding as necessary)
     632     * @throws DataFormatException if value is negative or if numBytes not 1-8
    633633     * @throws IOException if there is an IO error writing to the stream
    634634     */
    635635    public static void writeLong(OutputStream rawStream, int numBytes, long value)
    636636        throws DataFormatException, IOException {
    637         if (value < 0) throw new DataFormatException("Value is negative (" + value + ")");
     637        if (numBytes <= 0 || numBytes > 8)
     638            // probably got the args backwards
     639            throw new DataFormatException("Bad byte count " + numBytes);
     640        if (value < 0)
     641            throw new DataFormatException("Value is negative (" + value + ")");
    638642        for (int i = (numBytes - 1) * 8; i >= 0; i -= 8) {
    639643            byte cur = (byte) (value >> i);
Note: See TracChangeset for help on using the changeset viewer.