Skip to content

Commit

Permalink
When caching names from bytes, pad with 0xff instead of 0
Browse files Browse the repository at this point in the history
0xff can't occur in well-formed UTF-8, so it will not cause false-positives.
Might resolve FasterXML#148
  • Loading branch information
rjmac committed Aug 11, 2014
1 parent ca94baf commit ce25ff4
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1960,6 +1960,7 @@ protected Name _parseAposName() throws IOException
}
Name name = _symbols.findName(quads, qlen);
if (name == null) {
quads[qlen - 1] = pad(quads[qlen - 1], currQuadBytes);
name = addName(quads, qlen, currQuadBytes);
}
return name;
Expand All @@ -1971,10 +1972,16 @@ protected Name _parseAposName() throws IOException
/**********************************************************
*/

private int pad(int q, int bytes) {
if(bytes == 4) return q;
return q | (-1 << (bytes << 3));
}

private final Name findName(int q1, int lastQuadBytes)
throws JsonParseException
{
// Usually we'll find it from the canonical symbol table already
q1 = pad(q1, lastQuadBytes);
Name name = _symbols.findName(q1);
if (name != null) {
return name;
Expand All @@ -1988,6 +1995,7 @@ private final Name findName(int q1, int q2, int lastQuadBytes)
throws JsonParseException
{
// Usually we'll find it from the canonical symbol table already
q2 = pad(q2, lastQuadBytes);
Name name = _symbols.findName(q1, q2);
if (name != null) {
return name;
Expand All @@ -2004,7 +2012,7 @@ private final Name findName(int[] quads, int qlen, int lastQuad, int lastQuadByt
if (qlen >= quads.length) {
_quadBuffer = quads = growArrayBy(quads, quads.length);
}
quads[qlen++] = lastQuad;
quads[qlen++] = pad(lastQuad, lastQuadBytes);
Name name = _symbols.findName(quads, qlen);
if (name == null) {
return addName(quads, qlen, lastQuadBytes);
Expand Down

0 comments on commit ce25ff4

Please sign in to comment.