Skip to content

Commit

Permalink
8294702: BufferedInputStream uses undefined value range for markpos
Browse files Browse the repository at this point in the history
Reviewed-by: alanb, bpb
  • Loading branch information
mkarg authored and Brian Burkhalter committed Oct 11, 2022
1 parent 9d0009e commit 619cd82
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/java.base/share/classes/java/io/BufferedInputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public BufferedInputStream(InputStream in, int size) {
*/
private void fill() throws IOException {
byte[] buffer = getBufIfOpen();
if (markpos < 0)
if (markpos == -1)
pos = 0; /* no mark: throw away the buffer */
else if (pos >= buffer.length) { /* no room left in buffer */
if (markpos > 0) { /* can throw away early part of the buffer */
Expand Down Expand Up @@ -306,7 +306,7 @@ private int read1(byte[] b, int off, int len) throws IOException {
if there is no mark/reset activity, do not bother to copy the
bytes into the local buffer. In this way buffered streams will
cascade harmlessly. */
if (len >= getBufIfOpen().length && markpos < 0) {
if (len >= getBufIfOpen().length && markpos == -1) {
return getInIfOpen().read(b, off, len);
}
fill();
Expand Down Expand Up @@ -427,7 +427,7 @@ private long implSkip(long n) throws IOException {

if (avail <= 0) {
// If no mark position set then don't keep in buffer
if (markpos <0)
if (markpos == -1)
return getInIfOpen().skip(n);

// Fill in buffer to save bytes for reset
Expand Down

1 comment on commit 619cd82

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.