Skip to content

Commit 212dc6f

Browse files
committed
[GR-14480] Issues identified by Fortify report.
PullRequest: graalpython/440
2 parents 3135eaa + 2f0e067 commit 212dc6f

File tree

12 files changed

+22
-39
lines changed

12 files changed

+22
-39
lines changed

graalpython/com.oracle.graal.python.tck/src/com/oracle/graal/python/tck/PythonProvider.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,13 @@ private static Source createSource(String resourceName) throws IOException {
318318
int slashIndex = resourceName.lastIndexOf('/');
319319
String scriptName = slashIndex >= 0 ? resourceName.substring(slashIndex + 1) : resourceName;
320320
Reader in = new InputStreamReader(PythonProvider.class.getResourceAsStream(resourceName), "UTF-8");
321-
return Source.newBuilder(ID, in, scriptName).build();
321+
try {
322+
return Source.newBuilder(ID, in, scriptName).build();
323+
} finally {
324+
if (in != null) {
325+
in.close();
326+
}
327+
}
322328
}
323329

324330
private abstract static class PResultVerifier implements ResultVerifier {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1897,7 +1897,7 @@ private Object typeMetaclass(String name, PTuple bases, PDict namespace, PythonA
18971897
boolean addDict = false;
18981898
if (slots == null) {
18991899
// takes care of checking if we may_add_dict and adds it if needed
1900-
addDict = addDictIfNative(pythonClass);
1900+
addDictIfNative(pythonClass);
19011901
// TODO: tfel - also deal with weaklistoffset
19021902
} else {
19031903
// have slots

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,6 @@ private String format(String format, PTuple date) {
599599
break;
600600
}
601601
lastc = i + 1;
602-
i++;
603602
}
604603
return s;
605604
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/PySequenceArrayWrapperMR.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ Object doTuple(PTuple s, long idx, Object value,
335335

336336
@Fallback
337337
Object doGeneric(Object sequence, Object idx, Object value) {
338-
setItemNode().execute(sequence, idx, getToJavaNode().execute(value));
338+
getSetItemNode().execute(sequence, idx, getToJavaNode().execute(value));
339339
return value;
340340
}
341341

@@ -371,7 +371,7 @@ private SequenceStorageNodes.SetItemNode getSetByteItemNode() {
371371
return setByteItemNode;
372372
}
373373

374-
private LookupAndCallTernaryNode setItemNode() {
374+
private LookupAndCallTernaryNode getSetItemNode() {
375375
if (setItemNode == null) {
376376
CompilerDirectives.transferToInterpreterAndInvalidate();
377377
setItemNode = insert(LookupAndCallTernaryNode.create(__SETITEM__));

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/PCode.java

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
import java.util.ArrayList;
4444
import java.util.Arrays;
4545
import java.util.HashSet;
46-
import java.util.List;
4746
import java.util.Set;
4847

4948
import com.oracle.graal.python.PythonLanguage;
@@ -52,16 +51,13 @@
5251
import com.oracle.graal.python.builtins.objects.type.LazyPythonClass;
5352
import com.oracle.graal.python.nodes.ModuleRootNode;
5453
import com.oracle.graal.python.nodes.PRootNode;
55-
import com.oracle.graal.python.nodes.argument.ReadIndexedArgumentNode;
5654
import com.oracle.graal.python.nodes.argument.ReadVarArgsNode;
5755
import com.oracle.graal.python.nodes.argument.ReadVarKeywordsNode;
5856
import com.oracle.graal.python.nodes.frame.FrameSlotIDs;
59-
import com.oracle.graal.python.nodes.frame.WriteIdentifierNode;
6057
import com.oracle.graal.python.nodes.function.FunctionRootNode;
6158
import com.oracle.graal.python.nodes.generator.GeneratorFunctionRootNode;
6259
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
6360
import com.oracle.truffle.api.RootCallTarget;
64-
import com.oracle.truffle.api.nodes.Node;
6561
import com.oracle.truffle.api.nodes.NodeUtil;
6662
import com.oracle.truffle.api.nodes.RootNode;
6763
import com.oracle.truffle.api.source.SourceSection;
@@ -203,26 +199,6 @@ private static String extractName(RootNode rootNode) {
203199
return name;
204200
}
205201

206-
@TruffleBoundary
207-
private static Set<String> getKeywordArgumentNames(List<ReadIndexedArgumentNode> readKeywordNodes) {
208-
return extractArgumentNames(readKeywordNodes);
209-
}
210-
211-
@TruffleBoundary
212-
private static Set<String> extractArgumentNames(List<? extends ReadIndexedArgumentNode> readIndexedArgumentNodes) {
213-
Set<String> argNames = new HashSet<>();
214-
for (ReadIndexedArgumentNode node : readIndexedArgumentNodes) {
215-
Node parent = node.getParent();
216-
if (parent instanceof WriteIdentifierNode) {
217-
Object identifier = ((WriteIdentifierNode) parent).getIdentifier();
218-
if (identifier instanceof String) {
219-
argNames.add((String) identifier);
220-
}
221-
}
222-
}
223-
return argNames;
224-
}
225-
226202
private static int extractStackSize(RootNode rootNode) {
227203
return rootNode.getFrameDescriptor().getSize();
228204
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/IntBuiltins.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1821,7 +1821,7 @@ public PBytes fromPIntInt(PInt self, int byteCount, String byteorder, boolean si
18211821
// requested array is bigger then we obtained from BigInteger
18221822
byte[] resultBytes = new byte[byteCount];
18231823
System.arraycopy(bytes, 0, resultBytes, resultBytes.length - bytes.length, bytes.length);
1824-
if (signed && signByte == -1) {
1824+
if (signByte == -1) {
18251825
// add sign bytes
18261826
for (int i = 0; i < resultBytes.length - bytes.length; i++) {
18271827
resultBytes[i] = signByte;
@@ -1837,7 +1837,7 @@ public PBytes fromPIntInt(PInt self, int byteCount, String byteorder, boolean si
18371837
for (int i = 0; i < bytes.length; i++) {
18381838
resultBytes[i] = bytes[bytes.length - 1 - i];
18391839
}
1840-
if (byteCount > bytes.length && signed && signByte == -1) {
1840+
if (byteCount > bytes.length && signByte == -1) {
18411841
// add sign negative bytes
18421842
for (int i = bytes.length; i < resultBytes.length; i++) {
18431843
resultBytes[i] = signByte;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/zipimporter/PZipImporter.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,11 @@ private String getCode(String filenameAndSuffix) {
208208

209209
// reading the file should be done better?
210210
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
211-
StringBuilder code = new StringBuilder();
211+
int size = (int) entry.getSize();
212+
if (size < 0) {
213+
size = (int) entry.getCompressedSize();
214+
}
215+
StringBuilder code = new StringBuilder(size < 16 ? 16 : size);
212216
String line;
213217
while ((line = reader.readLine()) != null) {
214218
code.append(line);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/argument/ApplyKeywordsNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ Object[] applyCached(Object callee, @SuppressWarnings("unused") Signature callee
107107
throw raise(PythonBuiltinClassType.TypeError, "%s() got multiple values for argument '%s'", CreateArgumentsNode.getName(callee), name);
108108
}
109109
PArguments.setArgument(arguments, kwIdx, kwArg.getValue());
110-
} else if (takesVarKwds) {
110+
} else if (unusedKeywords != null) {
111111
unusedKeywords[k++] = kwArg;
112112
} else {
113113
additionalKwds++;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/argument/CreateArgumentsNode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ private Object[] createAndCheckArguments(PythonObject callable, Object[] args_w,
244244
// the called node takes and collect the rest in the keywords.
245245
if (keywords.length > 0) {
246246
// the node acts as a profile
247-
applyKeywords(callable, signature, scope_w, keywords);
247+
getApplyKeywordsNode(callable, signature, scope_w, keywords);
248248
}
249249

250250
if (too_many_args) {
@@ -265,7 +265,7 @@ private Object[] createAndCheckArguments(PythonObject callable, Object[] args_w,
265265
return scope_w;
266266
}
267267

268-
private void applyKeywords(Object callable, Signature signature, Object[] scope_w, PKeyword[] keywords) {
268+
private void getApplyKeywordsNode(Object callable, Signature signature, Object[] scope_w, PKeyword[] keywords) {
269269
if (applyKeywords == null) {
270270
CompilerDirectives.transferToInterpreterAndInvalidate();
271271
applyKeywords = insert(ApplyKeywordsNode.create());

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/builtins/ListNodes.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,6 @@ public SequenceStorage execute(Object iterator) {
241241
}
242242
case Generic: {
243243
Object[] elements = new Object[START_SIZE];
244-
array = elements;
245244
while (true) {
246245
try {
247246
Object value = next.execute(iterator);

0 commit comments

Comments
 (0)