Author: j16sdiz
Date: 2009-04-24 14:04:06 +0000 (Fri, 24 Apr 2009)
New Revision: 27286

Modified:
   trunk/freenet/src/freenet/support/Buffer.java
   trunk/freenet/src/freenet/support/ShortBuffer.java
   trunk/freenet/test/freenet/support/BufferTest.java
   trunk/freenet/test/freenet/support/ShortBufferTest.java
Log:
doh! off-by-one error (with test case)

Modified: trunk/freenet/src/freenet/support/Buffer.java
===================================================================
--- trunk/freenet/src/freenet/support/Buffer.java       2009-04-24 12:34:45 UTC 
(rev 27285)
+++ trunk/freenet/src/freenet/support/Buffer.java       2009-04-24 14:04:06 UTC 
(rev 27286)
@@ -69,7 +69,7 @@
        }
 
        public Buffer(byte[] data, int start, int length) {
-               if(length < 0 || start < 0 || start + length >= data.length)
+               if(length < 0 || start < 0 || start + length > data.length)
                    throw new IllegalArgumentException("Invalid Length: start=" 
+ start + ", length=" + length);
                _start = start;
                _data = data;

Modified: trunk/freenet/src/freenet/support/ShortBuffer.java
===================================================================
--- trunk/freenet/src/freenet/support/ShortBuffer.java  2009-04-24 12:34:45 UTC 
(rev 27285)
+++ trunk/freenet/src/freenet/support/ShortBuffer.java  2009-04-24 14:04:06 UTC 
(rev 27286)
@@ -65,7 +65,7 @@
        }
 
        public ShortBuffer(byte[] data, int start, int length) {
-               if(length > Short.MAX_VALUE || length < 0 || start < 0 || start 
+ length >= data.length)
+               if(length > Short.MAX_VALUE || length < 0 || start < 0 || start 
+ length > data.length)
                    throw new IllegalArgumentException("Invalid Length: start=" 
+ start + ", length=" + length);
                _start = start;
                _data = data;

Modified: trunk/freenet/test/freenet/support/BufferTest.java
===================================================================
--- trunk/freenet/test/freenet/support/BufferTest.java  2009-04-24 12:34:45 UTC 
(rev 27285)
+++ trunk/freenet/test/freenet/support/BufferTest.java  2009-04-24 14:04:06 UTC 
(rev 27286)
@@ -80,6 +80,8 @@
                } catch(IllegalArgumentException e) {
                        // expect this
                }
+               new Buffer(new byte[1], 1, 0);
+               new Buffer(new byte[1], 0, 1);
        }
        
        public void testDataInputStreamBuffer() {

Modified: trunk/freenet/test/freenet/support/ShortBufferTest.java
===================================================================
--- trunk/freenet/test/freenet/support/ShortBufferTest.java     2009-04-24 
12:34:45 UTC (rev 27285)
+++ trunk/freenet/test/freenet/support/ShortBufferTest.java     2009-04-24 
14:04:06 UTC (rev 27286)
@@ -87,6 +87,8 @@
                } catch(IllegalArgumentException e) {
                        // expect this
                }
+               new Buffer(new byte[1], 1, 0);
+               new Buffer(new byte[1], 0, 1);
        }
        
        public void testDataInputStreamShortBuffer() {

_______________________________________________
cvs mailing list
[email protected]
http://emu.freenetproject.org/cgi-bin/mailman/listinfo/cvs

Reply via email to