...
| Code Block | ||||
|---|---|---|---|---|
| ||||
#include <assert.h>
void func(void) {
char c = 'x';
int *ip = (int *)&c; /* This can lose information. */
char *cp = (char *)ip;
assert(cp == &c); /* Will fail on some conforming implementations */
/* ... */
} |
...
| Code Block | ||||
|---|---|---|---|---|
| ||||
#include <assert.h>
void func(void) {
char c = 'x';
int *ip = (int *)&c; /* This can lose information. */
char *cp = (char *)ip;
assert(cp == &c); /* Will fail on some conforming implementations */
/* ... */
} |
...
| Code Block | ||||
|---|---|---|---|---|
| ||||
#include <stdalign.h> /* For alignas() */
#include <assert.h>
void func(void) {
alignas(int) char c = 'x'; /* Align c to the alignment of an int */
int *ip = (int *)&c;
char *cp = (char *)ip;
assert(cp == &c); /* Both cp and &c point to equally aligned objects. */
/* ... */
} |
Risk Assessment
...
Rule | Severity | Likelihood | Remediation Cost | Priority | Level |
|---|---|---|---|---|---|
EXP36-C | lowLow | probableProbable | mediumMedium | P4 | L3 |
Automated Detection
Tool | Version | Checker | Description | ||||||
|---|---|---|---|---|---|---|---|---|---|
| Compass/ROSE | Can detect violations of this rule. However, it does not flag explicit casts to | ||||||||
| CC2.EXP36 | Fully implemented | |||||||
| EDG | |||||||||
| GCC |
| Can detect some violations of this rule when the | |||||||
| 94 S | Fully implemented | |||||||
| PRQA QA-C |
| 3305 | Fully implemented |
...