diff --git a/source/helper.c b/source/helper.c index f5ab6d9b..3de37208 100644 --- a/source/helper.c +++ b/source/helper.c @@ -44,7 +44,7 @@ char* fgets_s ( char* s, int n, FILE *iop, char sep ) { // Map these to registers. - register int c; + register int c = EOF; register char* cs; cs = s; // read until EOF or buffer is full. diff --git a/source/textbox.c b/source/textbox.c index a0c323db..665bd900 100644 --- a/source/textbox.c +++ b/source/textbox.c @@ -312,7 +312,8 @@ void textbox_draw ( textbox *tb ) // cursor handling for edit mode void textbox_cursor ( textbox *tb, int pos ) { - tb->cursor = MAX ( 0, MIN ( ( int ) strlen ( tb->text ), pos ) ); + int length = (tb->text == NULL)? 0: strlen(tb->text); + tb->cursor = MAX ( 0, MIN ( length, pos ) ); } // move right @@ -332,6 +333,9 @@ void textbox_cursor_dec ( textbox *tb ) // Move word right void textbox_cursor_inc_word ( textbox *tb ) { + if(tb->text == NULL) { + return; + } // Find word boundaries, with pango_Break? gchar *c = &( tb->text[tb->cursor] ); while ( ( c = g_utf8_next_char ( c ) ) ) { @@ -347,6 +351,9 @@ void textbox_cursor_inc_word ( textbox *tb ) break; } } + if(c == NULL) { + return; + } while ( ( c = g_utf8_next_char ( c ) ) ) { gunichar uc = g_utf8_get_char ( c ); GUnicodeBreakType bt = g_unichar_break_type ( uc ); @@ -445,6 +452,9 @@ void textbox_delete ( textbox *tb, int pos, int dlen ) // delete on character void textbox_cursor_del ( textbox *tb ) { + if(tb->text == NULL) { + return; + } int index = g_utf8_next_char ( &( tb->text[tb->cursor] ) ) - tb->text; textbox_delete ( tb, tb->cursor, index - tb->cursor ); }