Skip to content

Commit ac277ad

Browse files
committed
CPP: Fix %I length specifier.
1 parent 98c3e14 commit ac277ad

File tree

5 files changed

+6
-10
lines changed

5 files changed

+6
-10
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ class FormatLiteral extends Literal {
578578
or ((len="z" or len="Z")
579579
and (result = this.getSize_t() or result = this.getSsize_t()))
580580
or (len="t" and result = this.getPtrdiff_t())
581-
or (len="I" and result instanceof IntType)
581+
or (len="I" and (result = this.getSize_t() or result = this.getPtrdiff_t()))
582582
or (len="I32" and exists(MicrosoftInt32Type t |
583583
t.getUnsigned() = result.(IntegralType).getUnsigned()
584584
))
@@ -604,7 +604,7 @@ class FormatLiteral extends Literal {
604604
or ((len="z" or len="Z")
605605
and (result = this.getSize_t() or result = this.getSsize_t()))
606606
or (len="t" and result = this.getPtrdiff_t())
607-
or (len="I" and result instanceof IntType)
607+
or (len="I" and (result = this.getSize_t() or result = this.getPtrdiff_t()))
608608
or (len="I32" and exists(MicrosoftInt32Type t |
609609
t.getUnsigned() = result.(IntegralType).getUnsigned()
610610
))

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
| printf1.h:130:18:130:18 | 0 | This argument should be of type 'void *' but is of type 'int' |
2222
| printf1.h:153:18:153:18 | c | This argument should be of type '__wchar_t *' but is of type 'char *' |
2323
| printf1.h:156:18:156:19 | wc | This argument should be of type 'char *' but is of type '__wchar_t *' |
24-
| printf1.h:174:19:174:21 | pdt | This argument should be of type 'int' but is of type 'long long' |
25-
| printf1.h:175:19:175:20 | sz | This argument should be of type 'unsigned int' but is of type 'unsigned long long' |
2624
| printf1.h:181:21:181:22 | ll | This argument should be of type 'int' but is of type 'long long' |
2725
| printf1.h:182:21:182:23 | ull | This argument should be of type 'unsigned int' but is of type 'unsigned long long' |
2826
| printf1.h:185:21:185:23 | i64 | This argument should be of type 'int' but is of type 'long long' |

cpp/ql/test/query-tests/Likely Bugs/Format/WrongTypeFormatArguments/Microsoft/printf1.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ void fun4()
171171
__int64 i64;
172172
unsigned __int64 u64;
173173

174-
printf("%Ii\n", pdt); // GOOD [FALSE POSITIVE]
175-
printf("%Iu\n", sz); // GOOD [FALSE POSITIVE]
174+
printf("%Ii\n", pdt); // GOOD
175+
printf("%Iu\n", sz); // GOOD
176176

177177
printf("%I32i\n", i); // GOOD
178178
printf("%I32u\n", ui); // GOOD

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
| printf1.h:75:19:75:28 | sizeof(<expr>) | This argument should be of type 'ssize_t' but is of type 'unsigned long long' |
1818
| printf1.h:84:23:84:35 | ... - ... | This argument should be of type 'ssize_t' but is of type 'long long' |
1919
| printf1.h:130:18:130:18 | 0 | This argument should be of type 'void *' but is of type 'int' |
20-
| printf1.h:148:19:148:21 | pdt | This argument should be of type 'int' but is of type 'long long' |
21-
| printf1.h:149:19:149:20 | sz | This argument should be of type 'unsigned int' but is of type 'unsigned long long' |
2220
| printf1.h:155:21:155:22 | ll | This argument should be of type 'int' but is of type 'long long' |
2321
| printf1.h:156:21:156:23 | ull | This argument should be of type 'unsigned int' but is of type 'unsigned long long' |
2422
| printf1.h:159:21:159:23 | i64 | This argument should be of type 'int' but is of type 'long long' |

cpp/ql/test/query-tests/Likely Bugs/Format/WrongTypeFormatArguments/Microsoft_no_wchar/printf1.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ void fun4()
145145
__int64 i64;
146146
unsigned __int64 u64;
147147

148-
printf("%Ii\n", pdt); // GOOD [FALSE POSITIVE]
149-
printf("%Iu\n", sz); // GOOD [FALSE POSITIVE]
148+
printf("%Ii\n", pdt); // GOOD
149+
printf("%Iu\n", sz); // GOOD
150150

151151
printf("%I32i\n", i); // GOOD
152152
printf("%I32u\n", ui); // GOOD

0 commit comments

Comments
 (0)