Skip to content

Commit

Permalink
Avoid saving string values for tokens that don't require them
Browse files Browse the repository at this point in the history
This saves memory, and avoids an OOM discovered by fuzz testing.

PiperOrigin-RevId: 657713111
  • Loading branch information
cushon authored and Javac Team committed Jul 30, 2024
1 parent 74b8aa3 commit 1ed4779
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion java/com/google/turbine/parse/VariableInitializerParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,23 @@ private void dropBraces() {
}

private void save() {
tokens.add(new SavedToken(token, lexer.stringValue(), lexer.position()));
String value;
switch (token) {
case IDENT:
case INT_LITERAL:
case LONG_LITERAL:
case DOUBLE_LITERAL:
case FLOAT_LITERAL:
case STRING_LITERAL:
case CHAR_LITERAL:
value = lexer.stringValue();
break;
default:
// memory optimization: don't save string values for tokens that don't require them
value = null;
break;
}
tokens.add(new SavedToken(token, value, lexer.position()));
}

private void dropBracks(int many) {
Expand Down

0 comments on commit 1ed4779

Please sign in to comment.