File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed
cpp/ql/test/query-tests/Critical/InitialisationNotRun Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change 1+ #include < string.h>
2+
3+ class GlobalStorage {
4+ public:
5+ char name[1000 ];
6+ };
7+
8+ GlobalStorage *g1; // BAD
9+ static GlobalStorage g2; // GOOD
10+ static GlobalStorage *g3; // BAD
11+ // static variables are initialized by compilers
12+ static int a; // GOOD
13+ static int b = 0 ; // GOOD
14+
15+ void init () { // initializes g_storage, but is never run from main
16+ g1 = new GlobalStorage ();
17+ g3 = new GlobalStorage ();
18+ }
19+
20+ void init2 (int b) {
21+ for (int i = 0 ; i < b; ++i)
22+ a *= -1 ;
23+ }
24+
25+ int main (int argc, char *argv[]) {
26+ // init not called
27+ strcpy (g1->name , argv[1 ]); // g1 is used before init() is called
28+ strcpy (g2.name , argv[1 ]); // g2 is initialised by compiler
29+ strcpy (g3->name , argv[1 ]);
30+ b++;
31+ return 0 ;
32+ }
You can’t perform that action at this time.
0 commit comments