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

Mean is panicking on empty arrays #2611

Closed
2 tasks done
Rubilmax opened this issue Aug 4, 2022 · 3 comments · Fixed by #2612
Closed
2 tasks done

Mean is panicking on empty arrays #2611

Rubilmax opened this issue Aug 4, 2022 · 3 comments · Fixed by #2612
Assignees
Labels
T-bug Type: bug
Milestone

Comments

@Rubilmax
Copy link
Contributor

Rubilmax commented Aug 4, 2022

Component

Forge

Have you ensured that all of these are up to date?

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge 0.2.0 (9b0575e 2022-08-04T00:04:01.463358166Z)

What command(s) is the bug in?

forge test

Operating System

Linux

Describe the bug

In calc.rs#L12, this fix should be applied:

pub fn mean<T>(values: &[T]) -> U256
where
    T: Into<U256> + Copy,
{
-    values.iter().copied().fold(U256::zero(), |sum, val| sum + val.into()) / values.len();
+    let len = values.len();
+    if len > 0 {
+        values.iter().copied().fold(U256::zero(), |sum, val| sum + val.into()) / len
+    } else {
+        U256::zero()
+    }
}
@Rubilmax Rubilmax added the T-bug Type: bug label Aug 4, 2022
@Rubilmax
Copy link
Contributor Author

Rubilmax commented Aug 4, 2022

Is it possible to have write permission on side branches, so I could submit Pull Requests?

@onbjerg
Copy link
Member

onbjerg commented Aug 4, 2022

Not sure what you mean? Anyone can submit a pull request, you just need to fork the repository and push to a branch on the fork

@onbjerg onbjerg added this to the v1.0.0 milestone Aug 4, 2022
@Rubilmax
Copy link
Contributor Author

Rubilmax commented Aug 4, 2022

First time submitting an open source PR ahah, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-bug Type: bug
Projects
No open projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants