Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
frama-c
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pub
frama-c
Commits
b2e0f841
Commit
b2e0f841
authored
5 years ago
by
David Bühler
Browse files
Options
Downloads
Patches
Plain Diff
[Eva] Documents new option -warn-invalid-pointer and -warn-pointer-downcast.
parent
90fddb3d
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
doc/value/examples/alarms/pointer_arith.c
+5
-0
5 additions, 0 deletions
doc/value/examples/alarms/pointer_arith.c
doc/value/examples/alarms/pointer_conversion.c
+7
-0
7 additions, 0 deletions
doc/value/examples/alarms/pointer_conversion.c
doc/value/main.tex
+58
-0
58 additions, 0 deletions
doc/value/main.tex
with
70 additions
and
0 deletions
doc/value/examples/alarms/pointer_arith.c
0 → 100644
+
5
−
0
View file @
b2e0f841
void
main
()
{
int
x
,
*
p
=
&
x
;
p
++
;
p
++
;
}
This diff is collapsed.
Click to expand it.
doc/value/examples/alarms/pointer_conversion.c
0 → 100644
+
7
−
0
View file @
b2e0f841
#include
<stdint.h>
void
main
()
{
char
c
;
uintptr_t
a
=
&
c
;
char
*
p
=
(
char
*
)
(
a
+
1
);
char
*
q
=
(
char
*
)
(
a
+
2
);
}
This diff is collapsed.
Click to expand it.
doc/value/main.tex
+
58
−
0
View file @
b2e0f841
...
...
@@ -1460,6 +1460,58 @@ to the attitude described in \ref{norme_pratique}. An option
to warn about these lines could happen if there was demand for
this feature.
\subsubsection
{
Invalid pointer arithmetic
}
By default,
\Eva
{}
does
\emph
{
not
}
emit alarms on invalid pointer arithmetic:
alarms are only emitted when an invalid pointer is dereferenced or wrongly used
in a comparison, not at the creation of such pointers.
However, if the
\lstinline
|-warn-invalid-pointer| option is enabled,
\Eva
{}
emits an alarm when an operation may create a pointer that does
not point inside an object or one past an object,
even if this pointer is not used afterward.
This may happen on:
\begin{itemize}
\item
addition (or subtraction) of an integer from a pointer, when the analysis
is unable to prove that the resulting pointer points inside, or one past,
the same object pointed to by the initial pointer.
In this case, the emitted alarm reports a possible undefined behavior.
\item
conversion of an integer into a pointer. Except for the constant~0,
such a conversion is always an implementation-defined behavior
according to the ISO C99 standard. However, a footnote also explains that
conversion between pointers and integers is ``
\emph
{
intended to
be consistent with the addressing structure of the execution environment
}
''.
This is why Eva also also authorizes conversion of integers:
\begin{itemize}
\item
in the range of valid absolute addresses
(according to
\texttt
{
absolute-valid-range
}
)
\item
computed from the address of an object
\lstinline
|o| such that the
resulting pointer points inside or one past the object
\lstinline
|o|.
\end{itemize}
In all other cases, an alarm is emitted, which reports the possible
implementation-defined behavior mentionned above.
\end{itemize}
In the example below, the first increment of the pointer
\lstinline
|p| is valid,
although the resulting pointer should not be dereferenced. The second increment
leads to an invalid alarm when option
\lstinline
|-warn-invalid-pointer| is on.
\listinginput
{
1
}{
examples/alarms/pointer
_
arith.c
}
\begin{logs}
[eva:alarm] pointer
_
arith.c:4: Warning:
invalid pointer creation. assert
\object
_
pointer(p + 1);
\end{logs}
In the same way, in the example below, the first conversion at line~5
does not generate an alarm, but the second conversion leads to an invalid alarm
with option
\lstinline
|-warn-invalid-pointer|.
\listinginput
{
1
}{
examples/alarms/pointer
_
conversion.c
}
\begin{logs}
[eva:alarm] pointer
_
arith.c:6: Warning:
invalid pointer creation. assert
\object
_
pointer((char *)(a + 2));
\end{logs}
\subsubsection
{
Division by zero
}
When dividing by an expression that the analysis
...
...
@@ -1540,6 +1592,12 @@ defined semantics according to the ISO/IEC 9899:1999 standard.
If one wishes to signal and prevent such unsigned overflows,
option
\verb
+
-warn-unsigned-overflow
+
can be used.
By default, Eva emits alarms for downcasts of pointer values to (signed
or unsigned) integer types. Such downcasts are indeed undefined behavior
according to section 6.3.2.3, §6 of the ISO/IE 9899:1999 standard.
However, option
\lstinline
|-no-warn-pointer-downcast| can be used to disable
these alarms.
Finally, by default, no alarm is emitted for downcasts to signed or unsigned
integers. In the signed case, the least significant bits
of the original value are used, and are interpreted according
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment