Ticket #3694: 3694-0006-mc_search__hex_translate_to_regex-clean-up-handling-.patch

File 3694-0006-mc_search__hex_translate_to_regex-clean-up-handling-.patch, 1.7 KB (added by mooffie, 7 years ago)
  • lib/search/hex.c

    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 
    5858                                   int *error_pos_ptr) 
    5959{ 
    6060    GString *buff; 
    61     gchar *tmp_str, *tmp_str2; 
     61    gchar *tmp_str; 
    6262    gsize tmp_str_len; 
    6363    gsize loop = 0; 
    6464    mc_search_hex_parse_error_t error = MC_SEARCH_HEX_E_OK; 
    6565 
    6666    buff = g_string_sized_new (64); 
    6767    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  
    8168    tmp_str_len = strlen (tmp_str); 
    8269 
    8370    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 
    9178            while (g_ascii_isspace (tmp_str[loop])) 
    9279                loop++; 
    9380        } 
     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        } 
    9486        /* cppcheck-suppress invalidscanf */ 
    9587        else if (sscanf (tmp_str + loop, "%x%n", &val, &ptr) == 1) 
    9688        {