Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
K
klee_tutorial
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
Niklas Lundberg
klee_tutorial
Commits
2e7c74eb
Commit
2e7c74eb
authored
4 years ago
by
Blinningjr
Browse files
Options
Downloads
Patches
Plain Diff
D
parent
d32e0fc4
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
cargo_klee_examples/examples/array.rs
+8
-4
8 additions, 4 deletions
cargo_klee_examples/examples/array.rs
with
8 additions
and
4 deletions
cargo_klee_examples/examples/array.rs
+
8
−
4
View file @
2e7c74eb
...
@@ -8,11 +8,11 @@
...
@@ -8,11 +8,11 @@
use
klee_sys
::
klee_make_symbolic
;
use
klee_sys
::
klee_make_symbolic
;
use
panic_klee
as
_
;
use
panic_klee
as
_
;
fn
sum_first_elements
(
arr
:
&
[
u8
],
index
:
usize
)
->
u
8
{
fn
sum_first_elements
(
arr
:
&
[
u8
],
index
:
usize
)
->
u
16
{
let
mut
acc
=
0
;
let
mut
acc
:
u16
=
0
;
for
i
in
0
..
index
{
for
i
in
0
..
index
{
if
index
<
arr
.len
()
{
if
index
<
arr
.len
()
{
acc
+=
arr
[
i
as
usize
];
acc
+=
arr
[
i
as
usize
]
as
u16
;
}
else
{
}
else
{
break
;
break
;
}
}
...
@@ -45,7 +45,7 @@ fn main() {
...
@@ -45,7 +45,7 @@ fn main() {
// [your answer here]]
// [your answer here]]
// The diffrence is that debug test all 10 possible paths and release only checks 2. This is becaus
// The diffrence is that debug test all 10 possible paths and release only checks 2. This is becaus
// 9 of the paths are basicly the same. These are the path were index is 0..8, the last path is
// 9 of the paths are basicly the same. These are the path were index is 0..8, the last path is
// diffrent because then the index is out side of the array(index = 255), thus there will be an error.
// diffrent because then the index is out side of the array(index = 255), thus there will be an error
/panic
.
//
//
//
//
// Debug:
// Debug:
...
@@ -80,11 +80,15 @@ fn main() {
...
@@ -80,11 +80,15 @@ fn main() {
// Explain what caused the error.
// Explain what caused the error.
//
//
// [your answer here]
// [your answer here]
// acc = 255 and arr[i as usize] = 127 in the secound loop in sum_first_elements, test4. Thus acc
// is a u8 variable that will overflow and cause a panic.
//
//
// E) Make a sensible fix to the code.
// E) Make a sensible fix to the code.
// Motivate your choice.
// Motivate your choice.
//
//
// [your answer here]
// [your answer here]
// I made acc a u16 instead of a u8 because the maximum sum of arr is 8 * 255, which will easily
// fit in a u16. And thus will avoid the overflow problem.
//
//
// [Git commit "D"]
// [Git commit "D"]
//
//
...
...
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