[Forensics-changes] [yara] 287/407: Implement a cleaner solution to push_dbl and pop_dbl and avoid warnings.
Hilko Bengen
bengen at moszumanska.debian.org
Sat Jul 1 10:28:37 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 2fcfa8608c2b34dce5c660f0384d6580a4ce49bb
Author: Victor M. Alvarez <plusvic at gmail.com>
Date: Wed Dec 31 13:29:18 2014 +0100
Implement a cleaner solution to push_dbl and pop_dbl and avoid warnings.
The previous implementation of pop_dbl (x = *(double*) &stack[--sp]) was causing the following warning:
dereferencing type-punned pointer will break strict-aliasing rules
---
libyara/exec.c | 43 +++++++++++++------------------------------
1 file changed, 13 insertions(+), 30 deletions(-)
diff --git a/libyara/exec.c b/libyara/exec.c
index 35a5d05..f160b97 100644
--- a/libyara/exec.c
+++ b/libyara/exec.c
@@ -35,33 +35,25 @@ limitations under the License.
#define STACK_SIZE 16384
#define MEM_SIZE MAX_LOOP_NESTING * LOOP_LOCAL_VARS
+union STACK_ITEM {
+ int64_t i;
+ double d;
+};
#define push(x) \
do { \
- if (sp < STACK_SIZE) stack[sp++] = (x); \
+ if (sp < STACK_SIZE) stack[sp++].i = (x); \
else return ERROR_EXEC_STACK_OVERFLOW; \
} while(0)
-
-// Used when pushing a double to the stack, which looses precision when
-// using push().
#define push_dbl(x) \
do { \
- if (sp < STACK_SIZE) \
- { \
- dsp = (double*) (stack + sp); \
- *dsp = (x); \
- sp++; \
- } \
+ if (sp < STACK_SIZE) stack[sp++].d = (x); \
else return ERROR_EXEC_STACK_OVERFLOW; \
} while(0)
-
-#define pop(x) x = stack[--sp]
-
-
-#define pop_dbl(x) x = *(double*) &stack[--sp]
-
+#define pop(x) x = stack[--sp].i
+#define pop_dbl(x) x = stack[--sp].d
// The _rel() variants are used to push or pop at specific offsets from sp.
// This is useful when you need have a stack with an integer that needs to be
@@ -70,27 +62,18 @@ limitations under the License.
//
// pop_rel(2, r1)
// push_dbl_rel(2, r1)
-#define push_rel(offset, x) \
- do { \
- if (offset <= 0 || sp - offset < 0) return ERROR_EXEC_STACK_OVERFLOW; \
- else stack[sp - offset] = (x); \
- } while(0)
-
#define push_dbl_rel(offset, x) \
do { \
if (offset <= 0 || sp - offset < 0) return ERROR_EXEC_STACK_OVERFLOW; \
- else \
- { \
- dsp = (double *) ((stack + sp) - offset); \
- *dsp = (x); \
- } \
+ else stack[sp - offset].d = (x); \
} while(0)
+
#define pop_rel(offset, x) \
do { \
if (offset < 0 || sp - offset < 0) return ERROR_EXEC_STACK_OVERFLOW; \
- else x = stack[sp - offset]; \
+ else x = stack[sp - offset].i; \
} while(0)
@@ -171,12 +154,12 @@ int yr_execute_code(
double dr1;
double dr2;
int64_t mem[MEM_SIZE];
- int64_t stack[STACK_SIZE];
- double* dsp = 0;
int64_t args[MAX_FUNCTION_ARGS];
int32_t sp = 0;
uint8_t* ip = rules->code_start;
+ union STACK_ITEM stack[STACK_SIZE];
+
YR_RULE* rule;
YR_STRING* string;
YR_MATCH* 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