Adjust fuel consumption to be empty when fuel is 0 (#5013)

Co-authored-by: Jamey Sharp <jsharp@fastly.com>

Co-authored-by: Jamey Sharp <jsharp@fastly.com>
This commit is contained in:
Rainy Sinclair
2022-10-05 10:25:31 -04:00
committed by GitHub
parent e63771f2d9
commit 6d1bce9c64
3 changed files with 7 additions and 7 deletions

View File

@@ -787,7 +787,8 @@ impl Drop for SignalOnDrop {
}
}
fn set_fuel<T>(store: &mut Store<T>, fuel: u64) {
/// Set the amount of fuel in a store to a given value
pub fn set_fuel<T>(store: &mut Store<T>, fuel: u64) {
// Determine the amount of fuel already within the store, if any, and
// add/consume as appropriate to set the remaining amount to` fuel`.
let remaining = store.consume_fuel(0).unwrap();

View File

@@ -1434,7 +1434,7 @@ impl StoreOpaque {
.ok()
.and_then(|fuel| consumed_ptr.checked_add(fuel))
{
Some(consumed) if consumed < 0 => {
Some(consumed) if consumed <= 0 => {
*consumed_ptr = consumed;
Ok(u64::try_from(-consumed).unwrap())
}