Skip to content

Commit f43cf3e

Browse files
committed
Merge M17-0-5 and ERR52-CPP
1 parent b76309c commit f43cf3e

File tree

15 files changed

+55
-48
lines changed

15 files changed

+55
-48
lines changed

cpp/autosar/src/rules/M17-0-5/SetjmpMacroAndTheLongjmpFunctionUsed.ql

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,10 @@
1515

1616
import cpp
1717
import codingstandards.cpp.autosar
18+
import codingstandards.cpp.rules.donotusesetjmporlongjmpshared.DoNotUseSetjmpOrLongjmpShared
1819

19-
predicate isLongJumpCall(Locatable fc) {
20-
fc.(FunctionCall).getTarget().hasGlobalOrStdName("longjmp") or
21-
fc.(MacroInvocation).getMacroName() = "longjmp"
20+
class SetjmpMacroAndTheLongjmpFunctionUsedQuery extends DoNotUseSetjmpOrLongjmpSharedSharedQuery {
21+
SetjmpMacroAndTheLongjmpFunctionUsedQuery() {
22+
this = BannedFunctionsPackage::setjmpMacroAndTheLongjmpFunctionUsedQuery()
23+
}
2224
}
23-
24-
predicate isSetJumpCall(MacroInvocation mi) { mi.getMacroName() = "setjmp" }
25-
26-
from Element jmp, string callType
27-
where
28-
not isExcluded(jmp, BannedFunctionsPackage::setjmpMacroAndTheLongjmpFunctionUsedQuery()) and
29-
(
30-
isLongJumpCall(jmp) and callType = "longjmp function"
31-
or
32-
isSetJumpCall(jmp) and callType = "setjmp macro"
33-
)
34-
select jmp, "Use of banned " + callType + "."

cpp/autosar/test/rules/M17-0-5/SetjmpMacroAndTheLongjmpFunctionUsed.qlref

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cpp/common/test/rules/donotusesetjmporlongjmpshared/DoNotUseSetjmpOrLongjmpShared.ql

cpp/cert/src/rules/ERR52-CPP/DoNotUseSetjmpOrLongjmp.ql

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,10 @@
1313

1414
import cpp
1515
import codingstandards.cpp.cert
16+
import codingstandards.cpp.rules.donotusesetjmporlongjmpshared.DoNotUseSetjmpOrLongjmpShared
1617

17-
predicate isLongJumpCall(FunctionCall fc) { fc.getTarget().hasGlobalOrStdName("longjmp") }
18-
19-
predicate isSetJumpCall(MacroInvocation mi) { mi.getMacroName() = "setjmp" }
20-
21-
from Element jmp, string callType
22-
where
23-
not isExcluded(jmp, BannedFunctionsPackage::doNotUseSetjmpOrLongjmpQuery()) and
24-
(
25-
isLongJumpCall(jmp) and callType = "longjmp function"
26-
or
27-
isSetJumpCall(jmp) and callType = "setjmp macro"
28-
)
29-
select jmp, "Use of banned " + callType + "."
18+
class DoNotUseSetjmpOrLongjmpQuery extends DoNotUseSetjmpOrLongjmpSharedSharedQuery {
19+
DoNotUseSetjmpOrLongjmpQuery() {
20+
this = BannedFunctionsPackage::doNotUseSetjmpOrLongjmpQuery()
21+
}
22+
}

cpp/cert/test/rules/ERR52-CPP/DoNotUseSetjmpOrLongjmp.expected

Lines changed: 0 additions & 2 deletions
This file was deleted.

cpp/cert/test/rules/ERR52-CPP/DoNotUseSetjmpOrLongjmp.qlref

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cpp/common/test/rules/donotusesetjmporlongjmpshared/DoNotUseSetjmpOrLongjmpShared.ql

cpp/cert/test/rules/ERR52-CPP/test.cpp

Lines changed: 0 additions & 15 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Provides a library which includes a `problems` predicate for reporting....
3+
*/
4+
5+
import cpp
6+
import codingstandards.cpp.Customizations
7+
import codingstandards.cpp.Exclusions
8+
9+
abstract class DoNotUseSetjmpOrLongjmpSharedSharedQuery extends Query { }
10+
11+
Query getQuery() { result instanceof DoNotUseSetjmpOrLongjmpSharedSharedQuery }
12+
13+
predicate isLongJumpCall(Locatable fc) {
14+
fc.(FunctionCall).getTarget().hasGlobalOrStdName("longjmp") or
15+
fc.(MacroInvocation).getMacroName() = "longjmp"
16+
}
17+
18+
predicate isSetJumpCall(MacroInvocation mi) { mi.getMacroName() = "setjmp" }
19+
20+
query predicate problems(Element jmp, string message) {
21+
exists(string callType |
22+
not isExcluded(jmp, getQuery()) and
23+
message = "Use of banned " + callType + "." and
24+
(
25+
isLongJumpCall(jmp) and callType = "longjmp function"
26+
or
27+
isSetJumpCall(jmp) and callType = "setjmp macro"
28+
)
29+
)
30+
}

0 commit comments

Comments
 (0)