Skip to content

Commit 0d030d2

Browse files
committed
C++: Fix FormatLiteral.getMaxConvertedLength bug.
1 parent 06e86ac commit 0d030d2

File tree

2 files changed

+26
-26
lines changed

2 files changed

+26
-26
lines changed

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

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,12 +1125,12 @@ class FormatLiteral extends Literal {
11251125
exists(int dot, int afterdot |
11261126
(if this.getPrecision(n) = 0 then dot = 0 else dot = 1) and
11271127
(
1128-
(
1129-
if this.hasExplicitPrecision(n)
1130-
then afterdot = this.getPrecision(n)
1131-
else not this.hasImplicitPrecision(n)
1132-
) and
1133-
afterdot = 6
1128+
if this.hasExplicitPrecision(n)
1129+
then afterdot = this.getPrecision(n)
1130+
else (
1131+
not this.hasImplicitPrecision(n) and
1132+
afterdot = 6
1133+
)
11341134
) and
11351135
len = 1 + 309 + dot + afterdot
11361136
) and
@@ -1140,12 +1140,12 @@ class FormatLiteral extends Literal {
11401140
exists(int dot, int afterdot |
11411141
(if this.getPrecision(n) = 0 then dot = 0 else dot = 1) and
11421142
(
1143-
(
1144-
if this.hasExplicitPrecision(n)
1145-
then afterdot = this.getPrecision(n)
1146-
else not this.hasImplicitPrecision(n)
1147-
) and
1148-
afterdot = 6
1143+
if this.hasExplicitPrecision(n)
1144+
then afterdot = this.getPrecision(n)
1145+
else (
1146+
not this.hasImplicitPrecision(n) and
1147+
afterdot = 6
1148+
)
11491149
) and
11501150
len = 1 + 1 + dot + afterdot + 1 + 1 + 3
11511151
) and
@@ -1155,12 +1155,12 @@ class FormatLiteral extends Literal {
11551155
exists(int dot, int afterdot |
11561156
(if this.getPrecision(n) = 0 then dot = 0 else dot = 1) and
11571157
(
1158-
(
1159-
if this.hasExplicitPrecision(n)
1160-
then afterdot = this.getPrecision(n)
1161-
else not this.hasImplicitPrecision(n)
1162-
) and
1163-
afterdot = 6
1158+
if this.hasExplicitPrecision(n)
1159+
then afterdot = this.getPrecision(n)
1160+
else (
1161+
not this.hasImplicitPrecision(n) and
1162+
afterdot = 6
1163+
)
11641164
) and
11651165
// note: this could be displayed in the style %e or %f;
11661166
// however %f is only used when 'P > X >= -4'

cpp/ql/test/library-tests/printf/formatLiteral/formatLiteral.expected

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
| test.c:39:9:39:12 | %o | 12 |
2121
| test.c:40:9:40:13 | %#o | 13 |
2222
| test.c:43:9:43:12 | %f | 318 |
23-
| test.c:44:9:44:14 | %.2f | |
23+
| test.c:44:9:44:14 | %.2f | 314 |
2424
| test.c:45:9:45:12 | %e | 15 |
2525
| test.c:59:10:59:14 | %Ii | 12 |
2626
| test.c:66:10:66:14 | %zu | 21 |
@@ -37,17 +37,17 @@
3737
| test.c:101:10:101:15 | %%%% | 3 |
3838
| test.c:102:10:102:15 | %%%f | 319 |
3939
| test.c:103:10:103:17 | %%%%%f | 320 |
40-
| test.c:104:10:104:18 | %4.2f%% | |
40+
| test.c:104:10:104:18 | %4.2f%% | 315 |
4141
| test.c:105:10:105:17 | %%%f%% | 320 |
4242
| test.c:112:10:112:13 | %f | 318 |
43-
| test.c:113:10:113:15 | %.1f | |
43+
| test.c:113:10:113:15 | %.1f | 313 |
4444
| test.c:114:10:114:14 | %1f | 318 |
45-
| test.c:115:10:115:16 | %1.1f | |
45+
| test.c:115:10:115:16 | %1.1f | 313 |
4646
| test.c:116:10:116:13 | %e | 15 |
47-
| test.c:117:10:117:15 | %.2e | |
47+
| test.c:117:10:117:15 | %.2e | 11 |
4848
| test.c:118:10:118:14 | %3e | 15 |
49-
| test.c:119:10:119:16 | %3.2e | |
49+
| test.c:119:10:119:16 | %3.2e | 11 |
5050
| test.c:120:10:120:13 | %g | 15 |
51-
| test.c:121:10:121:15 | %.1g | |
51+
| test.c:121:10:121:15 | %.1g | 10 |
5252
| test.c:122:10:122:14 | %4g | 15 |
53-
| test.c:123:10:123:16 | %4.1g | |
53+
| test.c:123:10:123:16 | %4.1g | 10 |

0 commit comments

Comments
 (0)