Skip to content

Commit 2a3fac8

Browse files
Fix integer overflow in UCI go command (#798)
Bench: 2795637 Closes #782
1 parent 6d6edf0 commit 2a3fac8

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

src/uci.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -349,20 +349,20 @@ fn parse_limits(color: Color, tokens: &[&str]) -> Limits {
349349

350350
for chunk in tokens.chunks(2) {
351351
if let [name, value] = *chunk {
352-
let Ok(value) = value.parse() else {
352+
let Ok(value) = value.parse::<u64>() else {
353353
continue;
354354
};
355355

356356
match name {
357-
"depth" if value > 0 => return Limits::Depth(value),
358-
"movetime" if value > 0 => return Limits::Time(value as u64),
359-
"nodes" if value > 0 => return Limits::Nodes(value as u64),
357+
"depth" if value > 0 => return Limits::Depth(value as i32),
358+
"movetime" if value > 0 => return Limits::Time(value),
359+
"nodes" if value > 0 => return Limits::Nodes(value),
360360

361361
"wtime" if Color::White == color => main = Some(value),
362362
"btime" if Color::Black == color => main = Some(value),
363363
"winc" if Color::White == color => inc = Some(value),
364364
"binc" if Color::Black == color => inc = Some(value),
365-
"movestogo" => moves = Some(value as u64),
365+
"movestogo" => moves = Some(value),
366366

367367
_ => continue,
368368
}
@@ -373,8 +373,8 @@ fn parse_limits(color: Color, tokens: &[&str]) -> Limits {
373373
return Limits::Infinite;
374374
}
375375

376-
let main = main.unwrap_or_default().max(0) as u64;
377-
let inc = inc.unwrap_or_default().max(0) as u64;
376+
let main = main.unwrap_or_default();
377+
let inc = inc.unwrap_or_default();
378378

379379
match moves {
380380
Some(moves) => Limits::Cyclic(main, inc, moves),

0 commit comments

Comments
 (0)