1 | // RUN: %check_clang_tidy %s cert-msc32-c %t -- -config="{CheckOptions: {cert-msc32-c.DisallowedSeedTypes: 'some_type,time_t'}}" -- -std=c99 |
2 | |
3 | void srand(int seed); |
4 | typedef int time_t; |
5 | time_t time(time_t *t); |
6 | |
7 | void f(void) { |
8 | srand(seed: 1); |
9 | // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: random number generator seeded with a constant value will generate a predictable sequence of values [cert-msc32-c] |
10 | |
11 | const int a = 1; |
12 | srand(seed: a); |
13 | // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: random number generator seeded with a constant value will generate a predictable sequence of values [cert-msc32-c] |
14 | |
15 | time_t t; |
16 | srand(seed: time(t: &t)); // Disallowed seed type |
17 | // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: random number generator seeded with a disallowed source of seed value will generate a predictable sequence of values [cert-msc32-c] |
18 | } |
19 | |
20 | void g(void) { |
21 | typedef int user_t; |
22 | user_t a = 1; |
23 | srand(seed: a); |
24 | |
25 | int b = 1; |
26 | srand(seed: b); // Can not evaluate as int |
27 | } |
28 | |