Skip to content

Commit 3b70892

Browse files
committed
FIO-46: file as expression
1 parent 63c9c7c commit 3b70892

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

cpp/common/src/codingstandards/cpp/rules/donotaccessaclosedfile/DoNotAccessAClosedFile.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ predicate accessSameVariable(VariableAccess va1, VariableAccess va2) {
2727
va1.getTarget() = va2.getTarget()
2828
}
2929

30-
SubBasicBlock followsFileClose(SubBasicBlock source, VariableAccess closedFile) {
30+
SubBasicBlock followsFileClose(SubBasicBlock source, Expr closedFile) {
3131
result = source
3232
or
3333
exists(SubBasicBlock mid |

cpp/common/src/codingstandards/cpp/standardlibrary/FileAccess.qll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,18 +114,18 @@ class ImplicitFileAccess extends FileAccess {
114114
string fileName;
115115

116116
ImplicitFileAccess() {
117-
fileName = ["stdin", "_Stdin"] and
117+
fileName = "stdin" and
118118
this.getTarget().hasGlobalName(["getchar", "getwchar", "scanf", "scanf_s"])
119119
or
120-
fileName = ["stdout", "_Stdout"] and
120+
fileName = "stdout" and
121121
this.getTarget().hasGlobalName(["printf", "printf_s", "puts", "putchar", "putwchar"])
122122
or
123-
fileName = ["stderr", "_Stderr"] and this.getTarget().hasGlobalName("perror")
123+
fileName = "stderr" and this.getTarget().hasGlobalName("perror")
124124
}
125125

126126
/** The expression corresponding to the accessed file */
127127
override Expr getFileExpr() {
128-
fileName = result.(VariableAccess).getTarget().(GlobalVariable).toString() or
128+
result = any(MacroInvocation mi | mi.getMacroName() = fileName).getExpr() or
129129
fileName = result.findRootCause().(Macro).getName()
130130
}
131131
}

0 commit comments

Comments
 (0)