Skip to content

Commit 2eb0322

Browse files
committed
Fix: shrink array if varargs are less than expected
1 parent b14bdc9 commit 2eb0322

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PythonCextBuiltins.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3338,17 +3338,22 @@ static Object callFunction(VirtualFrame frame, Object callable, Object vaList,
33383338
*/
33393339
long arraySize = argsArrayLib.getArraySize(vaList);
33403340
Object[] args = new Object[PInt.intValueExact(arraySize) - 1];
3341+
int filled = 0;
33413342
for (int i = 0; i < args.length; i++) {
33423343
try {
33433344
Object object = argsArrayLib.readArrayElement(vaList, i);
33443345
if (argLib.isNull(object)) {
33453346
break;
33463347
}
33473348
args[i] = asPythonObjectNode.execute(object);
3349+
filled++;
33483350
} catch (InvalidArrayIndexException e) {
33493351
throw CompilerDirectives.shouldNotReachHere();
33503352
}
33513353
}
3354+
if (filled < args.length) {
3355+
args = PythonUtils.arrayCopyOf(args, filled);
3356+
}
33523357
return callableLib.callObject(callable, frame, args);
33533358
} catch (UnsupportedMessageException | OverflowException e) {
33543359
// I think we can just assume that there won't be more than

0 commit comments

Comments
 (0)