Fix a pair of relatively benign off-by-one bugs. These only manifest if the source Reader returns characters one-at-a-time.

This commit is contained in:
Jesse Wilson 2011-07-22 15:50:26 +00:00
parent befcfd908b
commit 161b4babe8
1 changed files with 2 additions and 2 deletions

View File

@ -846,7 +846,7 @@ public final class JsonReader implements Closeable {
limit += total;
// if this is the first read, consume an optional byte order mark (BOM) if it exists
if (bufferStartLine == 1 && bufferStartColumn == 1 && limit > 1 && buffer[0] == '\ufeff') {
if (bufferStartLine == 1 && bufferStartColumn == 1 && limit > 0 && buffer[0] == '\ufeff') {
pos++;
bufferStartColumn--;
}
@ -956,7 +956,7 @@ public final class JsonReader implements Closeable {
private boolean skipTo(String toFind) throws IOException {
outer:
for (; pos + toFind.length() < limit || fillBuffer(toFind.length()); pos++) {
for (; pos + toFind.length() <= limit || fillBuffer(toFind.length()); pos++) {
for (int c = 0; c < toFind.length(); c++) {
if (buffer[pos + c] != toFind.charAt(c)) {
continue outer;