natString.cc (getBytes (jstring enc)): Fixed the loop for multiple cycles, Code cleanup
authorMarco Trudel <mtrudel@gmx.ch>
Mon, 12 Mar 2007 19:48:32 +0000 (20:48 +0100)
committerTom Tromey <tromey@gcc.gnu.org>
Mon, 12 Mar 2007 19:48:32 +0000 (19:48 +0000)
2007-03-12  Marco Trudel  <mtrudel@gmx.ch>

* java/lang/natString.cc (getBytes (jstring enc)):
Fixed the loop for multiple cycles, Code cleanup

From-SVN: r122859

libjava/ChangeLog
libjava/java/lang/natString.cc

index 57485ef8ebf27ef1a05fd08d472719bd511641cd..ef215ef31a1e5bfe8719f78b34c9f8e7bbe01f0e 100644 (file)
@@ -1,3 +1,8 @@
+2007-03-12  Marco Trudel  <mtrudel@gmx.ch>
+
+       * java/lang/natString.cc (getBytes (jstring enc)):
+       Fixed the loop for multiple cycles, Code cleanup
+
 2007-03-09  Tom Tromey  <tromey@redhat.com>
 
        * sources.am, Makefile.in: Rebuilt.
index f86abd8bc2da9a9abd55bfaff0119d60f6d58ae5..39590a3e4e07489a5d294ffa38bd6ba53ed3b6b3 100644 (file)
@@ -1,6 +1,6 @@
 // natString.cc - Implementation of java.lang.String native methods.
 
-/* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006  Free Software Foundation
+/* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007  Free Software Foundation
 
    This file is part of libgcj.
 
@@ -615,11 +615,9 @@ java::lang::String::getBytes (jstring enc)
   while (todo > 0 || converter->havePendingBytes())
     {
       converter->setOutput(buffer, bufpos);
-      // We only really need to do a single write.
-      converter->setFinished();
       int converted = converter->write(this, offset, todo, NULL);
       bufpos = converter->count;
-      if (converted == 0 && bufpos == converter->count)
+      if (converted == 0)
        {
          buflen *= 2;
          jbyteArray newbuffer = JvNewByteArray(buflen);
@@ -627,10 +625,15 @@ java::lang::String::getBytes (jstring enc)
          buffer = newbuffer;
        }
       else
-       bufpos = converter->count;
-
-      offset += converted;
-      todo -= converted;
+       {
+         offset += converted;
+         todo -= converted;
+       }
+    }
+  if (length() > 0)
+    {
+      converter->setFinished();
+      converter->write(this, 0, 0, NULL);
     }
   converter->done ();
   if (bufpos == buflen)