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

Audit required: Function call in default() that returns Self RS-A1008 #2686

Open
philipjonsen opened this issue Sep 22, 2024 · 0 comments
Open

Comments

@philipjonsen
Copy link

philipjonsen commented Sep 22, 2024

Description
The default() function in the Default trait is used to create a default instance of the type. While implementing this, if a function call returns the same type, it could possibly create an infinite loop by calling default() itself.

Consider revisiting this implementation.

Bad practice;
`struct A(i32);

impl A {
fn new() -> Self {
Self::default()
}
}

impl Default for A {
fn default() -> Self {
// This call will create an infinite loop
Self::new()
}
}
´

Found call returning Self in default()
https://github.com/nitro/blob/master/arbitrator/prover/src/programs/counter.rs#L40-L42

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

No branches or pull requests

1 participant