mirror of
https://github.com/github/codeql.git
synced 2026-05-05 05:35:13 +02:00
QL code and tests for C#/C++/JavaScript.
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
| tst.js:2:9:2:24 | (x & (1<<n)) > 0 | Sign check of a bitwise operation |
|
||||
| tst.js:14:13:14:25 | (x >>> 0) > 0 | Sign check of a bitwise operation |
|
||||
| tst.js:23:1:23:21 | (x & 0x ... 00) > 0 | Sign check of a bitwise operation |
|
||||
@@ -0,0 +1 @@
|
||||
Expressions/BitwiseSignCheck.ql
|
||||
@@ -0,0 +1,23 @@
|
||||
function bitIsSet(x, n) {
|
||||
return (x & (1<<n)) > 0;
|
||||
}
|
||||
|
||||
console.log(bitIsSet(-1, 31)); // prints 'false'
|
||||
|
||||
(x & 3) > 0; // this is fine
|
||||
|
||||
// OK
|
||||
x = -1;
|
||||
console.log((x | 0) > (0)); // prints 'false'
|
||||
|
||||
// NOT OK
|
||||
console.log((x >>> 0) > 0); // prints 'true'
|
||||
|
||||
// OK
|
||||
console.log((x << 16 >> 16) > 0); // prints 'false'
|
||||
|
||||
// OK
|
||||
(x & 256) > 0;
|
||||
|
||||
// NOT OK
|
||||
(x & 0x100000000) > 0;
|
||||
Reference in New Issue
Block a user