Skip to content

Commit e1884c1

Browse files
committed
C++: Add tests (and fix a missing quote in the alert message).
1 parent 6cb5db2 commit e1884c1

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed

cpp/ql/src/Critical/GlobalUseBeforeInit.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,5 +111,5 @@ where
111111
uninitialisedBefore(v, f) and
112112
useFunc(v, f)
113113
select f,
114-
"The variable '" + v.getName() +
114+
"The variable '" + v.getName() + "'" +
115115
" is used in this function but may not be initialized when it is called."
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| test.cpp:27:5:27:6 | f1 | The variable 'b' is used in this function but may not be initialized when it is called. |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Critical/GlobalUseBeforeInit.ql
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
typedef __builtin_va_list va_list;
2+
typedef struct {} FILE;
3+
4+
extern FILE * stdin;
5+
extern FILE * stdout;
6+
extern FILE * stderr;
7+
8+
#define va_start(args, fmt) __builtin_va_start(args,fmt)
9+
#define va_end(args) __builtin_va_end(args);
10+
11+
int vfprintf (FILE *, const char *, va_list);
12+
13+
int a = 1;
14+
int b;
15+
16+
int my_printf(const char * fmt, ...)
17+
{
18+
va_list vl;
19+
int ret;
20+
va_start(vl, fmt);
21+
ret = vfprintf(stdout, fmt, vl);
22+
ret = vfprintf(stderr, fmt, vl);
23+
va_end(vl);
24+
return ret;
25+
}
26+
27+
int f1()
28+
{
29+
my_printf("%d\n", a + 2);
30+
my_printf("%d\n", b + 2); // BAD
31+
return 0;
32+
}
33+
34+
int main()
35+
{
36+
int b = f1();
37+
return 0;
38+
}

0 commit comments

Comments
 (0)