Skip to content

Commit 88a39d9

Browse files
committed
[CPP-370] Fix up // GOOD and // BAD test annotations so that they're consistent.
1 parent 0f5a4a7 commit 88a39d9

File tree

3 files changed

+44
-44
lines changed

3 files changed

+44
-44
lines changed

cpp/ql/test/query-tests/Likely Bugs/Format/NonConstantFormat/NonConstantFormat.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,23 @@ extern char *any_random_function(const char *);
2727

2828
int main(int argc, char **argv) {
2929
if(argc > 1)
30-
printf(argv[1]); // not ok
30+
printf(argv[1]); // BAD
3131
else
32-
printf("No argument supplied.\n"); // ok
32+
printf("No argument supplied.\n"); // GOOD
3333

34-
printf(_("No argument supplied.\n")); // ok
34+
printf(_("No argument supplied.\n")); // GOOD
3535

36-
printf(dgettext(NULL, "No argument supplied.\n")); // ok
36+
printf(dgettext(NULL, "No argument supplied.\n")); // GOOD
3737

38-
printf(ngettext("One argument\n", "%d arguments\n", argc-1), argc-1); // ok
38+
printf(ngettext("One argument\n", "%d arguments\n", argc-1), argc-1); // GOOD
3939

40-
printf(gettext("%d arguments\n"), argc-1); // ok
41-
printf(any_random_function("%d arguments\n"), argc-1); // not ok
40+
printf(gettext("%d arguments\n"), argc-1); // GOOD
41+
printf(any_random_function("%d arguments\n"), argc-1); // BAD
4242

4343
// Even though `_` is mapped to `some_random_function` above,
4444
// the following call should not be flagged.
4545
printf(_(any_random_function("%d arguments\n")),
46-
argc-1); // ok
46+
argc-1); // GOOD
4747

4848
return 0;
4949
}

cpp/ql/test/query-tests/Likely Bugs/Format/NonConstantFormat/nested.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ extern "C" int snprintf ( char * s, int n, const char * format, ... );
1818
struct A {
1919
void do_print(const char *fmt0) {
2020
char buf[32];
21-
snprintf(buf, 32, fmt0); // BAD [FALSE POSITIVE]
21+
snprintf(buf, 32, fmt0); // GOOD [FALSE POSITIVE]
2222
}
2323
};
2424

@@ -39,7 +39,7 @@ struct C {
3939

4040
void foo(void) {
4141
C c;
42-
c.do_some_printing(c.ext_fmt_str()); // GOOD [NOT DETECTED]
42+
c.do_some_printing(c.ext_fmt_str()); // BAD [NOT DETECTED]
4343
}
4444

4545
struct some_class {
@@ -54,7 +54,7 @@ struct debug_ {
5454
va_list args)
5555
{
5656
char str[4096];
57-
int length = _vsnprintf_s(str, sizeof(str), 0, fmt, args);
57+
int length = _vsnprintf_s(str, sizeof(str), 0, fmt, args); // GOOD
5858
if (length > 0)
5959
{
6060
return 0;

cpp/ql/test/query-tests/Likely Bugs/Format/NonConstantFormat/test.cpp

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -42,83 +42,83 @@ const char *const_wash(char *str) {
4242

4343
int main(int argc, char **argv) {
4444
const char *message = messages[2];
45-
printf(choose_message(argc - 1), argc - 1); // OK
46-
printf(messages[1]); // OK
47-
printf(message); // OK
48-
printf(make_message(argc - 1)); // NOT OK
49-
printf("Hello, World\n"); // OK
50-
printf(_("Hello, World\n")); // OK
45+
printf(choose_message(argc - 1), argc - 1); // GOOD
46+
printf(messages[1]); // GOOD
47+
printf(message); // GOOD
48+
printf(make_message(argc - 1)); // BAD
49+
printf("Hello, World\n"); // GOOD
50+
printf(_("Hello, World\n")); // GOOD
5151
{
5252
char hello[] = "hello, World\n";
5353
hello[0] = 'H';
54-
printf(hello); // NOT OK
55-
printf(_(hello)); // OK
56-
printf(gettext(hello)); // OK
57-
printf(const_wash(hello)); // NOT OK
58-
printf((hello + 1) + 1); // NOT OK
59-
printf(+hello); // NOT OK
60-
printf(*&hello); // NOT OK
61-
printf(&*hello); // NOT OK
62-
printf((char*)(void*)+(hello+1) + 1); // NOT OK
54+
printf(hello); // BAD
55+
printf(_(hello)); // GOOD
56+
printf(gettext(hello)); // GOOD
57+
printf(const_wash(hello)); // BAD
58+
printf((hello + 1) + 1); // BAD
59+
printf(+hello); // BAD
60+
printf(*&hello); // BAD
61+
printf(&*hello); // BAD
62+
printf((char*)(void*)+(hello+1) + 1); // BAD
6363
}
64-
printf(("Hello, World\n" + 1) + 1); // NOT OK
64+
printf(("Hello, World\n" + 1) + 1); // BAD
6565
{
6666
const char *hello = "Hello, World\n";
67-
printf(hello + 1); // NOT OK
68-
printf(hello); // OK
67+
printf(hello + 1); // BAD
68+
printf(hello); // GOOD
6969
}
7070
{
7171
const char *hello = "Hello, World\n";
7272
hello += 1;
73-
printf(hello); // NOT OK
73+
printf(hello); // BAD
7474
}
7575
{
7676
// Same as above block but using "x = x + 1" syntax
7777
const char *hello = "Hello, World\n";
7878
hello = hello + 1;
79-
printf(hello); // NOT OK
79+
printf(hello); // BAD
8080
}
8181
{
8282
// Same as above block but using "x++" syntax
8383
const char *hello = "Hello, World\n";
8484
hello++;
85-
printf(hello); // NOT OK
85+
printf(hello); // BAD
8686
}
8787
{
8888
// Same as above block but using "++x" as subexpression
8989
const char *hello = "Hello, World\n";
90-
printf(++hello); // NOT OK
90+
printf(++hello); // BAD
9191
}
9292
{
9393
// Same as above block but through a pointer
9494
const char *hello = "Hello, World\n";
9595
const char **p = &hello;
9696
(*p)++;
97-
printf(hello); // NOT OK [NOT DETECTED]
97+
printf(hello); // BAD [NOT DETECTED]
9898
}
9999
{
100100
// Same as above block but through a C++ reference
101101
const char *hello = "Hello, World\n";
102102
const char *&p = hello;
103103
p++;
104-
printf(hello); // NOT OK [NOT DETECTED]
104+
printf(hello); // BAD [NOT DETECTED]
105105
}
106106
if (gettext_debug) {
107-
printf(new char[100]); // NOT OK
107+
printf(new char[100]); // BAD
108108
}
109109
{
110110
const char *hello = "Hello, World\n";
111111
const char *const *p = &hello; // harmless reference to const pointer
112-
printf(hello); // OK
112+
printf(hello); // GOOD
113113
hello++; // modification comes after use and so does no harm
114114
}
115-
printf(argc > 2 ? "More than one\n" : _("Only one\n")); // OK
115+
printf(argc > 2 ? "More than one\n" : _("Only one\n")); // GOOD
116116

117117
// This following is OK since a const literal is passed to const_wash()
118118
// and the taint tracker detects this.
119119
//
120120
//
121-
printf(const_wash("Hello, World\n")); // OK
121+
printf(const_wash("Hello, World\n")); // GOOD
122122
}
123123

124124
const char *simple_func(const char *str) {
@@ -127,9 +127,9 @@ const char *simple_func(const char *str) {
127127

128128
void another_func(void) {
129129
const char *message = messages[2];
130-
printf(simple_func("Hello, World\n")); // OK
131-
printf(messages[1]); // OK
132-
printf(message); // OK
133-
printf("Hello, World\n"); // OK
134-
printf(gettext("Hello, World\n")); // OK
130+
printf(simple_func("Hello, World\n")); // GOOD
131+
printf(messages[1]); // GOOD
132+
printf(message); // GOOD
133+
printf("Hello, World\n"); // GOOD
134+
printf(gettext("Hello, World\n")); // GOOD
135135
}

0 commit comments

Comments
 (0)