Hit `unreachable_unchecked!()` which is undefined behaviour
Currently there is an invocation of [unreachable_unchecked](https://doc.rust-lang.org/std/hint/fn.unreachable_unchecked.html) in [trans.rs:92](https://github.com/archlinux/alpm.rs/blob/b81052c40b70e291a767d24dcda37fdd7967cf2a/alpm/src/trans.rs#L92).
I just hit this in debug while testing something. I have not fully debugged the cause in libalpm yet, but there are a lot of locations in its code that return -1 without setting an error on the handle (mostly in calls to their `ASSERT` macro). These result in a call to [`check_ret`](https://github.com/archlinux/alpm.rs/blob/b81052c40b70e291a767d24dcda37fdd7967cf2a/alpm/src/trans.rs#L158) returning an `Ok` error variant, leading to the `PrepareError::data()` call hitting the `unreachable_unchecked`.
I am fine with `data()` panicking, I think not receiving a correct error from libalpm is a bug in their code not yours. But I think a call to `unreachable` instead of the `_unchecked` variant would be a better idea, to reliably fail instead of invoking undefined behavior. Especially because unpacking an error is not a performance critical action.
**Edit:**
Finally figured out the error path I was hitting and opened an issue on their repo: [219](https://gitlab.archlinux.org/pacman/pacman/-/issues/219). For posterity, the thing I was doing wrong was invoking `libalpm` in a context without a writable `/tmp` dir and without providing cache directories.
关闭于 2025-01-01 1 条评论