[Forensics-changes] [yara] 81/407: Fix multiple warnings when compiling as C++

Hilko Bengen bengen at moszumanska.debian.org
Sat Jul 1 10:28:12 UTC 2017


This is an automated email from the git hooks/post-receive script.

bengen pushed a commit to annotated tag v3.3.0
in repository yara.

commit 09b306fe3a1cef8e5dbddc3b42e14b23258171d3
Author: Victor M. Alvarez <plusvic at gmail.com>
Date:   Tue Oct 7 16:17:14 2014 +0200

    Fix multiple warnings when compiling as C++
---
 libyara/ahocorasick.c        |  2 +-
 libyara/arena.c              | 14 +++++++-------
 libyara/atoms.c              | 18 +++++++++---------
 libyara/compiler.c           | 19 ++++++++++---------
 libyara/hash.c               |  2 +-
 libyara/include/yara/atoms.h |  8 ++++----
 libyara/include/yara/pe.h    | 10 ++++++----
 libyara/modules/cuckoo.c     |  3 +++
 libyara/modules/pe.c         |  7 +++----
 libyara/object.c             | 19 ++++++++++++-------
 libyara/parser.c             | 12 ++++++------
 libyara/re.c                 | 16 ++++++++--------
 libyara/rules.c              |  2 +-
 libyara/scan.c               |  2 +-
 14 files changed, 72 insertions(+), 62 deletions(-)

diff --git a/libyara/ahocorasick.c b/libyara/ahocorasick.c
index 70c09ab..662f5f6 100644
--- a/libyara/ahocorasick.c
+++ b/libyara/ahocorasick.c
@@ -65,7 +65,7 @@ int _yr_ac_queue_push(
 {
   QUEUE_NODE* pushed_node;
 
-  pushed_node = yr_malloc(sizeof(QUEUE_NODE));
+  pushed_node = (QUEUE_NODE*) yr_malloc(sizeof(QUEUE_NODE));
 
   if (pushed_node == NULL)
     return ERROR_INSUFICIENT_MEMORY;
diff --git a/libyara/arena.c b/libyara/arena.c
index 85df78f..e5126c5 100644
--- a/libyara/arena.c
+++ b/libyara/arena.c
@@ -79,7 +79,7 @@ YR_ARENA_PAGE* _yr_arena_new_page(
   if (new_page == NULL)
     return NULL;
 
-  new_page->address = yr_malloc(size);
+  new_page->address = (uint8_t*) yr_malloc(size);
 
   if (new_page->address == NULL)
   {
@@ -181,7 +181,7 @@ int _yr_arena_make_relocatable(
   {
     assert(base_offset + offset <= page->used - sizeof(int64_t));
 
-    reloc = yr_malloc(sizeof(YR_RELOC));
+    reloc = (YR_RELOC*) yr_malloc(sizeof(YR_RELOC));
 
     if (reloc == NULL)
       return ERROR_INSUFICIENT_MEMORY;
@@ -509,7 +509,7 @@ int yr_arena_reserve_memory(
 {
   YR_ARENA_PAGE* new_page;
   size_t new_page_size;
-  void* new_page_address;
+  uint8_t* new_page_address;
 
   if (size > free_space(arena->current_page))
   {
@@ -528,7 +528,7 @@ int yr_arena_reserve_memory(
     {
       // Current page is not used at all, it can be reallocated.
 
-      new_page_address = yr_realloc(
+      new_page_address = (uint8_t*) yr_realloc(
           arena->current_page->address,
           new_page_size);
 
@@ -830,7 +830,7 @@ int yr_arena_duplicate(
 
   while (reloc != NULL)
   {
-    new_reloc = yr_malloc(sizeof(YR_RELOC));
+    new_reloc = (YR_RELOC*) yr_malloc(sizeof(YR_RELOC));
 
     if (new_reloc == NULL)
       return ERROR_INSUFICIENT_MEMORY;
@@ -920,11 +920,11 @@ int yr_arena_save(
     {
       assert(reloc_target >= page->address);
       assert(reloc_target < page->address + page->used);
-      *reloc_address = (void*) (*reloc_address - page->address);
+      *reloc_address = (uint8_t*) (*reloc_address - page->address);
     }
     else
     {
-      *reloc_address = (void*) (size_t) 0xFFFABADA;
+      *reloc_address = (uint8_t*) (size_t) 0xFFFABADA;
     }
 
     reloc = reloc->next;
diff --git a/libyara/atoms.c b/libyara/atoms.c
index 2b89424..84119ed 100644
--- a/libyara/atoms.c
+++ b/libyara/atoms.c
@@ -375,7 +375,7 @@ int _yr_atoms_choose(
   {
   case ATOM_TREE_LEAF:
 
-    item = yr_malloc(sizeof(YR_ATOM_LIST_ITEM));
+    item = (YR_ATOM_LIST_ITEM*) yr_malloc(sizeof(YR_ATOM_LIST_ITEM));
 
     for (i = 0; i < node->atom_length; i++)
       item->atom[i] = node->atom[i];
@@ -548,7 +548,7 @@ int _yr_atoms_case_insentive(
 
     while (atom_length != 0)
     {
-      new_atom = yr_malloc(sizeof(YR_ATOM_LIST_ITEM));
+      new_atom = (YR_ATOM_LIST_ITEM*) yr_malloc(sizeof(YR_ATOM_LIST_ITEM));
 
       if (new_atom == NULL)
         return ERROR_INSUFICIENT_MEMORY;
@@ -598,7 +598,7 @@ int _yr_atoms_wide(
 
   while (atom != NULL)
   {
-    new_atom = yr_malloc(sizeof(YR_ATOM_LIST_ITEM));
+    new_atom = (YR_ATOM_LIST_ITEM*) yr_malloc(sizeof(YR_ATOM_LIST_ITEM));
 
     if (new_atom == NULL)
       return ERROR_INSUFICIENT_MEMORY;
@@ -857,7 +857,7 @@ int yr_atoms_extract_triplets(
 
       for (i = 0; i < 256; i++)
       {
-        atom = yr_malloc(sizeof(YR_ATOM_LIST_ITEM));
+        atom = (YR_ATOM_LIST_ITEM*) yr_malloc(sizeof(YR_ATOM_LIST_ITEM));
 
         if (atom == NULL)
           return ERROR_INSUFICIENT_MEMORY;
@@ -888,7 +888,7 @@ int yr_atoms_extract_triplets(
 
       for (i = 0; i < 16; i++)
       {
-        atom = yr_malloc(sizeof(YR_ATOM_LIST_ITEM));
+        atom = (YR_ATOM_LIST_ITEM*) yr_malloc(sizeof(YR_ATOM_LIST_ITEM));
 
         if (atom == NULL)
           return ERROR_INSUFICIENT_MEMORY;
@@ -923,7 +923,7 @@ int yr_atoms_extract_triplets(
 
       for (i = 0; i < 256; i++)
       {
-        atom = yr_malloc(sizeof(YR_ATOM_LIST_ITEM));
+        atom = (YR_ATOM_LIST_ITEM*) yr_malloc(sizeof(YR_ATOM_LIST_ITEM));
 
         if (atom == NULL)
           return ERROR_INSUFICIENT_MEMORY;
@@ -954,7 +954,7 @@ int yr_atoms_extract_triplets(
 
       for (i = 0; i < 16; i++)
       {
-        atom = yr_malloc(sizeof(YR_ATOM_LIST_ITEM));
+        atom = (YR_ATOM_LIST_ITEM*) yr_malloc(sizeof(YR_ATOM_LIST_ITEM));
 
         if (atom == NULL)
           return ERROR_INSUFICIENT_MEMORY;
@@ -994,7 +994,7 @@ int yr_atoms_extract_from_re(
     int flags,
     YR_ATOM_LIST_ITEM** atoms)
 {
-  ATOM_TREE* atom_tree = yr_malloc(sizeof(ATOM_TREE));
+  ATOM_TREE* atom_tree = (ATOM_TREE*) yr_malloc(sizeof(ATOM_TREE));
   ATOM_TREE_NODE* temp;
   YR_ATOM_LIST_ITEM* wide_atoms;
   YR_ATOM_LIST_ITEM* case_insentive_atoms;
@@ -1093,7 +1093,7 @@ int yr_atoms_extract_from_string(
   int quality;
   int i, j, length;
 
-  item = yr_malloc(sizeof(YR_ATOM_LIST_ITEM));
+  item = (YR_ATOM_LIST_ITEM*) yr_malloc(sizeof(YR_ATOM_LIST_ITEM));
 
   if (item == NULL)
     return ERROR_INSUFICIENT_MEMORY;
diff --git a/libyara/compiler.c b/libyara/compiler.c
index 4a8ee03..c35de8b 100644
--- a/libyara/compiler.c
+++ b/libyara/compiler.c
@@ -26,6 +26,7 @@ limitations under the License.
 #include <yara/mem.h>
 #include <yara/object.h>
 #include <yara/lexer.h>
+#include <yara/strutils.h>
 
 
 int yr_compiler_create(
@@ -268,7 +269,7 @@ int _yr_compiler_set_namespace(
   int i;
   int found;
 
-  ns = yr_arena_base_address(compiler->namespaces_arena);
+  ns = (YR_NAMESPACE*) yr_arena_base_address(compiler->namespaces_arena);
   found = FALSE;
 
   for (i = 0; i < compiler->namespaces_count; i++)
@@ -279,7 +280,7 @@ int _yr_compiler_set_namespace(
       break;
     }
 
-    ns = yr_arena_next_address(
+    ns = (YR_NAMESPACE*) yr_arena_next_address(
         compiler->namespaces_arena,
         ns,
         sizeof(YR_NAMESPACE));
@@ -296,7 +297,7 @@ int _yr_compiler_set_namespace(
       result = yr_arena_allocate_struct(
           compiler->namespaces_arena,
           sizeof(YR_NAMESPACE),
-          (void*) &ns,
+          (void**) &ns,
           offsetof(YR_NAMESPACE, name),
           EOL);
 
@@ -414,16 +415,16 @@ int _yr_compiler_compile_rules(
 
   if (result == ERROR_SUCCESS)
   {
-    rules_file_header->rules_list_head = yr_arena_base_address(
+    rules_file_header->rules_list_head = (YR_RULE*) yr_arena_base_address(
         compiler->rules_arena);
 
-    rules_file_header->externals_list_head = yr_arena_base_address(
-        compiler->externals_arena);
+    rules_file_header->externals_list_head = (YR_EXTERNAL_VARIABLE*) 
+		yr_arena_base_address(compiler->externals_arena);
 
-    rules_file_header->code_start = yr_arena_base_address(
+    rules_file_header->code_start = (uint8_t*) yr_arena_base_address(
         compiler->code_arena);
 
-    rules_file_header->automaton = yr_arena_base_address(
+    rules_file_header->automaton = (YR_AC_AUTOMATON*) yr_arena_base_address(
         compiler->automaton_arena);
   }
 
@@ -519,7 +520,7 @@ int yr_compiler_get_rules(
   if (compiler->compiled_rules_arena == NULL)
      FAIL_ON_ERROR(_yr_compiler_compile_rules(compiler));
 
-  yara_rules = yr_malloc(sizeof(YR_RULES));
+  yara_rules = (YR_RULES*) yr_malloc(sizeof(YR_RULES));
 
   if (yara_rules == NULL)
     return ERROR_INSUFICIENT_MEMORY;
diff --git a/libyara/hash.c b/libyara/hash.c
index d8b0a36..dce5940 100644
--- a/libyara/hash.c
+++ b/libyara/hash.c
@@ -93,7 +93,7 @@ int yr_hash_table_create(
   YR_HASH_TABLE* new_table;
   int i;
 
-  new_table = yr_malloc(
+  new_table = (YR_HASH_TABLE*) yr_malloc(
       sizeof(YR_HASH_TABLE) + size * sizeof(YR_HASH_TABLE_ENTRY*));
 
   if (new_table == NULL)
diff --git a/libyara/include/yara/atoms.h b/libyara/include/yara/atoms.h
index afa3198..68c34b1 100644
--- a/libyara/include/yara/atoms.h
+++ b/libyara/include/yara/atoms.h
@@ -31,8 +31,8 @@ typedef struct _ATOM_TREE_NODE
   uint8_t atom_length;
   uint8_t atom[MAX_ATOM_LENGTH];
 
-  void* forward_code;
-  void* backward_code;
+  uint8_t* forward_code;
+  uint8_t* backward_code;
 
   RE_NODE* recent_nodes[MAX_ATOM_LENGTH];
 
@@ -58,8 +58,8 @@ typedef struct _YR_ATOM_LIST_ITEM
 
   uint16_t backtrack;
 
-  void* forward_code;
-  void* backward_code;
+  uint8_t* forward_code;
+  uint8_t* backward_code;
 
   struct _YR_ATOM_LIST_ITEM* next;
 
diff --git a/libyara/include/yara/pe.h b/libyara/include/yara/pe.h
index 850067a..b8572b1 100644
--- a/libyara/include/yara/pe.h
+++ b/libyara/include/yara/pe.h
@@ -14,6 +14,8 @@ See the License for the specific language governing permissions and
 limitations under the License.
 */
 
+#ifndef _WIN32
+
 #include <stdint.h>
 #include <stdlib.h>
 
@@ -371,6 +373,10 @@ typedef struct _IMAGE_RESOURCE_DIRECTORY {
 } IMAGE_RESOURCE_DIRECTORY, *PIMAGE_RESOURCE_DIRECTORY;
 
 
+#endif  // _WIN32
+
+#include <windows.h>
+
 typedef struct _VERSION_INFO {
     WORD   Length;
     WORD   ValueLength;
@@ -378,8 +384,4 @@ typedef struct _VERSION_INFO {
     char   Key[0];
 } VERSION_INFO, *PVERSION_INFO;
 
-
-
-
-
 #pragma pack(pop)
diff --git a/libyara/modules/cuckoo.c b/libyara/modules/cuckoo.c
index 96dec9c..77295f4 100644
--- a/libyara/modules/cuckoo.c
+++ b/libyara/modules/cuckoo.c
@@ -21,6 +21,9 @@ limitations under the License.
 #include <yara/re.h>
 #include <yara/modules.h>
 
+#ifdef _WIN32
+#define strcasecmp _stricmp
+#endif
 
 #define MODULE_NAME cuckoo
 
diff --git a/libyara/modules/pe.c b/libyara/modules/pe.c
index 54a4cfd..d0660bc 100644
--- a/libyara/modules/pe.c
+++ b/libyara/modules/pe.c
@@ -14,11 +14,7 @@ See the License for the specific language governing permissions and
 limitations under the License.
 */
 
-#ifdef _WIN32
-#include <windows.h>
-#else
 #include <yara/pe.h>
-#endif
 
 #include <yara/modules.h>
 #include <yara/mem.h>
@@ -322,6 +318,9 @@ int pe_iterate_resources(
   return 0;
 }
 
+#ifdef __cplusplus
+#define typeof decltype
+#endif
 
 // Align offset to a 32-bit boundary and add it to a pointer
 
diff --git a/libyara/object.c b/libyara/object.c
index 49bc25c..f5f2c94 100644
--- a/libyara/object.c
+++ b/libyara/object.c
@@ -20,8 +20,12 @@ limitations under the License.
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <inttypes.h>
 
+#if _WIN32
+#define PRIu64 "%I64d"
+#else
+#include <inttypes.h>
+#endif
 
 #include <yara/mem.h>
 #include <yara/error.h>
@@ -594,7 +598,7 @@ int yr_object_structure_set_member(
   if (yr_object_lookup_field(object,  member->identifier) != NULL)
     return ERROR_DUPLICATED_STRUCTURE_MEMBER;
 
-  sm = yr_malloc(sizeof(YR_STRUCTURE_MEMBER));
+  sm = (YR_STRUCTURE_MEMBER*) yr_malloc(sizeof(YR_STRUCTURE_MEMBER));
 
   if (sm == NULL)
     return ERROR_INSUFICIENT_MEMORY;
@@ -654,7 +658,7 @@ int yr_object_array_set_item(
   {
     count = max(64, (index + 1) * 2);
 
-    array->items = yr_malloc(
+    array->items = (YR_ARRAY_ITEMS*) yr_malloc(
         sizeof(YR_ARRAY_ITEMS) + count * sizeof(YR_OBJECT*));
 
     if (array->items == NULL)
@@ -667,7 +671,7 @@ int yr_object_array_set_item(
   else if (index >= array->items->count)
   {
     count = array->items->count * 2;
-    array->items = yr_realloc(
+    array->items = (YR_ARRAY_ITEMS*) yr_realloc(
         array->items,
         sizeof(YR_ARRAY_ITEMS) + count * sizeof(YR_OBJECT*));
 
@@ -738,7 +742,7 @@ int yr_object_dict_set_item(
   {
     count = 64;
 
-    dict->items = yr_malloc(
+    dict->items = (YR_DICTIONARY_ITEMS*) yr_malloc(
         sizeof(YR_DICTIONARY_ITEMS) + count * sizeof(dict->items->objects[0]));
 
     if (dict->items == NULL)
@@ -752,7 +756,7 @@ int yr_object_dict_set_item(
   else if (dict->items->free == 0)
   {
     count = dict->items->used * 2;
-    dict->items = yr_realloc(
+    dict->items = (YR_DICTIONARY_ITEMS*) yr_realloc(
         dict->items,
         sizeof(YR_DICTIONARY_ITEMS) + count * sizeof(dict->items->objects[0]));
 
@@ -905,6 +909,7 @@ void yr_object_print_data(
 {
   YR_DICTIONARY_ITEMS* dict_items;
   YR_ARRAY_ITEMS* array_items;
+  YR_STRUCTURE_MEMBER* member;
 
   char indent_spaces[32];
 
@@ -939,7 +944,7 @@ void yr_object_print_data(
           indent_spaces,
           object->identifier);
 
-      YR_STRUCTURE_MEMBER* member = ((YR_OBJECT_STRUCTURE*) object)->members;
+      member = ((YR_OBJECT_STRUCTURE*) object)->members;
 
       while (member != NULL)
       {
diff --git a/libyara/parser.c b/libyara/parser.c
index 94cbad7..6efd96c 100644
--- a/libyara/parser.c
+++ b/libyara/parser.c
@@ -147,7 +147,7 @@ int yr_parser_emit_pushes_for_strings(
       }
     }
 
-    string = yr_arena_next_address(
+    string = (YR_STRING*) yr_arena_next_address(
         compiler->strings_arena,
         string,
         sizeof(YR_STRING));
@@ -209,7 +209,7 @@ YR_STRING* yr_parser_lookup_string(
       return string;
     }
 
-    string = yr_arena_next_address(
+    string = (YR_STRING*) yr_arena_next_address(
         compiler->strings_arena,
         string,
         sizeof(YR_STRING));
@@ -318,7 +318,7 @@ int _yr_parser_write_string(
         compiler->sz_arena,
         literal_string->c_string,
         literal_string->length,
-        (void*) &(*string)->string);
+        (void**) &(*string)->string);
 
     if (result == ERROR_SUCCESS)
     {
@@ -645,7 +645,7 @@ int yr_parser_reduce_rule_declaration(
       break;
     }
 
-    string = yr_arena_next_address(
+    string = (YR_STRING*) yr_arena_next_address(
         compiler->strings_arena,
         string,
         sizeof(YR_STRING));
@@ -746,7 +746,7 @@ int yr_parser_reduce_string_identifier(
           string->g_flags &= ~STRING_GFLAGS_FIXED_OFFSET;
         }
 
-        string = yr_arena_next_address(
+        string = (YR_STRING*) yr_arena_next_address(
             compiler->strings_arena,
             string,
             sizeof(YR_STRING));
@@ -861,7 +861,7 @@ int yr_parser_reduce_import(
 
   char* name;
 
-  module_structure = yr_hash_table_lookup(
+  module_structure = (YR_OBJECT*) yr_hash_table_lookup(
       compiler->objects_table,
       module_name->c_string,
       compiler->current_namespace->name);
diff --git a/libyara/re.c b/libyara/re.c
index 78614b9..c1382f1 100644
--- a/libyara/re.c
+++ b/libyara/re.c
@@ -142,9 +142,9 @@ int yr_re_finalize_thread(void)
   RE_THREAD_STORAGE* storage;
 
   #ifdef _WIN32
-  storage = TlsGetValue(thread_storage_key);
+  storage = (RE_THREAD_STORAGE*) TlsGetValue(thread_storage_key);
   #else
-  storage = pthread_getspecific(thread_storage_key);
+  storage = (RE_THREAD_STORAGE*) pthread_getspecific(thread_storage_key);
   #endif
 
   if (storage != NULL)
@@ -176,7 +176,7 @@ RE_NODE* yr_re_node_create(
     RE_NODE* left,
     RE_NODE* right)
 {
-  RE_NODE* result = yr_malloc(sizeof(RE_NODE));
+  RE_NODE* result = (RE_NODE*) yr_malloc(sizeof(RE_NODE));
 
   if (result != NULL)
   {
@@ -386,7 +386,7 @@ SIZED_STRING* yr_re_extract_literal(
     node = node->left;
   }
 
-  string = yr_malloc(sizeof(SIZED_STRING) + length);
+  string = (SIZED_STRING*) yr_malloc(sizeof(SIZED_STRING) + length);
 
   if (string == NULL)
     return NULL;
@@ -1105,14 +1105,14 @@ int _yr_re_alloc_storage(
     RE_THREAD_STORAGE** storage)
 {
   #ifdef _WIN32
-  *storage = TlsGetValue(thread_storage_key);
+  *storage = (RE_THREAD_STORAGE*) TlsGetValue(thread_storage_key);
   #else
-  *storage = pthread_getspecific(thread_storage_key);
+  *storage = (RE_THREAD_STORAGE*) pthread_getspecific(thread_storage_key);
   #endif
 
   if (*storage == NULL)
   {
-    *storage = yr_malloc(sizeof(RE_THREAD_STORAGE));
+    *storage = (RE_THREAD_STORAGE*) yr_malloc(sizeof(RE_THREAD_STORAGE));
 
     if (*storage == NULL)
       return ERROR_INSUFICIENT_MEMORY;
@@ -1145,7 +1145,7 @@ RE_FIBER* _yr_re_fiber_create(
   }
   else
   {
-    fiber = yr_malloc(sizeof(RE_FIBER));
+    fiber = (RE_FIBER*) yr_malloc(sizeof(RE_FIBER));
   }
 
   if (fiber != NULL)
diff --git a/libyara/rules.c b/libyara/rules.c
index bea56cb..31ddf5a 100644
--- a/libyara/rules.c
+++ b/libyara/rules.c
@@ -588,7 +588,7 @@ int yr_rules_load(
 
   int result;
 
-  new_rules = yr_malloc(sizeof(YR_RULES));
+  new_rules = (YR_RULES*) yr_malloc(sizeof(YR_RULES));
 
   if (new_rules == NULL)
     return ERROR_INSUFICIENT_MEMORY;
diff --git a/libyara/scan.c b/libyara/scan.c
index 6966ecd..0b38928 100644
--- a/libyara/scan.c
+++ b/libyara/scan.c
@@ -548,7 +548,7 @@ int _yr_scan_match_callback(
     int flags,
     void* args)
 {
-  CALLBACK_ARGS* callback_args = args;
+  CALLBACK_ARGS* callback_args = (CALLBACK_ARGS*) args;
 
   YR_STRING* string = callback_args->string;
   YR_MATCH* new_match;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/forensics/yara.git



More information about the forensics-changes mailing list