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 *
mc_search__hex_translate_to_regex (const GString * astr)
{
const char *str = astr->str;
GString *buff;
gchar *tmp_str;
gsize tmp_str_len;
gsize loop = 0;
int val, ptr;
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 */
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))
{
gchar *tmp_str2;
if (val < -128 || val > 255)
{
loop++;
continue;
else
{
g_string_append_printf (buff, "\\x%02X", (unsigned char) val);
loop += ptr;
}
tmp_str2 = g_strdup_printf ("\\x%02X", (unsigned char) val);
g_string_append (buff, tmp_str2);
g_free (tmp_str2);
loop += ptr;
}
else if (*(tmp_str + loop) == '"')
{
gsize loop2 = 0;
loop++;
while (loop + loop2 < astr->len)
while (loop + loop2 < tmp_str_len)
{
if (*(tmp_str + loop + loop2) == '"' &&
!strutils_is_char_escaped (tmp_str, tmp_str + loop + loop2))