seppo0010/rsedis

Cannot split off at a nonexistent index

Closed this issue · 3 comments

wlsnx commented

I am learning rust and the source code of rsedis is a good teaching material.But I found a BUG:

  pub fn ltrim(&mut self, _start: i64, _stop: i64) -> Result<(), OperationError> {
        let list = match *self {
            ValueList::Data(ref mut list) => {
                let len = list.len();
                let start = match normalize_position(_start, len) {
                    Ok(i) => i,
                    Err(g) => if !g { 0 } else {
                        list.split_off(len);
                        len
                    },
                };
                let stop = match normalize_position(_stop, len) {
                    Ok(i) => i,
                    Err(g) => if !g {
                        list.split_off(len);
                        0
                    } else { len },
                };
                list.split_off(stop + 1);
                list.split_off(start)
            }
        };
        *self = ValueList::Data(list);
        Ok(())
    }

This is a function of the struct ValueList in database/src/list.rs.
If _stop argument equal or greater than len , the value of stop will be len and stop + 1 will out of range.
If stop less than len and start greater than stop + 1 , the program will panic.

Thanks for the bug report! 😀

Feel free to submit Pull Requests!

If you wanna contribute, there's some low hanging fruit you can try. The following commands should be good to get started:

getset
mset
msetnx
randomkey
move
rename
renamenx
keys
wlsnx commented

I'm very glad to do this,it will help me to learn rust. 😄