Skip to content

Commit 454ba4e

Browse files
authored
Merge pull request #562 from knewbury01/knewbury01/fix-82
A8-4-7: fix type size rounding error
2 parents 795f67c + b174b09 commit 454ba4e

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
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

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ 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+
int minWordsRequiredToRepresentBytes(int bytes) { result = (1.0 * bytes / wordSize()).ceil() }
1616

1717
class TriviallyCopyableSmallType extends Type {
1818
TriviallyCopyableSmallType() {
1919
isTriviallyCopyableType(this) and
20-
exists(int size | size = this.getSize() | bytesToWords(size) <= 2)
20+
exists(int size | size = this.getSize() | minWordsRequiredToRepresentBytes(size) <= 2)
2121
}
2222
}

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)