Ticket #3694: 3694-0007-mc_search__hex_translate_to_regex-avoid-string-dupli.patch

File 3694-0007-mc_search__hex_translate_to_regex-avoid-string-dupli.patch, 1.3 KB (added by mooffie, 7 years ago)
  • lib/search/hex.c

    From c59b4880e4b14979d562ae10b6365546a9b98242 Mon Sep 17 00:00:00 2001
    From: Mooffie <mooffie@gmail.com>
    Date: Mon, 26 Sep 2016 00:51:22 +0300
    Subject: [PATCH 7/8] (mc_search__hex_translate_to_regex): avoid string
     duplication.
    
    We can read from the source string directly, as we no longer modify it.
    ---
     lib/search/hex.c | 8 +++-----
     1 file changed, 3 insertions(+), 5 deletions(-)
    
    diff --git a/lib/search/hex.c b/lib/search/hex.c
    index 14d0246..a0a3c19 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; 
     61    const char *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); 
    67     tmp_str = g_strndup (astr->str, astr->len); 
    68     tmp_str_len = strlen (tmp_str); 
     67    tmp_str = astr->str; 
     68    tmp_str_len = astr->len; 
    6969 
    7070    while (loop < tmp_str_len && error == MC_SEARCH_HEX_E_OK) 
    7171    { 
    mc_search__hex_translate_to_regex (const GString * astr, mc_search_hex_parse_err 
    119119            error = MC_SEARCH_HEX_E_INVALID_CHARACTER; 
    120120    } 
    121121 
    122     g_free (tmp_str); 
    123  
    124122    if (error != MC_SEARCH_HEX_E_OK) 
    125123    { 
    126124        g_string_free (buff, TRUE);