Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6855686

Browse files
authored
Merge pull request#647 from rak3-sh/rp/m0-1-10-646
Consider "main()" with typedef'd int return type as MainFunction
2 parents01a73a0 +6a1b283 commit6855686

File tree

8 files changed

+58
-1
lines changed

8 files changed

+58
-1
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-`M0-1-10` -`EncapsulatingFunctions.qll`:
2+
- Fixes#646. Consider typedef'd`int` return types for`main()` function as MainFunction.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| test.cpp:23:14:23:26 | uncalled_func | Function uncalled_func is never called. |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rules/M0-1-10/UnusedFunction.ql
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include<cstdint>
2+
3+
namespacemains {
4+
static std::int32_t var;
5+
6+
// @brief namespace_func
7+
staticvoid
8+
namespace_func(void)noexcept {// COMPLIANT: Called from "main" below.
9+
mains::var = -1;
10+
return;
11+
}
12+
}// namespace mains
13+
14+
std::int32_tfunc2()// COMPLIANT: Called from func1
15+
{
16+
return mains::var +20;
17+
}
18+
19+
std::int32_tfunc1() {// COMPLIANT: Called from main
20+
return mains::var +func2();// func2 called here.
21+
}
22+
23+
std::int32_tuncalled_func()// NON_COMPLIANT: Not called.
24+
{
25+
return mains::var +func1();// func1 called here.
26+
}
27+
28+
// @brief main
29+
// @return exit code
30+
std::int32_tmain(void) {
31+
std::int32_t ret{0};
32+
try {
33+
ret =func1();// func1 called here.
34+
mains::var += ret;
35+
}catch (...) {
36+
mains::namespace_func();// namespace_func called here.
37+
}
38+
return ret;
39+
}

‎cpp/common/src/codingstandards/cpp/EncapsulatingFunctions.qll‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ abstract class EncapsulatingFunction extends Function { }
1414
classMainFunctionextendsMainLikeFunction{
1515
MainFunction(){
1616
hasGlobalName("main")and
17-
getType()instanceofIntType
17+
getType().resolveTypedefs()instanceofIntType
1818
}
1919
}
2020

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| test.cpp:5:9:5:12 | main |
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import cpp
2+
import codingstandards.cpp.EncapsulatingFunctions
3+
4+
fromMainFunctionm
5+
selectm
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
typedefsignedintint32_t;
2+
3+
// @brief main
4+
// @return exit code
5+
int32_tmain(void) {
6+
int32_t ret{0};
7+
return ret;
8+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp