Skip to content

Commit c7b708d

Browse files
committed
Fix: used incorrect length of byte array.
1 parent 910f33c commit c7b708d

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,19 +226,19 @@ public Object bytearray(PythonClass cls, Object iterable, @SuppressWarnings("unu
226226
try {
227227
byte item = castToByteNode.execute(getNextNode.execute(it));
228228
if (i >= arr.length) {
229-
arr = resize(arr);
229+
arr = resize(arr, arr.length * 2);
230230
}
231231
arr[i++] = item;
232232
} catch (PException e) {
233233
e.expect(StopIteration, getCore(), stopIterationProfile);
234-
return create(cls, arr);
234+
return create(cls, resize(arr, i));
235235
}
236236
}
237237
}
238238

239239
@TruffleBoundary(transferToInterpreterOnException = false)
240-
private static byte[] resize(byte[] arr) {
241-
return Arrays.copyOf(arr, arr.length * 2);
240+
private static byte[] resize(byte[] arr, int len) {
241+
return Arrays.copyOf(arr, len);
242242
}
243243

244244
protected boolean isInt(Object o) {

0 commit comments

Comments
 (0)