diff --git a/CHANGELOG.md b/CHANGELOG.md index edf84e76..4127dde4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ Bug fixes --------- * Padding arrays with another array via `pad` no longer loops indefinitely. +* `chop` for arrays and BLOB's now works properly. * `set_bit` for bit-flags with negative index now works correctly. * Misnamed `params` field `name` in the JSON output of `Engine::gen_fn_metadata_to_json` is fixed (was incorrectly named `type`). diff --git a/src/packages/array_basic.rs b/src/packages/array_basic.rs index 857572ad..007a7fdc 100644 --- a/src/packages/array_basic.rs +++ b/src/packages/array_basic.rs @@ -171,11 +171,11 @@ pub mod array_functions { } } pub fn chop(array: &mut Array, len: INT) { - if !array.is_empty() && len as usize >= array.len() { - if len >= 0 { - array.drain(0..array.len() - len as usize); - } else { + if !array.is_empty() { + if len <= 0 { array.clear(); + } else if (len as usize) < array.len() { + array.drain(0..array.len() - len as usize); } } } diff --git a/src/packages/blob_basic.rs b/src/packages/blob_basic.rs index 92c42c4a..ff14fe3c 100644 --- a/src/packages/blob_basic.rs +++ b/src/packages/blob_basic.rs @@ -162,11 +162,11 @@ pub mod blob_functions { } } pub fn chop(blob: &mut Blob, len: INT) { - if !blob.is_empty() && len as usize >= blob.len() { - if len >= 0 { - blob.drain(0..blob.len() - len as usize); - } else { + if !blob.is_empty() { + if len <= 0 { blob.clear(); + } else if (len as usize) < blob.len() { + blob.drain(0..blob.len() - len as usize); } } }