Skip to content

Commit

Permalink
Fixed incorrect operator precedence
Browse files Browse the repository at this point in the history
Before this commit, if __optr is == or !=, the if condition on line 1052
is unintendedly interpreted as
  ((real_t)(opndv1.data.integer __optr opndv2.data.integer) == (real_t)opndv1.data.integer)
    __optr
  (real_t)opndv2.data.integer
because the associativity of != and == operators in C is left-to-right.
Fixed by fully parenthesize the complex comparison expression.
  • Loading branch information
szsam committed Mar 25, 2024
1 parent f5aba59 commit 42d38ac
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion core/my_basic.c
Original file line number Diff line number Diff line change
Expand Up @@ -1049,7 +1049,7 @@ static _object_t* _exp_assign = 0;
do { \
_instruct_common(__tuple) \
if(opndv1.type == _DT_INT && opndv2.type == _DT_INT) { \
if((real_t)(opndv1.data.integer __optr opndv2.data.integer) == (real_t)opndv1.data.integer __optr (real_t)opndv2.data.integer) { \
if((real_t)(opndv1.data.integer __optr opndv2.data.integer) == ((real_t)opndv1.data.integer __optr (real_t)opndv2.data.integer)) { \
val->type = _DT_INT; \
val->data.integer = opndv1.data.integer __optr opndv2.data.integer; \
} else { \
Expand Down

0 comments on commit 42d38ac

Please sign in to comment.