Skip to content

Commit d78c6fb

Browse files
committed
RULE-21-4: longjmp can be a macro or a function
1 parent 40f0b39 commit d78c6fb

File tree

1 file changed

+41
-29
lines changed

1 file changed

+41
-29
lines changed

c/misra/src/rules/RULE-21-4/StandardHeaderFileUsedSetjmph.ql

Lines changed: 41 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,44 @@
1010
* external/misra/obligation/required
1111
*/
1212

13-
import cpp
14-
import codingstandards.c.misra
15-
16-
class SetJmp extends Locatable {
17-
string name;
18-
19-
SetJmp() {
20-
this.getFile().getAbsolutePath().matches("%setjmp.h") and
21-
name = [this.(Macro).getName(), this.(Function).getName()] and
22-
name = ["setjmp", "longjmp"]
23-
}
24-
25-
Locatable getAnInvocation() {
26-
result = this.(Macro).getAnInvocation() or
27-
result = this.(Function).getACallToThisFunction()
28-
}
29-
30-
string getName() { result = name }
31-
}
32-
33-
from Locatable use, string name
34-
where
35-
not isExcluded(use, BannedPackage::standardHeaderFileUsedSetjmphQuery()) and
36-
exists(SetJmp jmp |
37-
use = jmp.getAnInvocation() and
38-
name = jmp.getName()
39-
)
40-
select use, "Use of " + name + "."
41-
13+
import cpp
14+
import codingstandards.c.misra
15+
16+
abstract class Jmp extends Locatable {
17+
string name;
18+
19+
Jmp() {
20+
this.getFile().getAbsolutePath().matches("%setjmp.h") and
21+
name = [this.(Macro).getName(), this.(Function).getName()]
22+
}
23+
24+
Locatable getAnInvocation() {
25+
result = this.(Macro).getAnInvocation() or
26+
result = this.(Function).getACallToThisFunction()
27+
}
28+
29+
string getName() { result = name }
30+
}
31+
32+
class SetJmp extends Jmp {
33+
SetJmp() {
34+
name = "setjmp" and
35+
this.(Macro).getName() = name
36+
}
37+
}
38+
39+
class LongJmp extends Jmp {
40+
LongJmp() {
41+
name = "longjmp" and
42+
[this.(Macro).getName(), this.(Function).getName()] = name
43+
}
44+
}
45+
46+
from Locatable use, string name
47+
where
48+
not isExcluded(use, BannedPackage::standardHeaderFileUsedSetjmphQuery()) and
49+
exists(Jmp jmp |
50+
use = jmp.getAnInvocation() and
51+
name = jmp.getName()
52+
)
53+
select use, "Use of " + name + "."

0 commit comments

Comments
 (0)