diff --git a/lib/search/hex.c b/lib/search/hex.c index 3dbb6c3b8..42416c6f9 100644 --- a/lib/search/hex.c +++ b/lib/search/hex.c @@ -51,34 +51,29 @@ 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 < 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) == '"') {