GH-219: fix |x| operator int overflow / floating point type inconsistency

When 'x' is an integral arithmetic expression, it's now coerced to
yield a signed integer before taking the absolute value of it to
prevent the common issue of unsigned integer overflow/wraparound for
values below zero.

Using a time or interval value/expression for 'x' now also yields a
time or interval, respective, from the |x| operation instead of
a double.
This commit is contained in:
Jon Siwek 2019-01-22 16:42:40 -06:00
parent bebc0fba6d
commit 3256ac7c49
8 changed files with 21 additions and 6 deletions

View file

@ -1360,7 +1360,10 @@ SizeExpr::SizeExpr(Expr* arg_op) : UnaryExpr(EXPR_SIZE, arg_op)
if ( IsError() )
return;
SetType(base_type(TYPE_COUNT));
if ( op->Type()->InternalType() == TYPE_INTERNAL_DOUBLE )
SetType(op->Type()->Ref());
else
SetType(base_type(TYPE_COUNT));
}
Val* SizeExpr::Eval(Frame* f) const