[Forensics-changes] [yara] 189/192: Prevent warning due to possible loss of data while converting size_t to int16_t

Hilko Bengen bengen at moszumanska.debian.org
Sat Jul 1 10:32:05 UTC 2017


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

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

commit 75fba43bbf0a0fdb288f9e25e7de8520525c9760
Author: Victor M. Alvarez <plusvic at gmail.com>
Date:   Fri May 19 13:55:48 2017 +0200

    Prevent warning due to possible loss of data while converting size_t to int16_t
---
 libyara/re.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/libyara/re.c b/libyara/re.c
index f9f5cf3..de20324 100644
--- a/libyara/re.c
+++ b/libyara/re.c
@@ -1016,8 +1016,10 @@ int _yr_re_emit(
 
     *code_size += jmp_size;
 
+    assert(split_size + branch_size + jmp_size < INT16_MAX);
+
     // Update split offset.
-    *split_offset_addr = split_size + branch_size + jmp_size;
+    *split_offset_addr = (int16_t) (split_size + branch_size + jmp_size);
     break;
 
   case RE_NODE_ALT:
@@ -1065,8 +1067,10 @@ int _yr_re_emit(
 
     *code_size += jmp_size;
 
+    assert(split_size + branch_size + jmp_size < INT16_MAX);
+
     // Update split offset.
-    *split_offset_addr = split_size + branch_size + jmp_size;
+    *split_offset_addr = (int16_t) (split_size + branch_size + jmp_size);
 
     FAIL_ON_ERROR(_yr_re_emit(
         emit_context,
@@ -1077,8 +1081,10 @@ int _yr_re_emit(
 
     *code_size += branch_size;
 
+    assert(branch_size + jmp_size < INT16_MAX);
+
     // Update offset for jmp instruction.
-    *jmp_offset_addr = branch_size + jmp_size;
+    *jmp_offset_addr = (int16_t) (branch_size + jmp_size);
     break;
 
   case RE_NODE_RANGE_ANY:
@@ -1248,7 +1254,10 @@ int _yr_re_emit(
     }
 
     if (emit_split)
-      *split_offset_addr = split_size + branch_size;
+    {
+      assert(split_size + branch_size  < INT16_MAX);
+      *split_offset_addr = (int16_t) (split_size + branch_size);
+    }
 
     break;
   }

-- 
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