Skip to content

Commit cc72321

Browse files
authored
Merge branch 'main' into rp/pre32-c-650
2 parents 490a968 + 95f7a1a commit cc72321

File tree

797 files changed

+10189
-1566
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

797 files changed

+10189
-1566
lines changed

c/cert/src/rules/INT30-C/UnsignedIntegerOperationsWrapAround.ql

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,11 @@
1515

1616
import cpp
1717
import codingstandards.c.cert
18-
import codingstandards.cpp.Overflow
19-
import semmle.code.cpp.controlflow.Guards
20-
import semmle.code.cpp.valuenumbering.GlobalValueNumbering
18+
import codingstandards.cpp.rules.unsignedoperationwithconstantoperandswraps.UnsignedOperationWithConstantOperandsWraps
2119

22-
from InterestingOverflowingOperation op
23-
where
24-
not isExcluded(op, IntegerOverflowPackage::unsignedIntegerOperationsWrapAroundQuery()) and
25-
op.getType().getUnderlyingType().(IntegralType).isUnsigned() and
26-
// Not within a guard condition
27-
not exists(GuardCondition gc | gc.getAChild*() = op) and
28-
// Not guarded by a check, where the check is not an invalid overflow check
29-
not op.hasValidPreCheck() and
30-
// Is not checked after the operation
31-
not op.hasValidPostCheck() and
32-
// Permitted by exception 3
33-
not op instanceof LShiftExpr and
34-
// Permitted by exception 2 - zero case is handled in separate query
35-
not op instanceof DivExpr and
36-
not op instanceof RemExpr
37-
select op,
38-
"Operation " + op.getOperator() + " of type " + op.getType().getUnderlyingType() + " may wrap."
20+
class UnsignedIntegerOperationsWrapAroundQuery extends UnsignedOperationWithConstantOperandsWrapsSharedQuery
21+
{
22+
UnsignedIntegerOperationsWrapAroundQuery() {
23+
this = IntegerOverflowPackage::unsignedIntegerOperationsWrapAroundQuery()
24+
}
25+
}

c/cert/test/rules/INT30-C/UnsignedIntegerOperationsWrapAround.expected

Lines changed: 0 additions & 4 deletions
This file was deleted.

c/cert/test/rules/INT30-C/UnsignedIntegerOperationsWrapAround.qlref

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
c/common/test/rules/unsignedoperationwithconstantoperandswraps/UnsignedOperationWithConstantOperandsWraps.ql
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
cpp/common/test/rules/donotuserandforgeneratingpseudorandomnumbers/DoNotUseRandForGeneratingPseudorandomNumbers.ql
1+
c/common/test/rules/donotuserandforgeneratingpseudorandomnumbers/DoNotUseRandForGeneratingPseudorandomNumbers.ql

c/common/src/codingstandards/c/Literals.qll

Lines changed: 0 additions & 4 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
| test.c:4:1:4:41 | #define BAD_MACRO_WITH_ARG(x) (x) + wow ## x | Macro BAD_MACRO_WITH_ARG contains use of parameter x used in multiple contexts. |
2-
| test.c:5:1:5:48 | #define BAD_MACRO_WITH_ARG_TWO(x,y) (x) + wow ## x | Macro BAD_MACRO_WITH_ARG_TWO contains use of parameter x used in multiple contexts. |
1+
| test.c:5:1:5:41 | #define BAD_MACRO_WITH_ARG(x) (x) + wow ## x | Macro BAD_MACRO_WITH_ARG contains use of parameter x used in multiple contexts. |
2+
| test.c:6:1:6:48 | #define BAD_MACRO_WITH_ARG_TWO(x,y) (x) + wow ## x | Macro BAD_MACRO_WITH_ARG_TWO contains use of parameter x used in multiple contexts. |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// GENERATED FILE - DO NOT MODIFY
2+
import codingstandards.cpp.rules.amixedusemacroargumentsubjecttoexpansion.AMixedUseMacroArgumentSubjectToExpansion
3+
4+
class TestFileQuery extends AMixedUseMacroArgumentSubjectToExpansionSharedQuery, TestQuery { }
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// NOTICE: THE TEST CASES BELOW ARE ALSO INCLUDED IN THE C++ TEST CASE AND
2+
// CHANGES SHOULD BE REFLECTED THERE AS WELL.
3+
#define GOOD_MACRO_WITH_ARG(X) ((X)*X##_scale) // COMPLIANT
4+
#define MACRO 1
5+
#define BAD_MACRO_WITH_ARG(x) (x) + wow##x // NON_COMPLIANT
6+
#define BAD_MACRO_WITH_ARG_TWO(x, y) (x) + wow##x // NON_COMPLIANT
7+
#define MACROONE(x) #x // COMPLIANT
8+
#define MACROTWO(x) x *x // COMPLIANT
9+
#define MACROTHREE(x) "##\"\"'" + (x) // COMPLIANT
10+
#define FOO(x) #x MACROONE(x) // COMPLIANT - no further arg expansion
11+
12+
void f() {
13+
14+
int x;
15+
int x_scale;
16+
int y;
17+
int wowMACRO = 0;
18+
19+
y = GOOD_MACRO_WITH_ARG(x);
20+
wowMACRO = BAD_MACRO_WITH_ARG(MACRO);
21+
wowMACRO = BAD_MACRO_WITH_ARG_TWO(MACRO, 1);
22+
char s[] = MACROONE(MACRO);
23+
y = MACROTWO(MACRO);
24+
MACROTHREE(MACRO);
25+
FOO(x);
26+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
| test.c:8:14:8:17 | call to atof | Call to banned function atof. |
2+
| test.c:9:12:9:15 | call to atoi | Call to banned function atoi. |
3+
| test.c:10:13:10:16 | call to atol | Call to banned function atol. |
4+
| test.c:11:18:11:22 | call to atoll | Call to banned function atoll. |

0 commit comments

Comments
 (0)