1
1

Ticket #1858: Segmentation fault when search in different encodings

Test case:
1. Make two files with same content but with different encodings (for example, in UTF-8 and KOI8-R);
2. Open UTF-8 file for editing. Press Alt+e and set 'UTF-8' encoding;
3. Search someting
4. exit from editor and open file with 'KOI8-R' encoding;
5. You must see a dots. Now press shift+F7 (continue search);
6. Segfault here

Fix issue:
Now function mc_search__recode_str() returns newly allocated string in any case

Signed-off-by: Slava Zanko <slavazanko@gmail.com>
Этот коммит содержится в:
Slava Zanko 2009-12-04 11:27:24 +02:00
родитель 2c7f684908
Коммит 2887d5c710
2 изменённых файлов: 10 добавлений и 12 удалений

Просмотреть файл

@ -67,11 +67,19 @@ mc_search__recode_str (const char *str, gsize str_len,
} }
conv = g_iconv_open (charset_to, charset_from); conv = g_iconv_open (charset_to, charset_from);
if (conv == INVALID_CONV) if (conv == INVALID_CONV) {
return NULL; *bytes_written = str_len;
return g_strndup (str, str_len);
}
ret = g_convert_with_iconv (str, str_len, conv, &bytes_read, bytes_written, NULL); ret = g_convert_with_iconv (str, str_len, conv, &bytes_read, bytes_written, NULL);
g_iconv_close (conv); g_iconv_close (conv);
if (ret == NULL) {
*bytes_written = str_len;
return g_strndup (str, str_len);
}
return ret; return ret;
} }
@ -152,8 +160,6 @@ mc_search__tolower_case_str (const char *charset, const char *str, gsize str_len
tmp_str2 = converted_str = tmp_str2 = converted_str =
mc_search__recode_str (str, str_len, charset, cp_display, &converted_str_len); mc_search__recode_str (str, str_len, charset, cp_display, &converted_str_len);
if (converted_str == NULL)
return NULL;
tmp_len = converted_str_len + 1; tmp_len = converted_str_len + 1;
@ -166,8 +172,6 @@ mc_search__tolower_case_str (const char *charset, const char *str, gsize str_len
tmp_str2 = tmp_str2 =
mc_search__recode_str (converted_str, converted_str_len, cp_display, charset, &tmp_len); mc_search__recode_str (converted_str, converted_str_len, cp_display, charset, &tmp_len);
g_free (converted_str); g_free (converted_str);
if (tmp_str2 == NULL)
return NULL;
ret = g_string_new_len (tmp_str2, tmp_len); ret = g_string_new_len (tmp_str2, tmp_len);
g_free (tmp_str2); g_free (tmp_str2);
@ -206,8 +210,6 @@ mc_search__toupper_case_str (const char *charset, const char *str, gsize str_len
tmp_str2 = converted_str = tmp_str2 = converted_str =
mc_search__recode_str (str, str_len, charset, cp_display, &converted_str_len); mc_search__recode_str (str, str_len, charset, cp_display, &converted_str_len);
if (converted_str == NULL)
return NULL;
tmp_len = converted_str_len + 1; tmp_len = converted_str_len + 1;
@ -221,8 +223,6 @@ mc_search__toupper_case_str (const char *charset, const char *str, gsize str_len
tmp_str2 = tmp_str2 =
mc_search__recode_str (converted_str, converted_str_len, cp_display, charset, &tmp_len); mc_search__recode_str (converted_str, converted_str_len, cp_display, charset, &tmp_len);
g_free (converted_str); g_free (converted_str);
if (tmp_str2 == NULL)
return NULL;
ret = g_string_new_len (tmp_str2, tmp_len); ret = g_string_new_len (tmp_str2, tmp_len);
g_free (tmp_str2); g_free (tmp_str2);

Просмотреть файл

@ -197,8 +197,6 @@ mc_search_prepare (mc_search_t * lc_mc_search)
buffer = buffer =
mc_search__recode_str (lc_mc_search->original, lc_mc_search->original_len, cp_source, mc_search__recode_str (lc_mc_search->original, lc_mc_search->original_len, cp_source,
codepages[loop1].id, &recoded_str_len); codepages[loop1].id, &recoded_str_len);
if (buffer == NULL)
continue;
g_ptr_array_add (ret, g_ptr_array_add (ret,
mc_search__cond_struct_new (lc_mc_search, buffer, mc_search__cond_struct_new (lc_mc_search, buffer,