Skip to content

Commit de0500e

Browse files
committed
fix possible out of bounds
1 parent 8eb686b commit de0500e

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,21 +223,22 @@ public void postInitialize(PythonCore core) {
223223
Object[] path;
224224
int pathIdx = 0;
225225
boolean doIsolate = PythonOptions.getOption(context, PythonOptions.IsolateFlag);
226-
int defaultPaths = doIsolate ? 3 : 4;
226+
boolean capiSeparate = !capiHome.equals(coreHome);
227+
int defaultPathsLen = (doIsolate ? 3 : 4) + (capiSeparate ? 1 : 0);
227228
if (option.length() > 0) {
228229
String[] split = option.split(context.getEnv().getPathSeparator());
229-
path = new Object[split.length + defaultPaths];
230+
path = new Object[split.length + defaultPathsLen];
230231
System.arraycopy(split, 0, path, 0, split.length);
231232
pathIdx = split.length;
232233
} else {
233-
path = new Object[defaultPaths];
234+
path = new Object[defaultPathsLen];
234235
}
235236
if (!doIsolate) {
236237
path[pathIdx++] = getScriptPath(env, args);
237238
}
238239
path[pathIdx++] = stdlibHome;
239240
path[pathIdx++] = coreHome + env.getFileNameSeparator() + "modules";
240-
if (!capiHome.equals(coreHome)) {
241+
if (capiSeparate) {
241242
// include our native modules on the path
242243
path[pathIdx++] = capiHome + env.getFileNameSeparator() + "modules";
243244
}

0 commit comments

Comments
 (0)