Merge branch '2579_hex_search'

* 2579_hex_search:
  (mc_search__hex_translate_to_regex): optimization and cleanup.
  Ticket #2579: incorrect length usage in hexadecimal search.
This commit is contained in:
Andrew Borodin 2011-07-19 21:17:00 +04:00
commit caccdbe877

View File

@ -51,39 +51,36 @@
static GString * static GString *
mc_search__hex_translate_to_regex (const GString * astr) mc_search__hex_translate_to_regex (const GString * astr)
{ {
const char *str = astr->str;
GString *buff; GString *buff;
gchar *tmp_str; gchar *tmp_str;
gsize tmp_str_len;
gsize loop = 0; gsize loop = 0;
int val, ptr;
buff = g_string_sized_new (64); buff = g_string_sized_new (64);
tmp_str = g_strndup (str, astr->len); tmp_str = g_strndup (astr->str, astr->len);
g_strchug (tmp_str); /* trim leadind whitespaces */ g_strchug (tmp_str); /* trim leadind whitespaces */
tmp_str_len = strlen (tmp_str);
while (loop < astr->len) while (loop < tmp_str_len)
{ {
int val, ptr;
if (sscanf (tmp_str + loop, "%i%n", &val, &ptr)) if (sscanf (tmp_str + loop, "%i%n", &val, &ptr))
{ {
gchar *tmp_str2;
if (val < -128 || val > 255) if (val < -128 || val > 255)
{
loop++; loop++;
continue; else
} {
g_string_append_printf (buff, "\\x%02X", (unsigned char) val);
tmp_str2 = g_strdup_printf ("\\x%02X", (unsigned char) val);
g_string_append (buff, tmp_str2);
g_free (tmp_str2);
loop += ptr; loop += ptr;
} }
}
else if (*(tmp_str + loop) == '"') else if (*(tmp_str + loop) == '"')
{ {
gsize loop2 = 0; gsize loop2 = 0;
loop++; loop++;
while (loop + loop2 < astr->len) while (loop + loop2 < tmp_str_len)
{ {
if (*(tmp_str + loop + loop2) == '"' && if (*(tmp_str + loop + loop2) == '"' &&
!strutils_is_char_escaped (tmp_str, tmp_str + loop + loop2)) !strutils_is_char_escaped (tmp_str, tmp_str + loop + loop2))