Skip to content

Commit

Permalink
[Truffle] Fix sprintf hash arg check
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon Fish committed Dec 12, 2016
1 parent 4fb3526 commit 5ac33ad
Showing 1 changed file with 4 additions and 6 deletions.
Expand Up @@ -31,7 +31,6 @@ public List<SprintfConfig> parse() {
ArgType argType = ArgType.NONE;

final int end = source.length;
int argumentIndex = 0;

for (int i = 0; i < end; ) {

Expand Down Expand Up @@ -132,7 +131,7 @@ public List<SprintfConfig> parse() {
config.setNamesBytes(charsToBytes(nameBytes));
i = j + 1;
checkNameArg(argType, nameBytes);
checkHash(arguments, argumentIndex);
checkHash(arguments);
argType = ArgType.NAMED;
argTypeSet = true;
if (term == '}') {
Expand Down Expand Up @@ -255,14 +254,13 @@ public List<SprintfConfig> parse() {
throw new InvalidFormatException("malformed format string - %" + p);
}
}
argumentIndex += 1;
}
return configs;
}

private static void checkHash(Object[] arguments, int argumentIndex) {
if(argumentIndex >= arguments.length ||
!RubyGuards.isRubyHash(arguments[argumentIndex])) {
private static void checkHash(Object[] arguments) {
if(arguments.length != 1 ||
!RubyGuards.isRubyHash(arguments[0])) {
throw new InvalidFormatException("one hash required");
}
}
Expand Down

0 comments on commit 5ac33ad

Please sign in to comment.