[kaffe] CVS kaffe (dalibor): Fixed small nio underflow problem

Kaffe CVS cvs-commits at kaffe.org
Thu May 27 14:54:02 PDT 2004


PatchSet 4791 
Date: 2004/05/27 21:42:45
Author: dalibor
Branch: HEAD
Tag: (none) 
Log:
Fixed small nio underflow problem

2004-05-27  Dalibor Topic  <robilad at kaffe.org>

        * libraries/javalib/java/nio/ByteBufferImpl.java,
        libraries/javalib/java/nio/CharBufferImpl.java,
        libraries/javalib/java/nio/DoubleBufferImpl.java,
        libraries/javalib/java/nio/FloatBufferImpl.java,
        libraries/javalib/java/nio/IntBufferImpl.java,
        libraries/javalib/java/nio/LongBufferImpl.java,
        libraries/javalib/java/nio/ShortBufferImpl.java:
        (get) Improved documentation. Added underflow check.

Members: 
	ChangeLog:1.2360->1.2361 
	libraries/javalib/java/nio/ByteBufferImpl.java:1.6->1.7 
	libraries/javalib/java/nio/CharBufferImpl.java:1.4->1.5 
	libraries/javalib/java/nio/DoubleBufferImpl.java:1.4->1.5 
	libraries/javalib/java/nio/FloatBufferImpl.java:1.4->1.5 
	libraries/javalib/java/nio/IntBufferImpl.java:1.4->1.5 
	libraries/javalib/java/nio/LongBufferImpl.java:1.4->1.5 
	libraries/javalib/java/nio/ShortBufferImpl.java:1.4->1.5 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.2360 kaffe/ChangeLog:1.2361
--- kaffe/ChangeLog:1.2360	Thu May 27 19:36:38 2004
+++ kaffe/ChangeLog	Thu May 27 21:42:45 2004
@@ -1,5 +1,16 @@
 2004-05-27  Dalibor Topic  <robilad at kaffe.org>
 
+        * libraries/javalib/java/nio/ByteBufferImpl.java,
+        libraries/javalib/java/nio/CharBufferImpl.java,
+        libraries/javalib/java/nio/DoubleBufferImpl.java,
+        libraries/javalib/java/nio/FloatBufferImpl.java,
+        libraries/javalib/java/nio/IntBufferImpl.java,
+        libraries/javalib/java/nio/LongBufferImpl.java,
+        libraries/javalib/java/nio/ShortBufferImpl.java:
+	(get) Improved documentation. Added underflow check.
+
+2004-05-27  Dalibor Topic  <robilad at kaffe.org>
+
 	* libraries/javalib/java/nio/CharBuffer.java:
 	Resynced with GNU Classpath.
 
Index: kaffe/libraries/javalib/java/nio/ByteBufferImpl.java
diff -u kaffe/libraries/javalib/java/nio/ByteBufferImpl.java:1.6 kaffe/libraries/javalib/java/nio/ByteBufferImpl.java:1.7
--- kaffe/libraries/javalib/java/nio/ByteBufferImpl.java:1.6	Thu May 27 00:06:32 2004
+++ kaffe/libraries/javalib/java/nio/ByteBufferImpl.java	Thu May 27 21:42:47 2004
@@ -129,20 +129,20 @@
   }
 
   /**
-   * Relative get method. Reads the next <code>byte</code> from the buffer.
+   * Reads the <code>byte</code> at this buffer's current position,
+   * and then increments the position.
    *
-   * @exception BufferUnderflowException If there is no next byte to read
+   * @exception BufferUnderflowException If there are no remaining
+   * <code>bytes</code> in this buffer.
    */
   public byte get ()
   {
-    try {
-	byte result = backing_buffer [position () + array_offset];
-    	position (position () + 1);
-    	return result;
-    }
-    catch (ArrayIndexOutOfBoundsException e) {
+    if (!hasRemaining())
 	throw new BufferUnderflowException();
-    }
+
+    byte result = backing_buffer [position () + array_offset];
+    position (position () + 1);
+    return result;
   }
   
   /**
Index: kaffe/libraries/javalib/java/nio/CharBufferImpl.java
diff -u kaffe/libraries/javalib/java/nio/CharBufferImpl.java:1.4 kaffe/libraries/javalib/java/nio/CharBufferImpl.java:1.5
--- kaffe/libraries/javalib/java/nio/CharBufferImpl.java:1.4	Mon Apr 12 11:40:27 2004
+++ kaffe/libraries/javalib/java/nio/CharBufferImpl.java	Thu May 27 21:42:47 2004
@@ -1,5 +1,5 @@
 /* CharBufferImpl.java -- 
-   Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -116,10 +116,17 @@
   }
   
   /**
-   * Relative get method. Reads the next <code>char</code> from the buffer.
+   * Reads the <code>char</code> at this buffer's current position,
+   * and then increments the position.
+   *
+   * @exception BufferUnderflowException If there are no remaining
+   * <code>chars</code> in this buffer.
    */
   public char get ()
   {
+    if (!hasRemaining())
+	throw new BufferUnderflowException();
+
     char result = backing_buffer [position ()];
     position (position () + 1);
     return result;
Index: kaffe/libraries/javalib/java/nio/DoubleBufferImpl.java
diff -u kaffe/libraries/javalib/java/nio/DoubleBufferImpl.java:1.4 kaffe/libraries/javalib/java/nio/DoubleBufferImpl.java:1.5
--- kaffe/libraries/javalib/java/nio/DoubleBufferImpl.java:1.4	Mon Apr 12 11:40:28 2004
+++ kaffe/libraries/javalib/java/nio/DoubleBufferImpl.java	Thu May 27 21:42:47 2004
@@ -1,5 +1,5 @@
 /* DoubleBufferImpl.java -- 
-   Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -98,10 +98,17 @@
   }
 
   /**
-   * Relative get method. Reads the next <code>double</code> from the buffer.
+   * Reads the <code>double</code> at this buffer's current position,
+   * and then increments the position.
+   *
+   * @exception BufferUnderflowException If there are no remaining
+   * <code>doubles</code> in this buffer.
    */
   public double get ()
   {
+    if (!hasRemaining())
+      throw new BufferUnderflowException();
+
     double result = backing_buffer [position ()];
     position (position () + 1);
     return result;
Index: kaffe/libraries/javalib/java/nio/FloatBufferImpl.java
diff -u kaffe/libraries/javalib/java/nio/FloatBufferImpl.java:1.4 kaffe/libraries/javalib/java/nio/FloatBufferImpl.java:1.5
--- kaffe/libraries/javalib/java/nio/FloatBufferImpl.java:1.4	Mon Apr 12 11:40:28 2004
+++ kaffe/libraries/javalib/java/nio/FloatBufferImpl.java	Thu May 27 21:42:47 2004
@@ -1,5 +1,5 @@
 /* FloatBufferImpl.java -- 
-   Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -98,10 +98,17 @@
   }
 
   /**
-   * Relative get method. Reads the next <code>float</code> from the buffer.
+   * Reads the <code>float</code> at this buffer's current position,
+   * and then increments the position.
+   *
+   * @exception BufferUnderflowException If there are no remaining
+   * <code>floats</code> in this buffer.
    */
   public float get ()
   {
+    if (!hasRemaining())
+      throw new BufferUnderflowException();
+
     float result = backing_buffer [position ()];
     position (position () + 1);
     return result;
Index: kaffe/libraries/javalib/java/nio/IntBufferImpl.java
diff -u kaffe/libraries/javalib/java/nio/IntBufferImpl.java:1.4 kaffe/libraries/javalib/java/nio/IntBufferImpl.java:1.5
--- kaffe/libraries/javalib/java/nio/IntBufferImpl.java:1.4	Mon Apr 12 11:40:28 2004
+++ kaffe/libraries/javalib/java/nio/IntBufferImpl.java	Thu May 27 21:42:47 2004
@@ -1,5 +1,5 @@
 /* IntBufferImpl.java -- 
-   Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -98,10 +98,17 @@
   }
 
   /**
-   * Relative get method. Reads the next <code>int</code> from the buffer.
+   * Reads the <code>int</code> at this buffer's current position,
+   * and then increments the position.
+   *
+   * @exception BufferUnderflowException If there are no remaining
+   * <code>ints</code> in this buffer.
    */
   public int get ()
   {
+    if (!hasRemaining())
+      throw new BufferUnderflowException();
+
     int result = backing_buffer [position ()];
     position (position () + 1);
     return result;
Index: kaffe/libraries/javalib/java/nio/LongBufferImpl.java
diff -u kaffe/libraries/javalib/java/nio/LongBufferImpl.java:1.4 kaffe/libraries/javalib/java/nio/LongBufferImpl.java:1.5
--- kaffe/libraries/javalib/java/nio/LongBufferImpl.java:1.4	Mon Apr 12 11:40:28 2004
+++ kaffe/libraries/javalib/java/nio/LongBufferImpl.java	Thu May 27 21:42:47 2004
@@ -1,5 +1,5 @@
 /* LongBufferImpl.java -- 
-   Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -98,10 +98,17 @@
   }
 
   /**
-   * Relative get method. Reads the next <code>long</code> from the buffer.
+   * Reads the <code>long</code> at this buffer's current position,
+   * and then increments the position.
+   *
+   * @exception BufferUnderflowException If there are no remaining
+   * <code>longs</code> in this buffer.
    */
   public long get ()
   {
+    if (!hasRemaining())
+      throw new BufferUnderflowException();
+
     long result = backing_buffer [position ()];
     position (position () + 1);
     return result;
Index: kaffe/libraries/javalib/java/nio/ShortBufferImpl.java
diff -u kaffe/libraries/javalib/java/nio/ShortBufferImpl.java:1.4 kaffe/libraries/javalib/java/nio/ShortBufferImpl.java:1.5
--- kaffe/libraries/javalib/java/nio/ShortBufferImpl.java:1.4	Mon Apr 12 11:40:28 2004
+++ kaffe/libraries/javalib/java/nio/ShortBufferImpl.java	Thu May 27 21:42:47 2004
@@ -1,5 +1,5 @@
 /* ShortBufferImpl.java -- 
-   Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -98,10 +98,17 @@
   }
 
   /**
-   * Relative get method. Reads the next <code>short</code> from the buffer.
+   * Reads the <code>short</code> at this buffer's current position,
+   * and then increments the position.
+   *
+   * @exception BufferUnderflowException If there are no remaining
+   * <code>shorts</code> in this buffer.
    */
   public short get ()
   {
+    if (!hasRemaining())
+      throw new BufferUnderflowException();
+
     short result = backing_buffer [position ()];
     position (position () + 1);
     return result;




More information about the kaffe mailing list