File tree Expand file tree Collapse file tree 3 files changed +67
-0
lines changed
c/common/test/rules/wrapspuriousfunctioninloop Expand file tree Collapse file tree 3 files changed +67
-0
lines changed Original file line number Diff line number Diff line change
1
+ | test.c:11:5:11:12 | call to cnd_wait | Use of a function that may wake up spuriously without a controlling loop. |
2
+ | test.c:49:3:49:10 | call to cnd_wait | Use of a function that may wake up spuriously without a controlling loop. |
3
+ | test.c:59:5:59:12 | call to cnd_wait | Use of a function that may wake up spuriously without a controlling loop. |
Original file line number Diff line number Diff line change
1
+ // GENERATED FILE - DO NOT MODIFY
2
+ import codingstandards.cpp.rules.wrapspuriousfunctioninloop.WrapSpuriousFunctionInLoop
Original file line number Diff line number Diff line change
1
+ #include <stddef.h>
2
+ #include <threads.h>
3
+
4
+ static mtx_t lk ;
5
+ static cnd_t cnd ;
6
+
7
+ void f1 () {
8
+ mtx_lock (& lk );
9
+
10
+ if (1 ) {
11
+ cnd_wait (& cnd , & lk ); // NON_COMPLIANT
12
+ }
13
+ }
14
+
15
+ void f2 () {
16
+ mtx_lock (& lk );
17
+ int i = 2 ;
18
+ while (i > 0 ) {
19
+ cnd_wait (& cnd , & lk ); // COMPLIANT
20
+ i -- ;
21
+ }
22
+ }
23
+
24
+ void f3 () {
25
+ mtx_lock (& lk );
26
+ int i = 2 ;
27
+ do {
28
+ cnd_wait (& cnd , & lk ); // COMPLIANT
29
+ i -- ;
30
+ } while (i > 0 );
31
+ }
32
+
33
+ void f4 () {
34
+ mtx_lock (& lk );
35
+
36
+ for (;;) {
37
+ cnd_wait (& cnd , & lk ); // COMPLIANT
38
+ }
39
+ }
40
+
41
+ void f5 () {
42
+ mtx_lock (& lk );
43
+
44
+ int i = 2 ;
45
+ while (i > 0 ) {
46
+ i -- ;
47
+ }
48
+
49
+ cnd_wait (& cnd , & lk ); // NON_COMPLIANT
50
+ }
51
+
52
+ void f6 () {
53
+ mtx_lock (& lk );
54
+
55
+ for (int i = 0 ; i < 10 ; i ++ ) {
56
+ }
57
+ int i = 0 ;
58
+ if (i > 0 ) {
59
+ cnd_wait (& cnd , & lk ); // NON_COMPLIANT
60
+ i -- ;
61
+ }
62
+ }
You can’t perform that action at this time.
0 commit comments