Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ae55b7b

Browse files
committed
[CPP-370] Add new test file for testing procedurally nested format
argument violations.
1 parent f19f48d commit ae55b7b

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

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

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

Lines changed: 3 additions & 4 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);
21+
snprintf(buf, 32, fmt0); // BAD [should detect at top-most call]
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());
42+
c.do_some_printing(c.ext_fmt_str()); // BAD [not detected at this location]
4343
}
4444

4545
struct some_class {
@@ -54,7 +54,6 @@ struct debug_ {
5454
va_list args)
5555
{
5656
char str[4096];
57-
//int length = printf(fmt, args);
5857
int length = _vsnprintf_s(str, sizeof(str), 0, fmt, args);
5958
if (length > 0)
6059
{
@@ -77,5 +76,5 @@ void diagnostic(const char *fmt, ...)
7776
}
7877

7978
void bar(void) {
80-
diagnostic (some_instance->get_fmt());
79+
diagnostic (some_instance->get_fmt()); // GOOD
8180
}

0 commit comments

Comments
 (0)