Skip to content

Commit 8198b96

Browse files
committed
C++: Add test cases.
1 parent 540af78 commit 8198b96

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@
1818
| test.cpp:87:12:87:16 | hello | The format string argument to printf should be constant to prevent security issues and other potential errors. |
1919
| test.cpp:92:12:92:18 | ++ ... | The format string argument to printf should be constant to prevent security issues and other potential errors. |
2020
| test.cpp:109:12:109:24 | new[] | The format string argument to printf should be constant to prevent security issues and other potential errors. |
21+
| test.cpp:129:20:129:26 | access to array | The format string argument to sprintf should be constant to prevent security issues and other potential errors. |

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ extern "C" int printf(const char *fmt, ...);
22
extern "C" int sprintf(char *buf, const char *fmt, ...);
33
extern "C" char *gettext (const char *);
44

5-
5+
#define MYSPRINTF sprintf
66

77
bool gettext_debug = false;
88

@@ -122,12 +122,12 @@ int main(int argc, char **argv) {
122122
//
123123
printf(const_wash("Hello, World\n")); // GOOD
124124

125+
{
126+
char buffer[1024];
125127

126-
127-
128-
129-
130-
128+
MYSPRINTF(buffer, "constant"); // GOOD
129+
MYSPRINTF(buffer, argv[0]); // BAD
130+
}
131131
}
132132

133133
const char *simple_func(const char *str) {

0 commit comments

Comments
 (0)