You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openoffice.apache.org by da...@apache.org on 2022/10/16 16:33:55 UTC
[openoffice] branch trunk updated: Fix some errors in the scripting module's XInputStreamImpl: - Check the loop termination in readBytes() properly: currently it increments totalBytesRead while also decrementing nBytesToRead, so when compared to each other, the loop terminates when the buffer is half full. Only check for nBytesToRead instead. - Deal with the possibility of available() returning 0 in readSomeBytes().
This is an automated email from the ASF dual-hosted git repository.
damjan pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/openoffice.git
The following commit(s) were added to refs/heads/trunk by this push:
new 7e29bacc90 Fix some errors in the scripting module's XInputStreamImpl: - Check the loop termination in readBytes() properly: currently it increments totalBytesRead while also decrementing nBytesToRead, so when compared to each other, the loop terminates when the buffer is half full. Only check for nBytesToRead instead. - Deal with the possibility of available() returning 0 in readSomeBytes().
7e29bacc90 is described below
commit 7e29bacc90c4b1b9788c3b71dfacd17daecde7a7
Author: Damjan Jovanovic <da...@apache.org>
AuthorDate: Sun Oct 16 18:31:15 2022 +0200
Fix some errors in the scripting module's XInputStreamImpl:
- Check the loop termination in readBytes() properly: currently it increments
totalBytesRead while also decrementing nBytesToRead, so when compared to
each other, the loop terminates when the buffer is half full. Only check
for nBytesToRead instead.
- Deal with the possibility of available() returning 0 in readSomeBytes().
Patch by: me
---
.../com/sun/star/script/framework/io/XInputStreamImpl.java | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/main/scripting/java/com/sun/star/script/framework/io/XInputStreamImpl.java b/main/scripting/java/com/sun/star/script/framework/io/XInputStreamImpl.java
index 4926ce8e45..a9c58f72ce 100644
--- a/main/scripting/java/com/sun/star/script/framework/io/XInputStreamImpl.java
+++ b/main/scripting/java/com/sun/star/script/framework/io/XInputStreamImpl.java
@@ -44,11 +44,17 @@ public class XInputStreamImpl implements XInputStream
try
{
int bytesRead = 0;
- while ( ( bytesRead = is.read( aData[ 0 ], totalBytesRead, nBytesToRead ) ) > 0 && ( totalBytesRead < nBytesToRead ) )
+ while ( ( nBytesToRead > 0 ) && ( bytesRead = is.read( aData[ 0 ], totalBytesRead, nBytesToRead ) ) > 0 )
{
totalBytesRead += bytesRead;
nBytesToRead -= bytesRead;
}
+ if ( totalBytesRead < aData[ 0 ].length )
+ {
+ byte[] out = new byte[ totalBytesRead ];
+ System.arraycopy( aData[ 0 ], 0, out, 0, totalBytesRead );
+ aData[ 0 ] = out;
+ }
}
catch ( IOException e )
{
@@ -65,7 +71,7 @@ public class XInputStreamImpl implements XInputStream
{
int bytesToRead = nMaxBytesToRead;
int availableBytes = available();
- if ( availableBytes < nMaxBytesToRead )
+ if ( 0 < availableBytes && availableBytes < nMaxBytesToRead )
{
bytesToRead = availableBytes;
}