aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.org.uk>2016-03-31 12:36:00 +0200
committerThomas White <taw@bitwiz.org.uk>2016-03-31 21:51:02 +0200
commit554a3d38045a2c563342b534084462771621e079 (patch)
tree1911b61b3fea65d82ac16853074519b4e1b5f7a7 /src
parent8e5fb26c9b5443edea16ed9a833761100aca7f58 (diff)
Avoid a few segfaults
Diffstat (limited to 'src')
-rw-r--r--src/frame.c21
-rw-r--r--src/sc_editor.c5
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;