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
7587f3c0
Commit
7587f3c0
authored
10 years ago
by
Julien Signoles
Browse files
Options
Downloads
Patches
Plain Diff
[csrv'14] improve benchmark 3
parent
88b42328
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/plugins/e-acsl/tests/csrv14/benchmark3.c
+33
-28
33 additions, 28 deletions
src/plugins/e-acsl/tests/csrv14/benchmark3.c
src/plugins/e-acsl/tests/csrv14/benchmark3.solution.c
+37
-45
37 additions, 45 deletions
src/plugins/e-acsl/tests/csrv14/benchmark3.solution.c
with
70 additions
and
73 deletions
src/plugins/e-acsl/tests/csrv14/benchmark3.c
+
33
−
28
View file @
7587f3c0
...
...
@@ -2,21 +2,13 @@
/* instructions */
/* ************************************************************************** */
/*
Detect an out-of-bounds access to arr[LEN] due to the call from main()
quicksort(arr, 0, LEN);
instead of
quicksort(arr, 0, LEN-1);
Here this out-of-bounds access does not provoke a segmentation fault by chance
since it happens to access another array. Moreover, this access may
not provoke a sorting error by chance like in this example where the
accessed element arr[LEN] is equal to the maximal element of the array arr.
Check that each call to the function [quicksort] is performed on an array
correctly allocated for each cell array[i], with left <= i <= right.
*/
/* ************************************************************************** */
#include
<stdio.h>
#define LEN
2048
//
#include<stdio.h>
#define LEN
10000
void
swap
(
int
*
array
,
int
i
,
int
j
)
{
int
tmp
=
array
[
i
];
...
...
@@ -46,28 +38,41 @@ void quicksort(int* array, int left, int right) {
}
}
int
main
(
void
)
{
void
init
(
int
*
arr1
,
int
*
arr2
)
{
int
i
;
int
arr
[
LEN
];
// array to be sorted
int
arr_max
[
LEN
];
// array of maximal elements
// filling arrays
arr
[
0
]
=
0
;
arr
_max
[
0
]
=
9
;
// filling arrays
arr
1
[
0
]
=
0
;
arr
2
[
0
]
=
9
;
for
(
i
=
1
;
i
<
LEN
;
i
++
){
arr
[
i
]
=
(
13
*
arr
[
i
-
1
]
+
i
)
%
10
;
arr
_max
[
i
]
=
9
;
arr
1
[
i
]
=
(
13
*
arr
1
[
i
-
1
]
+
i
)
%
10
;
arr
2
[
i
]
=
9
;
}
}
int
main
(
void
)
{
int
i
;
int
arr
[
LEN
];
// array to be sorted
int
arr_max
[
LEN
];
// array of maximal elements
printf
(
"
\n
Array before quicksort:
\n
"
);
for
(
i
=
0
;
i
<
LEN
;
i
++
)
printf
(
"%d, "
,
arr
[
i
]);
quicksort
(
arr
,
0
,
LEN
);
// error ! must be: quicksort(arr, 0, LEN-1);
init
(
arr
,
arr_max
);
/* printf("\n Array before quicksort:\n"); */
/* for (i=0; i < LEN; i++) */
/* printf("%d, ",arr[i]); */
quicksort
(
arr
,
0
,
LEN
-
1
);
printf
(
"
\n
Array after quicksort:
\n
"
);
for
(
i
=
0
;
i
<
LEN
;
i
++
)
printf
(
"%d, "
,
arr
[
i
]);
/* printf("\n Array after quicksort:\n"); */
/* for (i=0; i < LEN; i++) */
/* printf("%d, ",arr[i]); */
init
(
arr
,
arr_max
);
/* error to be detected on the next function call.
Should be: quicksort(arr, 0, LEN-1)
to prevent an out-of-bound access to arr[LEN] */
quicksort
(
arr
,
0
,
LEN
);
return
0
;
}
This diff is collapsed.
Click to expand it.
src/plugins/e-acsl/tests/csrv14/benchmark3.solution.c
+
37
−
45
View file @
7587f3c0
...
...
@@ -2,44 +2,26 @@
/* instructions */
/* ************************************************************************** */
/*
Detect an out-of-bounds access to arr[LEN] due to the call from main()
quicksort(arr, 0, LEN);
instead of
quicksort(arr, 0, LEN-1);
Here this out-of-bounds access does not provoke a segmentation fault by chance
since it happens to access another array. Moreover, this access may
not provoke a sorting error by chance like in this example where the
accessed element arr[LEN] is equal to the maximal element of the array arr.
Check that each call to the function [quicksort] is performed on an array
correctly allocated for each cell array[i], with left <= i <= right.
*/
/* ************************************************************************** */
#include
<stdio.h>
#define LEN
2048
//
#include<stdio.h>
#define LEN
10000
/*@ requires \valid(array+i);
@ requires \valid(array+j);
@ assigns array[i], array[j];
@ ensures array[i] == \old(array[j]);
@ ensures array[j] == \old(array[i]);
@*/
/* /\*@ requires \valid(array+i); */
/* @ requires \valid(array+j); *\/ */
void
swap
(
int
*
array
,
int
i
,
int
j
)
{
int
tmp
=
array
[
i
];
array
[
i
]
=
array
[
j
];
array
[
j
]
=
tmp
;
}
/*@ requires \forall integer j; left <= j <= right ==> \valid(array+j);
@ assigns array[left..right];
@*/
///*@ requires \forall integer j; left <= j <= right ==> \valid(array+j); */
int
partition
(
int
*
array
,
int
left
,
int
right
,
int
pivotIndex
)
{
int
pivotValue
=
array
[
pivotIndex
],
storeIndex
=
left
,
i
;
swap
(
array
,
pivotIndex
,
right
);
/*@ loop invariant left <= i <= right;
@ loop assigns i, storeIndex, array[left..right];
@ loop variant right-i;
@*/
for
(
i
=
left
;
i
<
right
;
i
++
)
{
if
(
array
[
i
]
<=
pivotValue
)
{
swap
(
array
,
i
,
storeIndex
);
...
...
@@ -50,10 +32,7 @@ int partition (int* array, int left, int right, int pivotIndex) {
return
storeIndex
;
}
/*@ requires \forall integer j; left <= j <= right ==> \valid(array+j);
@ assigns array[left..right];
@ ensures \forall int i; left <= i < right ==> array[i] <= array[i+1];
@*/
/*@ requires \forall integer j; left <= j <= right ==> \valid(array+j); */
void
quicksort
(
int
*
array
,
int
left
,
int
right
)
{
if
(
left
<
right
)
{
int
pivotIndex
=
(
left
+
right
)
/
2
;
...
...
@@ -63,28 +42,41 @@ void quicksort(int* array, int left, int right) {
}
}
int
main
(
void
)
{
void
init
(
int
*
arr1
,
int
*
arr2
)
{
int
i
;
int
arr
[
LEN
];
// array to be sorted
int
arr_max
[
LEN
];
// array of maximal elements
// filling arrays
arr
[
0
]
=
0
;
arr
_max
[
0
]
=
9
;
// filling arrays
arr
1
[
0
]
=
0
;
arr
2
[
0
]
=
9
;
for
(
i
=
1
;
i
<
LEN
;
i
++
){
arr
[
i
]
=
(
13
*
arr
[
i
-
1
]
+
i
)
%
10
;
arr
_max
[
i
]
=
9
;
arr
1
[
i
]
=
(
13
*
arr
1
[
i
-
1
]
+
i
)
%
10
;
arr
2
[
i
]
=
9
;
}
}
int
main
(
void
)
{
int
i
;
int
arr
[
LEN
];
// array to be sorted
int
arr_max
[
LEN
];
// array of maximal elements
printf
(
"
\n
Array before quicksort:
\n
"
);
for
(
i
=
0
;
i
<
LEN
;
i
++
)
printf
(
"%d, "
,
arr
[
i
]);
quicksort
(
arr
,
0
,
LEN
);
// error ! must be: quicksort(arr, 0, LEN-1);
init
(
arr
,
arr_max
);
/* printf("\n Array before quicksort:\n"); */
/* for (i=0; i < LEN; i++) */
/* printf("%d, ",arr[i]); */
quicksort
(
arr
,
0
,
LEN
-
1
);
printf
(
"
\n
Array after quicksort:
\n
"
);
for
(
i
=
0
;
i
<
LEN
;
i
++
)
printf
(
"%d, "
,
arr
[
i
]);
/* printf("\n Array after quicksort:\n"); */
/* for (i=0; i < LEN; i++) */
/* printf("%d, ",arr[i]); */
init
(
arr
,
arr_max
);
/* error to be detected on the next function call.
Should be: quicksort(arr, 0, LEN-1)
to prevent an out-of-bound access to arr[LEN] */
quicksort
(
arr
,
0
,
LEN
);
return
0
;
}
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