Consistently triggering null pointer bug

This commit is contained in:
Joshua Hoeflich 2021-08-10 10:51:15 -05:00
parent 945212db28
commit 05d87314e7
2 changed files with 61 additions and 7 deletions

View file

@ -1557,6 +1557,7 @@ fn str_from_utf8_range(symbol: Symbol, var_store: &mut VarStore) -> Def {
let start_var = var_store.fresh();
let start_bool = var_store.fresh();
let add_var = var_store.fresh();
let body = If {
cond_var: start_bool,
@ -1567,6 +1568,11 @@ fn str_from_utf8_range(symbol: Symbol, var_store: &mut VarStore) -> Def {
args: vec![
(
start_var,
RunLowLevel {
op: LowLevel::NumAdd,
args: vec![
(
add_var,
Access {
record_var: arg_record_var,
ext_var: var_store.fresh(),
@ -1575,6 +1581,20 @@ fn str_from_utf8_range(symbol: Symbol, var_store: &mut VarStore) -> Def {
loc_expr: Box::new(no_region(Var(Symbol::ARG_2))),
},
),
(
add_var,
Access {
record_var: arg_record_var,
ext_var: var_store.fresh(),
field: "count".into(),
field_var: var_store.fresh(),
loc_expr: Box::new(no_region(Var(Symbol::ARG_2))),
},
),
],
ret_var: add_var,
},
),
(
start_var,
RunLowLevel {

View file

@ -896,7 +896,7 @@ fn str_from_utf8_range_order_does_not_matter() {
}
#[test]
fn str_from_utf8_range_out_of_bounds() {
fn str_from_utf8_range_out_of_bounds_start_value() {
assert_evals_to!(
indoc!(
r#"
@ -911,3 +911,37 @@ fn str_from_utf8_range_out_of_bounds() {
RocStr
);
}
#[test]
fn str_from_utf8_range_count_too_high() {
assert_evals_to!(
indoc!(
r#"
bytes = Str.toUtf8 "hello"
when Str.fromUtf8Range bytes { start: 0, count: 6 } is
Ok _ -> ""
Err (BadUtf8 _ _) -> ""
Err OutOfBounds -> "out of bounds"
"#
),
RocStr::from("out of bounds"),
RocStr
);
}
#[test]
fn str_from_utf8_range_count_too_high_for_start() {
assert_evals_to!(
indoc!(
r#"
bytes = Str.toUtf8 "hello"
when Str.fromUtf8Range bytes { start: 4, count: 3 } is
Ok _ -> ""
Err (BadUtf8 _ _) -> ""
Err OutOfBounds -> "out of bounds"
"#
),
RocStr::from("out of bounds"),
RocStr
);
}