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

Skip to content

Commit 69f87d8

Browse files
committed
CPP: Fix ODASA-3654.
1 parent bd13823 commit 69f87d8

3 files changed

Lines changed: 4 additions & 5 deletions

File tree

cpp/ql/src/semmle/code/cpp/commons/Printf.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,11 @@ class FormatLiteral extends Literal {
256256
}
257257

258258
/**
259-
* Gets the format string, with '%%' replaced by '_' (to avoid processing
260-
* '%%' as a format specifier).
259+
* Gets the format string, with '%%' adn '%@' replaced by '_' (to avoid processing
260+
* them as format specifiers).
261261
*/
262262
string getFormat() {
263-
result = this.getValue().replaceAll("%%", "_")
263+
result = this.getValue().replaceAll("%%", "_").replaceAll("%@", "_")
264264
}
265265

266266
/**

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,3 @@
66
| test.c:15:2:15:7 | call to printf | Format expects 3 arguments but given 2 |
77
| test.c:19:2:19:7 | call to printf | Format expects 2 arguments but given 1 |
88
| test.c:29:3:29:8 | call to printf | Format expects 2 arguments but given 1 |
9-
| test.c:44:2:44:7 | call to printf | Format expects 3 arguments but given 2 |

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,5 @@ void test(int i, const char *str)
4141
printf("%2$.*4$f", num, 0, precision); // BAD (too few format arguments) [INCORRECT MESSAGE]
4242
}
4343

44-
printf("%@ %i %i", 1, 2); // GOOD [FALSE POSITIVE]
44+
printf("%@ %i %i", 1, 2); // GOOD
4545
}

0 commit comments

Comments
 (0)