gchp / iota

A terminal-based text editor written in Rust
MIT License
1.63k stars 81 forks source link

iota crashes after C-A/C-E when the buffer is only one line #100

Open snowp opened 9 years ago

snowp commented 9 years ago

The editor crashes due to a rust_panic caused by an out of bounds access on a Vec whenever move-beginning-of-line (C-a) or move-end-of-line (C-e) is used in a buffer with no newlines.

thread '<main>' panicked at 'index out of bounds: the len is 0 but the index is 0', /Users/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-mac/build/src/libcollections/vec.rs:1346

The issue seems to be with buffer.rs in get_line_index_backward and get_line_index_forward: nlines is an empty Vec when the buffer contains no newlines. The subsequent access to nlines[offset] on line 275 and 334 causes the panics.

gchp commented 9 years ago

Thanks for the report! Will try get this fixed asap!

romanlevin commented 8 years ago

This doesn't crash anymore, however C-e does nothing at all when you are on a line without a newline at the end of it.

crespyl commented 8 years ago

I have a partial fix here.

The cursor seems to get displayed one char after where it should be, but the actual insertion point is correct.

gchp commented 8 years ago

@crespyl looks good!

Wanna open a pull request? :)