Skip to content

Commit 22d50f0

Browse files
authored
Merge pull request #3667 from aschackmull/java/compiletimeconstant-cast-eval
Approved by aibaars
2 parents 4b3ca13 + c334d72 commit 22d50f0

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

java/ql/src/semmle/code/java/Expr.qll

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -305,10 +305,6 @@ class CompileTimeConstantExpr extends Expr {
305305
/**
306306
* Gets the integer value of this expression, where possible.
307307
*
308-
* All computations are performed on QL 32-bit `int`s, so no
309-
* truncation is performed in the case of overflow within `byte` or `short`:
310-
* `((byte)127)+((byte)1)` evaluates to 128 rather than to -128.
311-
*
312308
* Note that this does not handle the following cases:
313309
*
314310
* - values of type `long`,
@@ -332,7 +328,10 @@ class CompileTimeConstantExpr extends Expr {
332328
else
333329
if cast.getType().hasName("short")
334330
then result = (val + 32768).bitAnd(65535) - 32768
335-
else result = val
331+
else
332+
if cast.getType().hasName("char")
333+
then result = val.bitAnd(65535)
334+
else result = val
336335
)
337336
or
338337
result = this.(PlusExpr).getExpr().(CompileTimeConstantExpr).getIntValue()

0 commit comments

Comments
 (0)