From: Ian Jackson Date: Thu, 19 May 2022 20:12:43 +0000 (+0100) Subject: currency: Change "new_qty" to "new_value" X-Git-Tag: otter-1.1.0~51 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=ed2eaf11bf43c7345aaeb41b0546fccf017774d8;p=otter.git currency: Change "new_qty" to "new_value" Spotted a bug, which leaked value during occultation. Putting new_qty inside Value makes it easier to arrange to always call call .html on it. Signed-off-by: Ian Jackson --- diff --git a/src/currency.rs b/src/currency.rs index 8d3f01a8..baf7559d 100644 --- a/src/currency.rs +++ b/src/currency.rs @@ -256,10 +256,10 @@ impl PieceTrait for Banknote { let tqty = tgpc.xdata_exp::()?.qty; let mqty = mgpc.xdata_exp::()?.qty; - if_let!{ - Some(new_qty) = mqty.checked_add(tqty); - else return Ok(default()); // arithmetic overflow! - } + let new_value = match mqty.checked_add(tqty) { + Some(qty) => Value { qty }, + None => return default(), // arithmetic overflow! + }; let logent = hformat!( "{} deposited {}, giving {}{}", @@ -268,7 +268,8 @@ impl PieceTrait for Banknote { None => Html::lit("Departing player").into(), }, tipc.p.show(show).describe_html(tgpc, goccults)?, - new_qty, currency, + &new_value.html(), + currency, ); let logents = vec![ LogEntry { html: logent } ]; @@ -286,7 +287,7 @@ impl PieceTrait for Banknote { let mgpc = ig.gs.pieces.get_mut(mpiece).ok_or("tpiece vanished")?; let mvalue = mgpc.xdata_mut_exp::().map_err(|_|"xdata vanished")?; mvalue.qty = mvalue.qty.checked_add(tqty).ok_or("overflow")?; - if mvalue.qty != new_qty { throw!("modified value") } + if mvalue.qty != new_value.qty { throw!("modified value") } Ok::<_,&'static str>(()) })().unwrap_or_else(|m|{ warn!("during dorp-and-merge of currency {tpiece:?} into {mpiece:?}: {m}");