From 7421a4c865e95afe0bc64453a6f92c01119f5038 Mon Sep 17 00:00:00 2001
From: Mooffie <mooffie@gmail.com>
Date: Mon, 26 Sep 2016 00:26:17 +0300
Subject: [PATCH 6/8] (mc_search__hex_translate_to_regex): clean up handling of
0x prefixes.
---
lib/search/hex.c | 20 ++++++--------------
1 file changed, 6 insertions(+), 14 deletions(-)
diff --git a/lib/search/hex.c b/lib/search/hex.c
index 1180016..14d0246 100644
a
|
b
|
mc_search__hex_translate_to_regex (const GString * astr, mc_search_hex_parse_err |
58 | 58 | int *error_pos_ptr) |
59 | 59 | { |
60 | 60 | GString *buff; |
61 | | gchar *tmp_str, *tmp_str2; |
| 61 | gchar *tmp_str; |
62 | 62 | gsize tmp_str_len; |
63 | 63 | gsize loop = 0; |
64 | 64 | mc_search_hex_parse_error_t error = MC_SEARCH_HEX_E_OK; |
65 | 65 | |
66 | 66 | buff = g_string_sized_new (64); |
67 | 67 | tmp_str = g_strndup (astr->str, astr->len); |
68 | | tmp_str2 = tmp_str; |
69 | | |
70 | | /* remove 0x prefices */ |
71 | | while (TRUE) |
72 | | { |
73 | | tmp_str2 = strstr (tmp_str2, "0x"); |
74 | | if (tmp_str2 == NULL) |
75 | | break; |
76 | | |
77 | | *tmp_str2++ = ' '; |
78 | | *tmp_str2++ = ' '; |
79 | | } |
80 | | |
81 | 68 | tmp_str_len = strlen (tmp_str); |
82 | 69 | |
83 | 70 | while (loop < tmp_str_len && error == MC_SEARCH_HEX_E_OK) |
… |
… |
mc_search__hex_translate_to_regex (const GString * astr, mc_search_hex_parse_err |
91 | 78 | while (g_ascii_isspace (tmp_str[loop])) |
92 | 79 | loop++; |
93 | 80 | } |
| 81 | else if (tmp_str[loop] == '0' && (tmp_str[loop + 1] == 'x' || tmp_str[loop + 1] == 'X')) |
| 82 | { |
| 83 | /* Skip 0x prefixes. */ |
| 84 | loop += 2; |
| 85 | } |
94 | 86 | /* cppcheck-suppress invalidscanf */ |
95 | 87 | else if (sscanf (tmp_str + loop, "%x%n", &val, &ptr) == 1) |
96 | 88 | { |