Skip to content

Commit 19c1ee5

Browse files
committed
Adds preliminary modernization
1 parent 85f5ad2 commit 19c1ee5

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

python/ql/src/Expressions/WrongNumberArgumentsForFormat.ql

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,29 @@
1515
import python
1616
import semmle.python.strings
1717

18-
predicate string_format(BinaryExpr operation, StrConst str, Object args, AstNode origin) {
19-
exists(Object fmt, Context ctx | operation.getOp() instanceof Mod |
20-
operation.getLeft().refersTo(ctx, fmt, _, str) and
21-
operation.getRight().refersTo(ctx, args, _, origin)
18+
predicate string_format(BinaryExpr operation, StrConst str, Value args, AstNode origin) {
19+
exists(Value fmt, Context ctx | operation.getOp() instanceof Mod |
20+
operation.getLeft().pointsTo(ctx, fmt, str) and
21+
operation.getRight().pointsTo(ctx, args, origin)
2222
)
2323
}
2424

25-
int sequence_length(Object args) {
25+
int sequence_length(Value args) {
2626
/* Guess length of sequence */
27-
exists(Tuple seq |
28-
seq = args.getOrigin() |
27+
exists(Tuple seq, AstNode origin |
28+
seq.pointsTo(args,origin) |
2929
result = strictcount(seq.getAnElt()) and
3030
not seq.getAnElt() instanceof Starred
3131
)
3232
or
3333
exists(ImmutableLiteral i |
34-
i.getLiteralObject() = args |
34+
i.getLiteralValue() = args |
3535
result = 1
3636
)
3737
}
3838

3939

40-
from BinaryExpr operation, StrConst fmt, Object args, int slen, int alen, AstNode origin, string provided
40+
from BinaryExpr operation, StrConst fmt, Value args, int slen, int alen, AstNode origin, string provided
4141
where string_format(operation, fmt, args, origin) and slen = sequence_length(args) and alen = format_items(fmt) and slen != alen and
4242
(if slen = 1 then provided = " is provided." else provided = " are provided.")
4343
select operation, "Wrong number of $@ for string format. Format $@ takes " + alen.toString() + ", but " + slen.toString() + provided,

0 commit comments

Comments
 (0)