Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

panic (overflow) in amount_pico_btc #3027

Closed
mikedilger opened this issue Apr 26, 2024 · 1 comment · Fixed by #3032
Closed

panic (overflow) in amount_pico_btc #3027

mikedilger opened this issue Apr 26, 2024 · 1 comment · Fixed by #3032

Comments

@mikedilger
Copy link

mikedilger commented Apr 26, 2024

thread '<unnamed>' panicked at /home/mike/.cargo/registry/src/index.crates.io-6f17d22bba15001f/lightning-invoice-0.30.0/src/lib.rs:1081:13:
attempt to multiply with overflow

Could use overflowing_mul() to detect and return None

Panics upstream downstream project, which I cannot catch and swallow.

@mikedilger
Copy link
Author

This is probably too verbose but:

pub fn amount_pico_btc(&self) -> Option<u64> {
        match self.hrp.raw_amount {
            None => None,
            Some(v) => {
                let (product, overflow) = v.overflowing_mul(
                    self.hrp
                        .si_prefix
                        .as_ref()
                        .map_or(1_000_000_000_000, |si| { si.multiplier() })
                );
                if overflow {
                    None
                } else {
                    Some(product)
                }
            }
        }
}

I'm not sure if None is acceptable here or it needs refactoring into a Result.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant