File tree Expand file tree Collapse file tree 2 files changed +12
-1
lines changed
test/query-tests/InconsistentCode/MistypedExponentiation Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Original file line number Diff line number Diff line change 1313
1414import go
1515
16+ private Expr getConstantInitialiser ( Expr e ) {
17+ exists ( DeclaredConstant c | e = c .getAReference ( ) | result = c .getInit ( ) )
18+ }
19+
1620/** Holds if `e` is not 0 and is either an octal or hexadecimal literal, or the number one. */
1721predicate maybeXorBitPattern ( Expr e ) {
1822 // 0 makes no sense as an xor bit pattern
1923 not e .getNumericValue ( ) = 0 and
2024 // include octal and hex literals
21- e .( IntLit ) .getText ( ) .matches ( "0%" )
25+ [ e , getConstantInitialiser ( e ) ] .( IntLit ) .getText ( ) .matches ( "0%" )
2226 or
2327 e .getNumericValue ( ) = 1
2428}
Original file line number Diff line number Diff line change @@ -22,6 +22,13 @@ func main() {
2222
2323 mask := (((1 << 10 ) - 1 ) ^ 7 ) // OK
2424
25+ const (
26+ c1 = 0x1234
27+ c2 = 0x5678
28+ )
29+
30+ fmt .Println (c1 ^ c2 ) // OK
31+
2532 // This is not ok, but isn't detected because the multiplication binds tighter
2633 // than the xor operator and so the query doesn't see a constant on the left
2734 // hand side of ^.
You can’t perform that action at this time.
0 commit comments