japanoise / emsys

ersatz-emacs text editor
MIT License
3 stars 2 forks source link

setting the mark at end of file causes error "Mark invalid" #10

Closed nicholascarroll closed 2 years ago

nicholascarroll commented 2 years ago

To reproduce:

  1. Go to end of file
  2. Set mark
  3. moveup some lines and try cut or copy
  4. you get the error "Mark invalid"

Fix: in file region.c, line 9:

void editorSetMark(struct editorBuffer *buf) {                                               
        if (buf->cy == buf->numrows) {                                            
               buf->cx = buf->row[--buf->cy].size;        
    }                                                                                        
        buf->markx = buf->cx;                                                                
        buf->marky = buf->cy;                                                                
        editorSetStatusMessage("Mark set.");                                                 
}   
nicholascarroll commented 2 years ago

There are other bugs which relate to the buffer being made empty: BUG: SPEWS CHARACTERS INTO BUFFER

  1. Go to start of buffer
  2. Set mark
  3. Go to end of buffer (M->)
  4. Cut (C-w)
  5. Now buffer should be empty but actually there will be some characters appear in the buffer

BUG: SEGFAULT

  1. Go to end of file and position cursor at the end of last actual line
  2. Set mark
  3. Go to first line of file
  4. Cut (C-w)
  5. Yank (buffer is now empty)
  6. press a few arrow keys
  7. SEGFAULT!!
japanoise commented 2 years ago

This class of shenanigans has bitten me once before. In Gomacs I actually removed the idea of typing outside of the buffer because of stuff like this, which ended up being a mistake because it introduced more bugs and misbehavior. This time, I think this deserves a proper fix.

nicholascarroll commented 2 years ago

thanks! I fetch merged in this change and tested it; all working nicely.