diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/frame.c | 21 | ||||
-rw-r--r-- | src/sc_editor.c | 5 |
2 files changed, 24 insertions, 2 deletions
diff --git a/src/frame.c b/src/frame.c index 542ced2..c835869 100644 --- a/src/frame.c +++ b/src/frame.c @@ -557,6 +557,11 @@ int find_cursor(struct frame *fr, double x, double y, double pos = fr->pad_t; int i; + if ( fr == NULL ) { + fprintf(stderr, "Cursor frame is NULL.\n"); + return 1; + } + for ( i=0; i<fr->n_paras; i++ ) { double npos = pos + fr->paras[i]->height; if ( npos > y ) { @@ -572,6 +577,8 @@ int find_cursor(struct frame *fr, double x, double y, pos = npos; } + if ( fr->n_paras == 0 ) return 1; + /* Pretend it's in the last paragraph */ pos -= fr->paras[fr->n_paras-1]->height; *ppara = fr->n_paras - 1; @@ -588,7 +595,12 @@ int get_para_highlight(struct frame *fr, int cursor_para, int i; double py = 0.0; - if ( cursor_para > fr->n_paras ) { + if ( fr == NULL ) { + fprintf(stderr, "Cursor frame is NULL.\n"); + return 1; + } + + if ( cursor_para >= fr->n_paras ) { fprintf(stderr, "Cursor paragraph number is too high!\n"); return 1; } @@ -614,7 +626,12 @@ int get_cursor_pos(struct frame *fr, int cursor_para, int cursor_pos, int i; double py = 0.0; - if ( cursor_para > fr->n_paras ) { + if ( fr == NULL ) { + fprintf(stderr, "Cursor frame is NULL.\n"); + return 1; + } + + if ( cursor_para >= fr->n_paras ) { fprintf(stderr, "Cursor paragraph number is too high!\n"); return 1; } diff --git a/src/sc_editor.c b/src/sc_editor.c index 72e90e8..ca37853 100644 --- a/src/sc_editor.c +++ b/src/sc_editor.c @@ -583,6 +583,11 @@ static void insert_text(char *t, SCEditor *e) { Paragraph *para; + if ( e->cursor_frame == NULL ) { + fprintf(stderr, "Inserting text into no frame.\n"); + return; + } + if ( e->cursor_para >= e->cursor_frame->n_paras ) { fprintf(stderr, "Cursor paragraph number is too high!\n"); return; |