fix: edit_get_prev_utf segfault, add compare str with start of buf

This commit is contained in:
Ilia Maslakov 2009-04-15 19:07:46 +00:00 committed by Slava Zanko
parent 2fdb3689e2
commit 7bcb0b1930

View File

@ -168,6 +168,7 @@ int edit_get_utf (WEdit * edit, long byte_index, int *char_width)
return '\n'; return '\n';
} }
str = edit_get_byte_ptr (edit, byte_index); str = edit_get_byte_ptr (edit, byte_index);
res = g_utf8_get_char_validated (str, -1); res = g_utf8_get_char_validated (str, -1);
@ -200,27 +201,26 @@ int edit_get_prev_utf (WEdit * edit, long byte_index, int *char_width)
gunichar ch; gunichar ch;
gchar *next_ch = NULL; gchar *next_ch = NULL;
int width = 0; int width = 0;
gchar *prn_buf=NULL;
if ( byte_index > 0 ) { if ( byte_index > 0 ) {
byte_index--; byte_index--;
} }
ch = edit_get_utf (edit, byte_index, &width); ch = edit_get_utf (edit, byte_index, &width);
if ( width == 1 ) { if ( width == 1 ) {
*char_width = width; *char_width = width;
return ch; return ch;
} }
if ( byte_index >= (edit->curs1 + edit->curs2) || byte_index < 0 ) { if ( byte_index >= (edit->curs1 + edit->curs2) || byte_index < 0 ) {
*char_width = 1; *char_width = 0;
return 0; return 0;
} }
str = edit_get_byte_ptr (edit, byte_index); str = edit_get_byte_ptr (edit, byte_index);
buf = edit_get_buf_ptr (edit, byte_index); buf = edit_get_buf_ptr (edit, byte_index);
/* get prev utf8 char */ /* get prev utf8 char */
if ( str != buf )
str = g_utf8_find_prev_char (buf, str); str = g_utf8_find_prev_char (buf, str);
res = g_utf8_get_char_validated (str, -1); res = g_utf8_get_char_validated (str, -1);