Skip to content

Commit 9a9f794

Browse files
committed
C++: Fix bug for exact powers of 10 and accept test changes.
1 parent 5388491 commit 9a9f794

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ bindingset[f]
279279
private int lengthInBase10(float f) {
280280
f = 0 and result = 1
281281
or
282-
result = f.log10().ceil()
282+
result = f.log10().floor() + 1
283283
}
284284

285285
/**

cpp/ql/test/query-tests/Security/CWE/CWE-242/semmle/tests/OverrunWrite.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,7 @@
99
| tests.cpp:324:3:324:9 | call to sprintf | This 'call to sprintf' operation requires 11 bytes but the destination is only 2 bytes. |
1010
| tests.cpp:327:2:327:8 | call to sprintf | This 'call to sprintf' operation requires 12 bytes but the destination is only 2 bytes. |
1111
| tests.cpp:329:3:329:9 | call to sprintf | This 'call to sprintf' operation requires 12 bytes but the destination is only 2 bytes. |
12+
| tests.cpp:341:2:341:8 | call to sprintf | This 'call to sprintf' operation requires 3 bytes but the destination is only 2 bytes. |
13+
| tests.cpp:343:2:343:8 | call to sprintf | This 'call to sprintf' operation requires 3 bytes but the destination is only 2 bytes. |
1214
| tests.cpp:345:2:345:8 | call to sprintf | This 'call to sprintf' operation requires 11 bytes but the destination is only 2 bytes. |
15+
| tests.cpp:347:2:347:8 | call to sprintf | This 'call to sprintf' operation requires 3 bytes but the destination is only 2 bytes. |

cpp/ql/test/query-tests/Security/CWE/CWE-242/semmle/tests/tests.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,11 +338,11 @@ void test6(unsigned unsigned_value, int value) {
338338
sprintf(buffer, "%u", 5); // GOOD
339339
sprintf(buffer, "%d", 5); // GOOD
340340

341-
sprintf(buffer, "%d", -1); // BAD [NOT DETECTED]
341+
sprintf(buffer, "%d", -1); // BAD
342342
sprintf(buffer, "%d", 9); // GOOD
343-
sprintf(buffer, "%d", 10); // BAD [NOT DETECTED]
343+
sprintf(buffer, "%d", 10); // BAD
344344

345345
sprintf(buffer, "%u", -1); // BAD
346346
sprintf(buffer, "%u", 9); // GOOD
347-
sprintf(buffer, "%u", 10); // BAD [NOT DETECTED]
347+
sprintf(buffer, "%u", 10); // BAD
348348
}

0 commit comments

Comments
 (0)