jordanbray / chess

A rust library to manage chess move generation
https://jordanbray.github.io/chess/
MIT License
231 stars 54 forks source link

Panic due to uninitialized Board #42

Closed lzanini closed 3 years ago

lzanini commented 3 years ago

Hello,

Rust 1.50 panics when running this simple example (chess version: 3.1.1)

use chess::{Board, ChessMove, Square};

fn main() {
    let board = Board::default();
    board.make_move_new(ChessMove::new(Square::E2, Square::E4, None));
}

Traceback:

thread 'main' panicked at 'attempted to leave type `chess::Board` uninitialized, which is invalid'
stack backtrace:
   0: rust_begin_unwind
             at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/library/std/src/panicking.rs:493:5
   1: core::panicking::panic_fmt
             at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/library/core/src/panicking.rs:92:14
   2: core::panicking::panic
             at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/library/core/src/panicking.rs:50:5
   3: core::mem::uninitialized
             at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/library/core/src/mem/mod.rs:659:9
   4: chess::board::Board::make_move_new
             at /home/lucas/.cargo/registry/src/github.com-1ecc6299db9ec823/chess-3.1.1/src/board.rs:857:35
   5: simple_engine::main
             at ./src/main.rs:6:13
   6: core::ops::function::FnOnce::call_once
             at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/library/core/src/ops/function.rs:227:5

Apparently, it is not happy with the mem::uninitialized() in board.rs

pub fn make_move_new(&self, m: ChessMove) -> Board {
    let mut result = unsafe { mem::uninitialized() };
    self.make_move(m, &mut result);
    result
}

Edit: probably fixed by 6693cacb2e77297b40349096f1aabbdb7baf0f66 but not released yet.

jordanbray commented 3 years ago

I'm unable to replicate this. Can you try your example code with the newly-released 3.2 and see if that works out?

joeri commented 3 years ago

I had the same issue with 3.1.1 and rust 1.50. I can confirm that on 3.2 I no longer have the issue.