From de2baf30bbd4ad88d018bc8bcf89bc1a1cc2b9e1 Mon Sep 17 00:00:00 2001
From: Mark Wielaard <mark@klomp.org>
Date: Mon, 30 Dec 2002 07:16:59 +0000
Subject: [PATCH] StringBuffer.java (getChars): Remove wrong dstOffset check
 against count.

        * java/lang/StringBuffer.java (getChars): Remove wrong dstOffset check
        against count.

From-SVN: r60616
---
 libjava/ChangeLog                   |  5 ++++
 libjava/java/lang/StringBuffer.java | 39 +++++++++++++++--------------
 2 files changed, 25 insertions(+), 19 deletions(-)

diff --git a/libjava/ChangeLog b/libjava/ChangeLog
index 1d8107b206e4..3831b9548cb5 100644
--- a/libjava/ChangeLog
+++ b/libjava/ChangeLog
@@ -1,3 +1,8 @@
+2002-12-30  Mark Wielaard  <mark@klomp.org>
+
+	* java/lang/StringBuffer.java (getChars): Remove wrong dstOffset check
+	against count.
+
 2002-12-27  Mark Mitchell  <mark@codesourcery.com>
 
 	* boehm.cc: Remove stray semicolon.
diff --git a/libjava/java/lang/StringBuffer.java b/libjava/java/lang/StringBuffer.java
index bfaaaf92f23d..922d6bb6d241 100644
--- a/libjava/java/lang/StringBuffer.java
+++ b/libjava/java/lang/StringBuffer.java
@@ -308,26 +308,27 @@ public final class StringBuffer implements Serializable, CharSequence
       }
   }
 
-  /** Get the specified array of characters.
-   *  The characters will be copied into the array you pass in.
-   *  @param srcOffset the index to start copying from in the
-   *         <code>StringBuffer</code>.
-   *  @param srcEnd the number of characters to copy.
-   *  @param dst the array to copy into.
-   *  @param dstOffset the index to start copying into <code>dst</code>.
-   *  @exception NullPointerException if dst is null.
-   *  @exception IndexOutOfBoundsException if any source or target
-   *             indices are out of range.
-   *  @see java.lang.System#arraycopy(java.lang.Object,int,java.lang.Object,int,int)
-   */
-  public synchronized void getChars (int srcOffset, int srcEnd,
-				     char[] dst, int dstOffset)
-  {
-    if (srcOffset < 0 || srcOffset > srcEnd)
-      throw new StringIndexOutOfBoundsException (srcOffset);
+  /**
+   * Get the specified array of characters. <code>srcOffset - srcEnd</code>
+   * characters will be copied into the array you pass in.
+   *
+   * @param srcOffset the index to start copying from (inclusive)
+   * @param srcEnd the index to stop copying from (exclusive)
+   * @param dst the array to copy into
+   * @param dstOffset the index to start copying into
+   * @throws NullPointerException if dst is null
+   * @throws IndexOutOfBoundsException if any source or target indices are
+   *         out of range (while unspecified, source problems cause a
+   *         StringIndexOutOfBoundsException, and dest problems cause an
+   *         ArrayIndexOutOfBoundsException)
+   * @see System#arraycopy(Object, int, Object, int, int)
+   */
+  public synchronized void getChars(int srcOffset, int srcEnd,
+                                    char[] dst, int dstOffset)
+  {
     int todo = srcEnd - srcOffset;
-    if (srcEnd > count || dstOffset + todo > count)
-      throw new StringIndexOutOfBoundsException (srcEnd);
+    if (srcOffset < 0 || srcEnd > count || todo < 0)
+      throw new StringIndexOutOfBoundsException();
     System.arraycopy(value, srcOffset, dst, dstOffset, todo);
   }
 
-- 
GitLab