...
This noncompliant code uses the assert()
macro to assert a property concerning a memory-mapped structure that is essential for the code to behave correctly.:
Code Block | ||||
---|---|---|---|---|
| ||||
struct timer { unsigned char MODE; unsigned int DATA; unsigned int COUNT; }; int func(void) { assert(sizeof(struct timer) == sizeof(unsigned char) + sizeof(unsigned int) + sizeof(unsigned int)); } |
...
This portable compliant solution uses static_assert
.:
Code Block | ||||
---|---|---|---|---|
| ||||
struct timer { unsigned char MODE; unsigned int DATA; unsigned int COUNT; }; static_assert(sizeof(struct timer) == sizeof(unsigned char) + sizeof(unsigned int) + sizeof(unsigned int), "Structure must not have any padding"); |
...
Tool | Version | Checker | Description | ||||||
---|---|---|---|---|---|---|---|---|---|
Compass/ROSE |
|
| Could detect violations of this rule merely by looking for calls to | ||||||
ECLAIR |
| macrcall | Fully implemented. | ||||||
| 44 S | Fully implemented. | |||||||
PRQA QA-C |
| 2741 2742 | Partially implemented. |
Related Vulnerabilities
Search for vulnerabilities resulting from the violation of this rule on the CERT website.
...