JavaScript: Teach ShiftOutOfRange about BigInt.

This commit is contained in:
Max Schaefer
2019-06-26 09:16:34 -07:00
parent 99c32f08fb
commit e35fde322b
4 changed files with 13 additions and 6 deletions

View File

@@ -14,7 +14,9 @@ greater than 31, the left operand is actually only shifted by that value modulo
<p>
Use standard library functions such as <code>Math.pow</code> to perform the required
shifting.
shifting. Alternatively, you can use the
<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt">BigInt</a>
type if it is available on your platform.
</p>
</recommendation>

View File

@@ -1,7 +1,7 @@
/**
* @name Shift out of range
* @description The shift operators '<<', '>>' and '>>>' only take the five least significant bits of their
* right operand into account. Thus, it is not possible to shift by more than 31 bits.
* @description The integer shift operators '<<', '>>' and '>>>' only take the five least significant bits of their
* right operand into account. Thus, it is not possible to shift an integer by more than 31 bits.
* @kind problem
* @problem.severity error
* @id js/shift-out-of-range
@@ -14,5 +14,7 @@
import javascript
from ShiftExpr shift
where shift.getRightOperand().getIntValue() > 31
where
shift.getRightOperand().getIntValue() > 31 and
not shift.getRightOperand().stripParens() instanceof BigIntLiteral
select shift, "Shift out of range."