Skip to content

Commit

Permalink
Fix try_from_iter() (#179)
Browse files Browse the repository at this point in the history
* Fix a bug in try_from_iter()

* Add CHANGELOG
  • Loading branch information
yutannihilation authored Apr 14, 2024
1 parent d74dc97 commit 6e554ca
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 10 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
Please keep in mind that, in Rust, panic is an **unrecoverable error**. So,
not crashing doesn't mean you are saved.

### Fixed bugs

* Fixed a bug in `try_from_iter()` when the actual length is different than the
size reported by `size_hint()`.

## [v0.5.1] (2024-04-13)

### New features
Expand Down
6 changes: 4 additions & 2 deletions src/sexp/complex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,12 @@ impl OwnedComplexSexp {
last_index = i;
}

if last_index + 1 != upper {
let new_len = last_index + 1;
if new_len != upper {
unsafe {
savvy_ffi::SETLENGTH(out.inner, (last_index + 1) as _);
savvy_ffi::SETLENGTH(out.inner, new_len as _);
}
out.len = new_len;
}

Ok(out)
Expand Down
6 changes: 4 additions & 2 deletions src/sexp/integer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,12 @@ impl OwnedIntegerSexp {
last_index = i;
}

if last_index + 1 != upper {
let new_len = last_index + 1;
if new_len != upper {
unsafe {
savvy_ffi::SETLENGTH(out.inner, (last_index + 1) as _);
savvy_ffi::SETLENGTH(out.inner, new_len as _);
}
out.len = new_len;
}

Ok(out)
Expand Down
6 changes: 4 additions & 2 deletions src/sexp/logical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,12 @@ impl OwnedLogicalSexp {
last_index = i;
}

if last_index + 1 != upper {
let new_len = last_index + 1;
if new_len != upper {
unsafe {
savvy_ffi::SETLENGTH(out.inner, (last_index + 1) as _);
savvy_ffi::SETLENGTH(out.inner, new_len as _);
}
out.len = new_len;
}

Ok(out)
Expand Down
6 changes: 4 additions & 2 deletions src/sexp/real.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,12 @@ impl OwnedRealSexp {
last_index = i;
}

if last_index + 1 != upper {
let new_len = last_index + 1;
if new_len != upper {
unsafe {
savvy_ffi::SETLENGTH(out.inner, (last_index + 1) as _);
savvy_ffi::SETLENGTH(out.inner, new_len as _);
}
out.len = new_len;
}

Ok(out)
Expand Down
6 changes: 4 additions & 2 deletions src/sexp/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,12 @@ impl OwnedStringSexp {
last_index = i;
}

if last_index + 1 != upper {
let new_len = last_index + 1;
if new_len != upper {
unsafe {
savvy_ffi::SETLENGTH(out.inner, (last_index + 1) as _);
savvy_ffi::SETLENGTH(out.inner, new_len as _);
}
out.len = new_len;
}

Ok(out)
Expand Down

0 comments on commit 6e554ca

Please sign in to comment.