...
"It
...
is
...
undefined
...
what
...
will
...
happen
...
if
...
a
...
pointer
...
of
...
some
...
type
...
is
...
converted
...
to
...
void*,
...
and
...
then
...
the
...
void
...
*
...
pointer
...
is
...
converted
...
to
...
a
...
type
...
with
...
a
...
stricter
...
alignment
...
requirement"
...
-C99
...
rationaleV5.10.pdf
...
Non-compliant
...
code
...
example
Code Block | ||||
---|---|---|---|---|
| =
| |||
} char *char_ptr = "example"; int *int_ptr; int *Function(void *v_pointer){ return pointer; } P2 = Function(pointer); {code} |
Pointer
...
might
...
be
...
aligned
...
on
...
even
...
boundary,
...
once
...
it
...
is
...
cast
...
to
...
an
...
int
...
some
...
architectures
...
will
...
require
...
it
...
to
...
be
...
on
...
4
...
byte
...
boundaries.
...
Pointers
...
are
...
often
...
cast
...
because
...
a
...
void
...
*
...
cannot
...
be
...
dereferenced.
...
Careless
...
coding
...
can
...
result
...
in
...
an
...
arbitrary
...
pointer
...
type
...
being
...
used
...
irregardless
...
of
...
its
...
alignment.
...
List
...
of
...
common
...
alignments
...
for
...
Microsoft,
...
Borland
...
and
...
GNU
...
compilers
...
to
...
x86
...
char
...
-1
...
byte
...
aligned
...
short
...
-2
...
byte
...
aligned
...
int
...
-4
...
byte
...
aligned
...
float
...
-
...
4
...
byte
...
aligned
...
double
...
-
...
8
...
byte
...
on
...
windows,
...
4
...
byte
...
on
...
linux
...
Compliant
...
code
...
suggestions
Code Block | ||||
---|---|---|---|---|
| =
| |||
} -make specific functions (avoid use of void*) -always use strictest alignment type for arbitary pointers {code} h2. Risk Assessment Programs can crash || Rule || Severity || Likelihood || Remediation Cost || Priority || Level || | DRAFT | *1* (low) | *2* (probable) | *2* (medium) | {color:green}P4{color} | {color:green}L3{color} | h2. References {list} \*Bryant, Randal and O'Hallaron, David. [2003] 2001 Computer Systems: A Programmer's Perspective. Prentice Hall. ISBN |
Risk Assessment
Programs can crash
Rule | Severity | Likelihood | Remediation Cost | Priority | Level |
---|---|---|---|---|---|
DRAFT | 1 (low) | 2 (probable) | 2 (medium) | P4 | L3 |
References
- Bryant, Randal and O'Hallaron, David. 2003 2001 Computer Systems: A Programmer's Perspective. Prentice Hall. ISBN 0-13-034074-X.
...
...