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

View File

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