Skip to content

Commit eab24cc

Browse files
committed
[GR-14133] Fix relevant issues identified by Fortify report.
Part 2 - the low issues.
1 parent abd6c3a commit eab24cc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+225
-269
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/PythonLanguage.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public final class PythonLanguage extends TruffleLanguage<PythonContext> {
111111
public final ConcurrentHashMap<Class<? extends PythonBuiltinBaseNode>, RootCallTarget> builtinCallTargetCache = new ConcurrentHashMap<>();
112112

113113
private static final Layout objectLayout = Layout.newLayout().build();
114-
private static final Shape freshShape = objectLayout.createShape(new ObjectType());
114+
private static final Shape newShape = objectLayout.createShape(new ObjectType());
115115

116116
public PythonLanguage() {
117117
this.nodeFactory = NodeFactory.create(this);
@@ -535,7 +535,7 @@ public PCode cacheCode(String filename, Supplier<PCode> createCode) {
535535
}
536536

537537
public static Shape freshShape() {
538-
return freshShape;
538+
return newShape;
539539
}
540540

541541
@Override

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/Python3Core.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ private static final PythonBuiltins[] initializeBuiltins(Env env) {
371371
*/
372372
private boolean initialized;
373373

374-
private final PythonObjectFactory factory = PythonObjectFactory.create();
374+
private final PythonObjectFactory objectFactory = PythonObjectFactory.create();
375375

376376
public Python3Core(PythonParser parser, Env env) {
377377
this.parser = parser;
@@ -463,9 +463,9 @@ public PythonModule getBuiltins() {
463463
public PException raise(PythonBuiltinClassType type, String format, Object... args) {
464464
PBaseException instance;
465465
if (format != null) {
466-
instance = factory.createBaseException(type, format, args);
466+
instance = objectFactory.createBaseException(type, format, args);
467467
} else {
468-
instance = factory.createBaseException(type);
468+
instance = objectFactory.createBaseException(type);
469469
}
470470
throw PException.fromObject(instance, null);
471471
}
@@ -579,7 +579,7 @@ private void addBuiltinsTo(PythonObject obj, PythonBuiltins builtinsForObj) {
579579
Object value;
580580
assert obj instanceof PythonModule || obj instanceof PythonBuiltinClass : "unexpected object while adding builtins";
581581
if (obj instanceof PythonModule) {
582-
value = factory.createBuiltinMethod(obj, (PBuiltinFunction) entry.getValue());
582+
value = objectFactory.createBuiltinMethod(obj, (PBuiltinFunction) entry.getValue());
583583
} else {
584584
value = entry.getValue().boundToObject(((PythonBuiltinClass) obj).getType(), factory());
585585
}
@@ -630,7 +630,7 @@ private Source getSource(String basename, String prefix) {
630630

631631
private void loadFile(String s, String prefix) {
632632
Source source = getSource(s, prefix);
633-
Supplier<PCode> getCode = () -> factory.createCode(Truffle.getRuntime().createCallTarget((RootNode) getParser().parse(ParserMode.File, this, source, null)));
633+
Supplier<PCode> getCode = () -> objectFactory.createCode(Truffle.getRuntime().createCallTarget((RootNode) getParser().parse(ParserMode.File, this, source, null)));
634634
RootCallTarget callTarget = getLanguage().cacheCode(source.getName(), getCode).getRootCallTarget();
635635
PythonModule mod = lookupBuiltinModule(s);
636636
if (mod == null) {
@@ -641,7 +641,7 @@ private void loadFile(String s, String prefix) {
641641
}
642642

643643
public PythonObjectFactory factory() {
644-
return factory;
644+
return objectFactory;
645645
}
646646

647647
public void setContext(PythonContext context) {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ private byte[] b64decode(byte[] data) {
134134
@Builtin(name = "a2b_hex", minNumOfPositionalArgs = 2, declaresExplicitSelf = true)
135135
@GenerateNodeFactory
136136
abstract static class A2bHexNode extends PythonBinaryBuiltinNode {
137-
private ReadAttributeFromObjectNode getAttrNode;
137+
private ReadAttributeFromObjectNode readAttrNode;
138138

139139
private PException raise(LazyPythonClass klass, String string) {
140140
return raise(factory().createBaseException(klass, string, new Object[0]));
@@ -167,11 +167,11 @@ private PException nonHexError(PythonModule self) {
167167
}
168168

169169
private ReadAttributeFromObjectNode getAttrNode() {
170-
if (getAttrNode == null) {
170+
if (readAttrNode == null) {
171171
CompilerDirectives.transferToInterpreterAndInvalidate();
172-
getAttrNode = insert(ReadAttributeFromObjectNode.create());
172+
readAttrNode = insert(ReadAttributeFromObjectNode.create());
173173
}
174-
return getAttrNode;
174+
return readAttrNode;
175175
}
176176
}
177177

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,7 +1344,7 @@ public PList listObject(@SuppressWarnings("unused") Object cls, Object arg) {
13441344
@Builtin(name = OBJECT, minNumOfPositionalArgs = 1, takesVarArgs = true, takesVarKeywordArgs = true, constructsClass = PythonBuiltinClassType.PythonObject)
13451345
@GenerateNodeFactory
13461346
public abstract static class ObjectNode extends PythonVarargsBuiltinNode {
1347-
@Child private PCallCapiFunction callNativeGenericNewNode;
1347+
@Child private PCallCapiFunction callCapiFunction;
13481348
@Children private CExtNodes.ToSulongNode[] toSulongNodes;
13491349
@Child private CExtNodes.AsPythonObjectNode asPythonObjectNode;
13501350
@Child private TypeNodes.GetInstanceShape getInstanceShapeNode;
@@ -1403,9 +1403,9 @@ private static PythonNativeClass findFirstNativeBaseClass(PythonAbstractClass[]
14031403
}
14041404

14051405
private Object callNativeGenericNewNode(PythonNativeClass self, Object[] varargs, PKeyword[] kwargs) {
1406-
if (callNativeGenericNewNode == null) {
1406+
if (callCapiFunction == null) {
14071407
CompilerDirectives.transferToInterpreterAndInvalidate();
1408-
callNativeGenericNewNode = insert(PCallCapiFunction.create(NativeCAPISymbols.FUN_PY_OBJECT_GENERIC_NEW));
1408+
callCapiFunction = insert(PCallCapiFunction.create(NativeCAPISymbols.FUN_PY_OBJECT_GENERIC_NEW));
14091409
}
14101410
if (toSulongNodes == null) {
14111411
CompilerDirectives.transferToInterpreterAndInvalidate();
@@ -1422,7 +1422,7 @@ private Object callNativeGenericNewNode(PythonNativeClass self, Object[] varargs
14221422
PTuple targs = factory().createTuple(varargs);
14231423
PDict dkwargs = factory().createDict(kwarr);
14241424
return asPythonObjectNode.execute(
1425-
callNativeGenericNewNode.call(toSulongNodes[0].execute(self), toSulongNodes[1].execute(self), toSulongNodes[2].execute(targs), toSulongNodes[3].execute(dkwargs)));
1425+
callCapiFunction.call(toSulongNodes[0].execute(self), toSulongNodes[1].execute(self), toSulongNodes[2].execute(targs), toSulongNodes[3].execute(dkwargs)));
14261426
}
14271427

14281428
private Shape getInstanceShape(LazyPythonClass clazz) {
@@ -1783,8 +1783,8 @@ public abstract static class TypeNode extends PythonBuiltinNode {
17831783
@Child private CastToListNode castToList;
17841784
@Child private CastToStringNode castToStringNode;
17851785
@Child private SequenceStorageNodes.LenNode slotLenNode;
1786-
@Child private SequenceStorageNodes.GetItemNode getSlotItemNode;
1787-
@Child private SequenceStorageNodes.AppendNode setSlotItemNode;
1786+
@Child private SequenceStorageNodes.GetItemNode getItemNode;
1787+
@Child private SequenceStorageNodes.AppendNode appendNode;
17881788
@Child private HashingStorageNodes.ContainsKeyNode containsKeyNode;
17891789
@Child private HashingStorageNodes.GetItemNode getDictItemNode;
17901790
@Child private CExtNodes.PCallCapiFunction callAddNativeSlotsNode;
@@ -1972,7 +1972,7 @@ private PTuple copySlots(String className, SequenceStorage slotList, int slotlen
19721972
}
19731973

19741974
setSlotItemNode().execute(newSlots, slotName);
1975-
if (containsKeyNode().execute(namespace.getDictStorage(), slotName)) {
1975+
if (getContainsKeyNode().execute(namespace.getDictStorage(), slotName)) {
19761976
throw raise(PythonBuiltinClassType.ValueError, "%s in __slots__ conflicts with class variable", slotName);
19771977
}
19781978
j++;
@@ -2021,7 +2021,7 @@ private String mangle(String privateobj, String ident) {
20212021
return "_" + privateobj.substring(ipriv) + ident;
20222022
}
20232023

2024-
private HashingStorageNodes.ContainsKeyNode containsKeyNode() {
2024+
private HashingStorageNodes.ContainsKeyNode getContainsKeyNode() {
20252025
if (containsKeyNode == null) {
20262026
CompilerDirectives.transferToInterpreterAndInvalidate();
20272027
containsKeyNode = insert(HashingStorageNodes.ContainsKeyNode.create());
@@ -2030,19 +2030,19 @@ private HashingStorageNodes.ContainsKeyNode containsKeyNode() {
20302030
}
20312031

20322032
private SequenceStorageNodes.GetItemNode getSlotItemNode() {
2033-
if (getSlotItemNode == null) {
2033+
if (getItemNode == null) {
20342034
CompilerDirectives.transferToInterpreterAndInvalidate();
2035-
getSlotItemNode = insert(SequenceStorageNodes.GetItemNode.create());
2035+
getItemNode = insert(SequenceStorageNodes.GetItemNode.create());
20362036
}
2037-
return getSlotItemNode;
2037+
return getItemNode;
20382038
}
20392039

20402040
private SequenceStorageNodes.AppendNode setSlotItemNode() {
2041-
if (setSlotItemNode == null) {
2041+
if (appendNode == null) {
20422042
CompilerDirectives.transferToInterpreterAndInvalidate();
2043-
setSlotItemNode = insert(SequenceStorageNodes.AppendNode.create(() -> NoGeneralizationNode.create("")));
2043+
appendNode = insert(SequenceStorageNodes.AppendNode.create(() -> NoGeneralizationNode.create("")));
20442044
}
2045-
return setSlotItemNode;
2045+
return appendNode;
20462046
}
20472047

20482048
private SequenceStorageNodes.LenNode getListLenNode() {

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -583,12 +583,6 @@ public PTuple doObject(Object a, Object b,
583583
return factory().createTuple(new Object[]{div, mod});
584584
}
585585

586-
@TruffleBoundary
587-
private static BigInteger[] divideAndRemainder(PInt a, PInt b) {
588-
BigInteger[] result = a.getValue().divideAndRemainder(b.getValue());
589-
assert result.length == 2;
590-
return result;
591-
}
592586
}
593587

594588
// eval(expression, globals=None, locals=None)

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

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -155,21 +155,6 @@ protected static boolean isIllegal(int fd) {
155155
return fd < -1;
156156
}
157157

158-
@SuppressWarnings("unused")
159-
private MapMode convertAccessToMapMode(int access) {
160-
switch (access) {
161-
case 0:
162-
return MapMode.READ_WRITE;
163-
case 1:
164-
return MapMode.READ_ONLY;
165-
case 2:
166-
return MapMode.READ_WRITE;
167-
case 3:
168-
return MapMode.PRIVATE;
169-
}
170-
throw raise(ValueError, "mmap invalid access parameter.");
171-
}
172-
173158
private void checkLength(int length) {
174159
if (length < 0) {
175160
invalidLengthProfile.enter();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ public int ceil(boolean value) {
248248
public Object ceil(PFloat value,
249249
@Cached("create(__CEIL__)") LookupAndCallUnaryNode dispatchCeil) {
250250
Object result = dispatchCeil.executeObject(value);
251-
if (PNone.NO_VALUE.equals(result)) {
251+
if (PNone.NO_VALUE == result) {
252252
if (MathGuards.fitLong(value.getValue())) {
253253
return ceilLong(value.getValue());
254254
} else {
@@ -582,7 +582,7 @@ public Object floor(Object value,
582582
@Cached("create()") CastToDoubleNode castNode,
583583
@Cached("create()") FloorNode recursiveNode) {
584584
Object result = dispatchFloor.executeObject(value);
585-
if (PNone.NO_VALUE.equals(result)) {
585+
if (PNone.NO_VALUE == result) {
586586
return recursiveNode.execute(castNode.execute(value));
587587
}
588588
return result;

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1286,8 +1286,13 @@ PTuple waitpid(Object pid, Object options) {
12861286
@GenerateNodeFactory
12871287
@TypeSystemReference(PythonArithmeticTypes.class)
12881288
abstract static class SystemNode extends PythonBuiltinNode {
1289-
static final String[] shell = System.getProperty("os.name").toLowerCase(Locale.ENGLISH).startsWith("windows") ? new String[]{"cmd.exe", "/c"}
1289+
static final String[] shell;
1290+
static {
1291+
String osProperty = System.getProperty("os.name");
1292+
shell = osProperty != null && osProperty.toLowerCase(Locale.ENGLISH).startsWith("windows") ? new String[]{"cmd.exe", "/c"}
12901293
: new String[]{(System.getenv().getOrDefault("SHELL", "sh")), "-c"};
1294+
}
1295+
12911296

12921297
static class PipePump extends Thread {
12931298
private static final int MAX_READ = 8192;

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@ abstract static class ProcessEscapeSequences extends PythonUnaryBuiltinNode {
111111
@Child private SequenceStorageNodes.ToByteArrayNode toByteArrayNode;
112112
@Child private BytesNodes.ToBytesNode toBytesNode;
113113

114-
@CompilationFinal private Pattern namedCaptGroupPattern;
115-
116114
@Specialization
117115
Object run(PString str) {
118116
return run(str.getValue());

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,16 +120,16 @@ public void postInitialize(PythonCore core) {
120120
}
121121

122122
private static class SignalTriggerAction implements AsyncHandler.AsyncAction {
123-
private final Object callable;
123+
private final Object callableObject;
124124
private final int signum;
125125

126126
SignalTriggerAction(Object callable, int signum) {
127-
this.callable = callable;
127+
this.callableObject = callable;
128128
this.signum = signum;
129129
}
130130

131131
public Object callable() {
132-
return callable;
132+
return callableObject;
133133
}
134134

135135
public Object[] arguments() {

0 commit comments

Comments
 (0)