Skip to content

Commit 75ba9ab

Browse files
committed
A8-4-7: fix type size rounding error
1 parent 795f67c commit 75ba9ab

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- `A8-4-7` - `InParametersForCheapToCopyTypesNotPassedByValue.ql`, `InParametersForCheapToCopyTypesNotPassedByReference.ql`:
2+
- Fixes #89. Accidental floor rounding was applying to type size calculations.

cpp/autosar/src/rules/A8-4-7/TriviallyCopyableSmallType.qll

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ int wordSize() { result = max(VoidPointerType v | | v.getSize()) }
1212
* Converts bytes to words
1313
*/
1414
bindingset[bytes]
15-
int bytesToWords(int bytes) { result = bytes / wordSize() }
15+
float bytesToWords(float bytes) { result = bytes / wordSize() }
1616

1717
class TriviallyCopyableSmallType extends Type {
1818
TriviallyCopyableSmallType() {

cpp/autosar/test/rules/A8-4-7/test.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,14 @@ struct S5 {
6868

6969
void f15(S3 f15a) {} // COMPLIANT
7070
void f17(S4 f17a) {} // NON_COMPLIANT (S4 has a non-trivial destructor)
71-
void f18(S5 f18a) {} // COMPLIANT
71+
void f18(S5 f18a) {} // COMPLIANT
72+
73+
#include <iostream>
74+
class A8_4_7 {
75+
public:
76+
std::array<char, 20UL> values;
77+
};
78+
void fp_reported_in_82(
79+
const A8_4_7 &a847) noexcept { // COMPLIANT - larger than 2 words
80+
std::cout << a847.values[0] << std::endl;
81+
}

0 commit comments

Comments
 (0)