Skip to content

Commit aebfe0e

Browse files
Improve performance of expr print in fopen mode string
1 parent adb15c7 commit aebfe0e

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

c/cert/src/rules/FIO03-C/FopenWithNonExclusiveFileCreationMode.ql

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,20 @@ import codingstandards.cpp.standardlibrary.FileAccess
1919

2020
class PrettyPrintExpr extends Expr {
2121
PrettyPrintExpr() {
22-
this instanceof BinaryOperation
23-
or
24-
this instanceof Literal
22+
exists(FOpenCall fopen | this.getParent*() = fopen.getMode()) and
23+
(
24+
this instanceof BinaryOperation
25+
or
26+
this instanceof Literal
27+
)
2528
}
2629
}
2730

28-
string prettyPrint(Expr e) {
29-
result = PrintExpr<PrettyPrintExpr>::print(e)
30-
}
31-
32-
from FOpenCall fopen
31+
from FOpenCall fopen, string modeStr
3332
where
3433
not isExcluded(fopen, IO5Package::fopenWithNonExclusiveFileCreationModeQuery()) and
3534
fopen.mayCreate() and
36-
not fopen.isExclusiveMode()
35+
not fopen.isExclusiveMode() and
36+
modeStr = PrintExpr<PrettyPrintExpr>::print(fopen.getMode())
3737
select fopen,
38-
"Call to create file with non-exclusive creation mode '" + prettyPrint(fopen.getMode()) + "'."
38+
"Call to create file with non-exclusive creation mode '" + modeStr + "'."

0 commit comments

Comments
 (0)