You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by mi...@apache.org on 2004/06/07 18:04:08 UTC
cvs commit: xml-xalan/java/src/org/apache/xml/serializer WriterToUTF8Buffered.java
minchau 2004/06/07 09:04:08
Modified: java/src/org/apache/xml/serializer WriterToUTF8Buffered.java
Log:
PR: bugzilla 29372
Submitted by: J Desrochers (john@ASCnet.COM)
Reviewed by: Brian Minchau
A safe fix for chunking up an array for output. The length was multiplied by the
chunk number (0,1,2... chunks) then divided by "chunks". John's fix uses a
"long" to do the arithemetic because multiplying by the chunk number first
could cause an overflow.
Revision Changes Path
1.6 +6 -4 xml-xalan/java/src/org/apache/xml/serializer/WriterToUTF8Buffered.java
Index: WriterToUTF8Buffered.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/serializer/WriterToUTF8Buffered.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- WriterToUTF8Buffered.java 17 Feb 2004 04:18:18 -0000 1.5
+++ WriterToUTF8Buffered.java 7 Jun 2004 16:04:08 -0000 1.6
@@ -185,12 +185,14 @@
* Cut the buffer up into chunks, each of which will
* not cause an overflow to the output buffer m_outputBytes,
* and make multiple recursive calls.
+ * Be careful about integer overflows in multiplication.
*/
final int chunks = 1 + length/CHARS_MAX;
- for (int chunk =0 ; chunk < chunks; chunk++)
+ int end_chunk = start;
+ for (int chunk = 1; chunk <= chunks; chunk++)
{
- int start_chunk = start + ((length*chunk)/chunks);
- int end_chunk = start + ((length*(chunk+1))/chunks);
+ int start_chunk = end_chunk;
+ end_chunk = start + (int) ((((long) length) * chunk) / chunks);
int len_chunk = (end_chunk - start_chunk);
this.write(chars,start_chunk, len_chunk);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org