From 3533e9dd63a648188bb72f511de73c49d72024e5 Mon Sep 17 00:00:00 2001 From: "Victor M. Alvarez" Date: Mon, 4 Jan 2021 13:34:47 +0100 Subject: [PATCH] Fix some warnings. --- libyara/arena.c | 4 ++-- libyara/exec.c | 2 +- libyara/filemap.c | 2 +- libyara/grammar.c | 8 ++++---- libyara/grammar.y | 8 ++++---- libyara/include/yara/arena.h | 6 +++--- libyara/modules/dotnet/dotnet.c | 4 ++-- libyara/rules.c | 2 +- libyara/scan.c | 9 +++++---- 9 files changed, 23 insertions(+), 22 deletions(-) diff --git a/libyara/arena.c b/libyara/arena.c index a97b6b7a..006a09ee 100644 --- a/libyara/arena.c +++ b/libyara/arena.c @@ -223,7 +223,7 @@ static int _yr_arena_allocate_memory( // ERROR_INSUFFICIENT_MEMORY // int yr_arena_create( - int number_of_buffers, + uint32_t num_buffers, size_t initial_buffer_size, YR_ARENA** arena) { @@ -233,7 +233,7 @@ int yr_arena_create( return ERROR_INSUFFICIENT_MEMORY; new_arena->xrefs = 1; - new_arena->num_buffers = number_of_buffers; + new_arena->num_buffers = num_buffers; new_arena->initial_buffer_size = initial_buffer_size; *arena = new_arena; diff --git a/libyara/exec.c b/libyara/exec.c index 9f9c5c0d..2a925e7d 100644 --- a/libyara/exec.c +++ b/libyara/exec.c @@ -475,7 +475,7 @@ int yr_execute_code(YR_SCAN_CONTEXT* context) pop(r1); r3.p = yr_notebook_alloc( - it_notebook, sizeof(YR_ITERATOR) + sizeof(uint64_t) * r1.i); + it_notebook, sizeof(YR_ITERATOR) + sizeof(uint64_t) * (size_t) r1.i); if (r3.p == NULL) { diff --git a/libyara/filemap.c b/libyara/filemap.c index 8e349b2f..b0a3872c 100644 --- a/libyara/filemap.c +++ b/libyara/filemap.c @@ -110,7 +110,7 @@ YR_API int yr_filemap_map_fd( return ERROR_COULD_NOT_OPEN_FILE; } - if (offset > file_size) + if (offset > (off_t) file_size) return ERROR_COULD_NOT_MAP_FILE; if (size == 0) diff --git a/libyara/grammar.c b/libyara/grammar.c index 53b01589..dcc39bff 100644 --- a/libyara/grammar.c +++ b/libyara/grammar.c @@ -2312,8 +2312,8 @@ yyreduce: fail_if_error(result); (yyval.modifier).flags = STRING_FLAGS_XOR; - (yyval.modifier).xor_min = (yyvsp[-1].integer); - (yyval.modifier).xor_max = (yyvsp[-1].integer); + (yyval.modifier).xor_min = (uint8_t) (yyvsp[-1].integer); + (yyval.modifier).xor_max = (uint8_t) (yyvsp[-1].integer); } #line 2319 "grammar.c" /* yacc.c:1663 */ break; @@ -2347,8 +2347,8 @@ yyreduce: fail_if_error(result); (yyval.modifier).flags = STRING_FLAGS_XOR; - (yyval.modifier).xor_min = (yyvsp[-3].integer); - (yyval.modifier).xor_max = (yyvsp[-1].integer); + (yyval.modifier).xor_min = (uint8_t) (yyvsp[-3].integer); + (yyval.modifier).xor_max = (uint8_t) (yyvsp[-1].integer); } #line 2354 "grammar.c" /* yacc.c:1663 */ break; diff --git a/libyara/grammar.y b/libyara/grammar.y index 7e57e6f4..d95f8c07 100644 --- a/libyara/grammar.y +++ b/libyara/grammar.y @@ -741,8 +741,8 @@ string_modifier fail_if_error(result); $$.flags = STRING_FLAGS_XOR; - $$.xor_min = $3; - $$.xor_max = $3; + $$.xor_min = (uint8_t) $3; + $$.xor_max = (uint8_t) $3; } /* * Would love to use range here for consistency in the language but that @@ -777,8 +777,8 @@ string_modifier fail_if_error(result); $$.flags = STRING_FLAGS_XOR; - $$.xor_min = $3; - $$.xor_max = $5; + $$.xor_min = (uint8_t) $3; + $$.xor_max = (uint8_t) $5; } | _BASE64_ { diff --git a/libyara/include/yara/arena.h b/libyara/include/yara/arena.h index 68bac29c..cc43654f 100644 --- a/libyara/include/yara/arena.h +++ b/libyara/include/yara/arena.h @@ -143,10 +143,10 @@ struct YR_ARENA // created, and can be incremented by calling yr_arena_acquire. On each call // to yr_arena_release it gets decremented by one, if xrefs reaches zero // the buffers and the YR_ARENA structures are freed. - int xrefs; + uint32_t xrefs; // Number of buffers in this arena. - int num_buffers; + uint32_t num_buffers; // Status of individual buffers. YR_ARENA_BUFFER buffers[YR_MAX_ARENA_BUFFERS]; @@ -165,7 +165,7 @@ struct YR_ARENA // it. Initially each buffer is empty, the first time that some data is written // into a buffer at least initial_buffer_size are reserved for the buffer. int yr_arena_create( - int num_buffers, + uint32_t num_buffers, size_t initial_buffer_size, YR_ARENA** arena); diff --git a/libyara/modules/dotnet/dotnet.c b/libyara/modules/dotnet/dotnet.c index bc600b83..4d137e1f 100644 --- a/libyara/modules/dotnet/dotnet.c +++ b/libyara/modules/dotnet/dotnet.c @@ -1608,7 +1608,7 @@ void dotnet_parse_tilde( streams); } -void dotnet_parse_com(PE* pe, size_t base_address) +void dotnet_parse_com(PE* pe) { PIMAGE_DATA_DIRECTORY directory; PCLI_HEADER cli_header; @@ -1795,7 +1795,7 @@ int module_load( module_object->data = pe; - dotnet_parse_com(pe, block->base); + dotnet_parse_com(pe); break; } diff --git a/libyara/rules.c b/libyara/rules.c index 107fd397..df7f1507 100644 --- a/libyara/rules.c +++ b/libyara/rules.c @@ -452,7 +452,7 @@ YR_API int yr_rules_get_stats(YR_RULES* rules, YR_RULES_STATS* stats) float match_list_length_sum = 0; int c = 0; - for (int i = 0; i < stats->ac_tables_size; i++) + for (uint32_t i = 0; i < stats->ac_tables_size; i++) { int match_list_length = 0; diff --git a/libyara/scan.c b/libyara/scan.c index 5be34dfe..781a568c 100644 --- a/libyara/scan.c +++ b/libyara/scan.c @@ -36,9 +36,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include #include #include -#include #include #include @@ -546,7 +546,8 @@ static int _yr_scan_verify_chained_string_match( match->match_length = (int32_t)( match_offset - match->offset + match_length); - match->data_length = yr_min(match->match_length, max_match_data); + match->data_length = yr_min( + match->match_length, (int32_t) max_match_data); match->data = yr_notebook_alloc( context->matches_notebook, match->data_length); @@ -584,7 +585,7 @@ static int _yr_scan_verify_chained_string_match( // A copy of the matching data is written to the matches_arena, the // amount of data copies is limited by YR_CONFIG_MAX_MATCH_DATA. - new_match->data_length = yr_min(match_length, max_match_data); + new_match->data_length = yr_min(match_length, (int32_t) max_match_data); if (new_match->data_length > 0) { @@ -702,7 +703,7 @@ static int _yr_scan_match_callback( goto _exit; } - new_match->data_length = yr_min(match_length, max_match_data); + new_match->data_length = yr_min(match_length, (int32_t) max_match_data); if (new_match->data_length > 0) {