This is the mail archive of the java-discuss@sourceware.cygnus.com mailing list for the GCJ project. See the GCJ home page for more information.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: [patch] String.getBytes()


I'm rather sick now, so I may not be thinking too clearly,
but your patch seems wrong to me.  I think something like
the following (untested) is right.  Basically, `buflen'
should be the allocated size of `buffer', while `bufpos'
is the number of bytes written to it.

Index: natString.cc
===================================================================
RCS file: /cvs/cvsfiles/devo/libjava/java/lang/natString.cc,v
retrieving revision 1.24
diff -u -r1.24 natString.cc
--- natString.cc	1999/04/21 19:40:27	1.24
+++ natString.cc	1999/04/21 20:23:52
@@ -473,9 +473,11 @@
     {
       converter->setOutput(buffer, bufpos);
       int converted = converter->write(this, offset, todo, NULL);
+      bufpos = converter->count;
       if (converted == 0)
 	{
-	  jbyteArray newbuffer = JvNewByteArray(2 * buflen);
+	  buflen = 2 * buflen;
+	  jbyteArray newbuffer = JvNewByteArray(buflen);
 	  memcpy (elements (newbuffer), elements (buffer), bufpos);
 	  buffer = newbuffer;
 	}

	--Per Bothner
Cygnus Solutions     bothner@cygnus.com     http://www.cygnus.com/~bothner