From fdc9b6a3841d7346dab6f4aeea06322be0d3ee95 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Mon, 14 Nov 2022 22:10:12 +0100 Subject: compiler: fix `??=`, `||=` and `&&=` logical assignment semantics When compiling logical assignment expressions, ensure that the right hand side of the assignment is not evaluated when the assignment condition is unfulfilled. Signed-off-by: Jo-Philipp Wich --- vm.c | 28 ---------------------------- 1 file changed, 28 deletions(-) (limited to 'vm.c') diff --git a/vm.c b/vm.c index 3bf9836..5bc071b 100644 --- a/vm.c +++ b/vm.c @@ -1408,31 +1408,6 @@ uc_vm_value_bitop(uc_vm_t *vm, uc_vm_insn_t operation, uc_value_t *value, uc_val return rv; } -static uc_value_t * -uc_vm_value_logical(uc_vm_t *vm, uc_vm_insn_t operation, uc_value_t *value, uc_value_t *operand) -{ - uc_value_t *rv = NULL; - - switch (operation) { - case I_LTRUE: - rv = ucv_get(ucv_is_truish(value) ? operand : value); - break; - - case I_LFALSE: - rv = ucv_get(ucv_is_truish(value) ? value : operand); - break; - - case I_LNULL: - rv = ucv_get(value == NULL ? operand : value); - break; - - default: - break; - } - - return rv; -} - static uc_value_t * uc_vm_string_concat(uc_vm_t *vm, uc_value_t *v1, uc_value_t *v2) { @@ -1492,9 +1467,6 @@ uc_vm_value_arith(uc_vm_t *vm, uc_vm_insn_t operation, uc_value_t *value, uc_val operation == I_BAND || operation == I_BXOR || operation == I_BOR) return uc_vm_value_bitop(vm, operation, value, operand); - if (operation == I_LTRUE || operation == I_LFALSE || operation == I_LNULL) - return uc_vm_value_logical(vm, operation, value, operand); - if (operation == I_ADD && (ucv_type(value) == UC_STRING || ucv_type(operand) == UC_STRING)) return uc_vm_string_concat(vm, value, operand); -- cgit v1.2.3