Skip to content

Commit

Permalink
Make left or right shift by negative number return 0, instead of trig…
Browse files Browse the repository at this point in the history
…gering undefined behavior (fixes #515)
  • Loading branch information
Mytherin committed Apr 11, 2020
1 parent 0d29535 commit 7e1234d
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/function/scalar/operators/bitwise.cpp
Expand Up @@ -65,7 +65,7 @@ void BitwiseXorFun::RegisterFunction(BuiltinFunctions &set) {
//===--------------------------------------------------------------------===//
struct BitwiseShiftLeftOperator {
template <class TA, class TB, class TR> static inline TR Operation(TA left, TB right) {
return left << right;
return right < 0 ? 0 : left << right;
}
};

Expand All @@ -83,7 +83,7 @@ void LeftShiftFun::RegisterFunction(BuiltinFunctions &set) {
//===--------------------------------------------------------------------===//
struct BitwiseShiftRightOperator {
template <class TA, class TB, class TR> static inline TR Operation(TA left, TB right) {
return left >> right;
return right < 0 ? 0 : left >> right;
}
};

Expand Down

0 comments on commit 7e1234d

Please sign in to comment.