File tree Expand file tree Collapse file tree 6 files changed +72
-6
lines changed
cpp/common/src/codingstandards/cpp
common/src/codingstandards/c Expand file tree Collapse file tree 6 files changed +72
-6
lines changed Original file line number Diff line number Diff line change
1
+ import cpp
2
+ import codingstandards.cpp.UndefinedBehavior
3
+
4
+ /**
5
+ * Library for modeling undefined behavior.
6
+ */
7
+ abstract class CUndefinedBehavior extends UndefinedBehavior { }
8
+
9
+ class C99MainFunction extends Function {
10
+ C99MainFunction ( ) {
11
+ this .getNumberOfParameters ( ) = 2 and
12
+ this .getType ( ) instanceof IntType and
13
+ this .getParameter ( 0 ) .getType ( ) instanceof IntType and
14
+ this .getParameter ( 1 ) .getType ( ) .( PointerType ) .getBaseType ( ) .( PointerType ) .getBaseType ( )
15
+ instanceof CharType
16
+ or
17
+ this .getNumberOfParameters ( ) = 0 and
18
+ this .getType ( ) instanceof VoidType
19
+ }
20
+ }
21
+
22
+ class CUndefinedMainDefinition extends CUndefinedBehavior , Function {
23
+ CUndefinedMainDefinition ( ) {
24
+ // for testing purposes, we use the prefix ____codeql_coding_standards`
25
+ ( this .getName ( ) = "main" or this .getName ( ) .indexOf ( "____codeql_coding_standards" ) = 0 ) and
26
+ not this instanceof C99MainFunction
27
+ }
28
+ }
Original file line number Diff line number Diff line change 13
13
14
14
import cpp
15
15
import codingstandards.c.misra
16
+ import codingstandards.c.UndefinedBehavior
16
17
17
- from
18
- where
19
- not isExcluded ( x , Language3Package:: occurrenceOfUndefinedBehaviorQuery ( ) ) and
20
- select
18
+ from CUndefinedBehavior c
19
+ where not isExcluded ( c , Language3Package:: occurrenceOfUndefinedBehaviorQuery ( ) )
20
+ select c , "May result in undefined behavior."
Original file line number Diff line number Diff line change 1
- No expected results have yet been specified
1
+ | test.c:8:6:8:35 | ____codeql_coding_standards_m2 | May result in undefined behavior. |
2
+ | test.c:11:5:11:34 | ____codeql_coding_standards_m3 | May result in undefined behavior. |
3
+ | test.c:15:5:15:34 | ____codeql_coding_standards_m4 | May result in undefined behavior. |
4
+ | test.c:19:5:19:34 | ____codeql_coding_standards_m5 | May result in undefined behavior. |
5
+ | test.c:23:5:23:34 | ____codeql_coding_standards_m6 | May result in undefined behavior. |
Original file line number Diff line number Diff line change
1
+ void main (void ) { // COMPLIANT
2
+ }
3
+
4
+ int ____codeql_coding_standards_m1 (int argc , char * * argv ) { // NON_COMPLIANT
5
+ return 0 ;
6
+ }
7
+
8
+ void ____codeql_coding_standards_m2 (char * argc , char * * argv ) { // NON_COMPLIANT
9
+ }
10
+
11
+ int ____codeql_coding_standards_m3 (int argc , char * argv ) { // NON_COMPLIANT
12
+ return 0 ;
13
+ }
14
+
15
+ int ____codeql_coding_standards_m4 () { // NON_COMPLIANT
16
+ return 0 ;
17
+ }
18
+
19
+ int ____codeql_coding_standards_m5 (int argc , int * argv ) { // NON_COMPLIANT
20
+ return 0 ;
21
+ }
22
+
23
+ int ____codeql_coding_standards_m6 (int argc , int * * argv ) { // NON_COMPLIANT
24
+ return 0 ;
25
+ }
Original file line number Diff line number Diff line change
1
+ import cpp
2
+ /**
3
+ * Library for modeling undefined behavior.
4
+ */
5
+ abstract class UndefinedBehavior extends Locatable { }
6
+ abstract class CPPUndefinedBehavior extends UndefinedBehavior { }
Original file line number Diff line number Diff line change 38
38
"tags" : [
39
39
" maintainability" ,
40
40
" readability"
41
- ]
41
+ ],
42
+ "implementation_scope" : {
43
+ "description" : " This implementation only considers alternate forms of `main` and the undefined behavior that results. Additional cases from Appendix J of the C99 standard are not currently considered."
44
+ }
42
45
}
43
46
],
44
47
"title" : " There shall be no occurrence of undefined or critical unspecified behavior"
You can’t perform that action at this time.
0 commit comments