Skip to content

Commit e1190d8

Browse files
committed
Improve fix for FP for issue 216
reintroduce omission wrappers
1 parent 5432a1d commit e1190d8

File tree

4 files changed

+18
-15
lines changed

4 files changed

+18
-15
lines changed

cpp/autosar/src/rules/A5-1-1/LiteralValueUsedOutsideTypeInit.ql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ where
2626
not exists(ConstructorCall cc | cc.getAnArgument() = l) and
2727
not exists(ConstructorFieldInit cf | cf.getExpr() = l) and
2828
not l = any(LoggingOperation logOp).getALoggedExpr().getAChild*() and
29+
// Exclude arguments to wrapper functions (depth 1)
30+
not exists(FunctionCall fc, LoggerOrStreamWrapperFunction w |
31+
fc.getAnArgument() = l and w.getACallToThisFunction() = fc
32+
) and
2933
// Exclude Macros with names like *LOG
3034
not exists(MacroInvocation m | m.getMacroName().matches("%LOG") and m.getAnAffectedElement() = l) and
3135
// Exclude literal 0
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
| test.cpp:5:9:5:25 | constant string | Literal value "constant string" used outside of type initialization StringLiteral |
22
| test.cpp:14:23:14:25 | 100 | Literal value 100 used outside of type initialization Literal |
33
| test.cpp:54:7:54:7 | 1 | Literal value 1 used outside of type initialization Literal |
4+
| test.cpp:75:23:75:28 | test | Literal value "test" used outside of type initialization StringLiteral |
5+
| test.cpp:76:19:76:28 | not okay | Literal value "not okay" used outside of type initialization StringLiteral |

cpp/autosar/test/rules/A5-1-1/test.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,9 @@ void test_stream_two(std::ostream &os, const char *str,
7272
}
7373

7474
void test_not_wrapper_stream(std::ostream &os, const char *str) noexcept {
75-
test_stream_two(
76-
os, "test",
77-
"not okay"); // NON_COMPLIANT[FALSE_NEGATIVE] - test_stream_two is
78-
// not actually exclusively a wrapper
75+
test_stream_two(os, "test",
76+
"not okay"); // NON_COMPLIANT - test_stream_two is
77+
// not actually exclusively a wrapper
7978
}
8079

8180
#define MACRO_LOG(test_str) \

cpp/common/src/codingstandards/cpp/LoggingOperation.qll

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ class OutputWriteLogging extends LoggingOperation, OutputWrite {
2020
/**
2121
* A `FileStreamFunctionCall` operation is considered a log operation for Coding Standards purposes.
2222
*/
23-
class FileStreamLogging extends LoggingOperation, FileStreamFunctionCall {
24-
override Expr getALoggedExpr() { result = getAnArgument() }
23+
class FileStreamLogging extends LoggingOperation {
24+
FileStreamLogging() { this instanceof FileStreamFunctionCall }
25+
26+
override Expr getALoggedExpr() { result = this.(FileStreamFunctionCall).getAnArgument() }
2527

26-
override Expr getFStream() { result = this.getQualifier() }
28+
Expr getFStream() { result = this.(FileStreamFunctionCall).getQualifier() }
2729
}
2830

2931
/** A call which looks like `printf`. */
@@ -39,14 +41,10 @@ class PrintfLikeCall extends LoggingOperation, Call {
3941
*/
4042
class LoggerOrStreamWrapperFunction extends Function {
4143
LoggerOrStreamWrapperFunction() {
42-
forall(Parameter p | p.getFunction() = this |
43-
forall(VariableAccess va | va = p.getAnAccess() |
44-
(
45-
any(FileStreamFunctionCall fc).getAnArgument().getAChild*() = va
46-
or
47-
any(LoggingOperation logOp).getALoggedExpr().getAChild*() = va
48-
)
49-
)
44+
forall(VariableAccess va |
45+
exists(Parameter p | p.getFunction() = this and va = p.getAnAccess())
46+
|
47+
any(LoggingOperation logOp).getALoggedExpr().getAChild*() = va
5048
)
5149
}
5250
}

0 commit comments

Comments
 (0)