File tree Expand file tree Collapse file tree 1 file changed +25
-5
lines changed
cpp/ql/test/query-tests/Likely Bugs/Conversion/ImplicitDowncastFromBitfield Expand file tree Collapse file tree 1 file changed +25
-5
lines changed Original file line number Diff line number Diff line change @@ -2,22 +2,42 @@ typedef struct {
2
2
int x : 24 ;
3
3
} my_struct;
4
4
5
- int getX1 (my_struct m) {
5
+ unsigned int getX1 (my_struct m) {
6
6
return m.x ;
7
7
}
8
8
9
9
short getX2 (my_struct m) {
10
- return m.x ;
10
+ return m.x ; // BAD
11
11
}
12
12
13
13
short getX3 (my_struct m) {
14
- return (short ) m.x ;
14
+ return (short ) m.x ; // GOOD
15
15
}
16
16
17
17
bool getX4 (my_struct m) {
18
- return m.x ;
18
+ return m.x ; // GOOD
19
19
}
20
20
21
21
short getX5 (my_struct m) {
22
- return (char ) m.x ;
22
+ return (char ) m.x ; // GOOD
23
+ }
24
+
25
+ const char & getx6 (my_struct& m) {
26
+ const char & result = m.x ; // BAD [NOT DETECTED]
27
+ return result;
28
+ }
29
+
30
+ const short & getx7 (my_struct& m) {
31
+ const short & result = (short ) m.x ; // GOOD
32
+ return result;
33
+ }
34
+
35
+ const int & getx8 (my_struct& m) {
36
+ const int & result = m.x ; // GOOD
37
+ return result;
38
+ }
39
+
40
+ const bool & getx9 (my_struct& m) {
41
+ const bool & result = m.x ; // GOOD
42
+ return result;
23
43
}
You can’t perform that action at this time.
0 commit comments