We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 55a145b commit 9524f16Copy full SHA for 9524f16
tests/integration-tests/fib.rs
@@ -3,17 +3,26 @@
3
#[nexus_rt::main]
4
#[nexus_rt::public_input(n)]
5
fn main(n: u32) -> u32 {
6
- let mut a = 0;
7
- let mut b = 1;
8
-
+ // Handle edge cases
9
if n == 0 {
10
- return a;
+ return 0;
+ }
+ if n == 1 {
11
+ return 1;
12
}
13
14
+ let mut a = 0u32;
15
+ let mut b = 1u32;
16
+
17
for _ in 2..n {
- let c = a + b;
18
+ // Check for potential overflow before addition
19
+ if let Some(c) = a.checked_add(b) {
20
a = b;
- b = c;
21
+ b = c;
22
+ } else {
23
+ // In case of overflow, return max value
24
+ return u32::MAX;
25
26
27
28
b
0 commit comments