|
6 | 6 | * arguments on a stack may lead to unpredictable function behavior. |
7 | 7 | * @kind problem |
8 | 8 | * @problem.severity warning |
9 | | - * @precision very-high |
| 9 | + * @precision high |
10 | 10 | * @id cpp/mistyped-function-arguments |
11 | 11 | * @tags correctness |
12 | 12 | * maintainability |
13 | 13 | */ |
14 | 14 |
|
15 | 15 | import cpp |
16 | 16 |
|
17 | | -pragma[inline] |
18 | | -int sizeofInt() { result = any(IntType pt).getSize() } |
19 | | - |
20 | 17 | pragma[inline] |
21 | 18 | predicate pointerArgTypeMayBeUsed(Type arg, Type parm) { |
22 | 19 | arg = parm |
@@ -47,39 +44,16 @@ pragma[inline] |
47 | 44 | predicate argTypeMayBeUsed(Type arg, Type parm) { |
48 | 45 | arg = parm |
49 | 46 | or |
50 | | - // float will be promoted to double, and so it should correspond |
51 | | - // to the prototype |
52 | | - arg instanceof FloatType and parm instanceof DoubleType |
53 | | - or |
54 | | - // integral types are promoted "up to" (unsigned) int, but not long long. |
| 47 | + // we treat signed and unsigned versions of integer types as compatible. |
55 | 48 | arg instanceof IntegralType and |
56 | | - parm instanceof IntegralType and |
57 | | - arg.getSize() <= sizeofInt() and |
58 | | - parm.getSize() <= sizeofInt() |
| 49 | + parm instanceof IntegralType |
59 | 50 | or |
60 | | - /* |
61 | | - * // we allow interoperability between long long and pointer |
62 | | - * arg.getSize() = parm.getSize() and |
63 | | - * ( |
64 | | - * (arg instanceof IntegralType and parm instanceof PointerType) |
65 | | - * or |
66 | | - * (arg instanceof PointerType and parm instanceof IntegralType) |
67 | | - * ) |
68 | | - * or |
69 | | - */ |
70 | | - |
71 | 51 | // pointers to compatible types |
72 | 52 | pointerArgTypeMayBeUsed(arg.(PointerType).getBaseType().getUnspecifiedType(), |
73 | 53 | parm.(PointerType).getBaseType().getUnspecifiedType()) |
74 | 54 | or |
75 | 55 | pointerArgTypeMayBeUsed(arg.(PointerType).getBaseType().getUnspecifiedType(), |
76 | 56 | parm.(ArrayType).getBaseType().getUnspecifiedType()) |
77 | | - or |
78 | | - pointerArgTypeMayBeUsed(arg.(ArrayType).getBaseType().getUnspecifiedType(), |
79 | | - parm.(PointerType).getBaseType().getUnspecifiedType()) |
80 | | - or |
81 | | - pointerArgTypeMayBeUsed(arg.(ArrayType).getBaseType().getUnspecifiedType(), |
82 | | - parm.(ArrayType).getBaseType().getUnspecifiedType()) |
83 | 57 | } |
84 | 58 |
|
85 | 59 | // This predicate doesn't necessarily have to exist, but if it does exist |
|
0 commit comments