@@ -239,39 +239,43 @@ private class AnalyzedBinaryExpr extends DataFlow::AnalyzedValueNode {
239
239
}
240
240
241
241
/**
242
- * Gets a primitive type to which the local value of `e` can be coerced .
242
+ * Gets the `n`th operand of the given `+` or `+=` expression .
243
243
*/
244
- private PrimitiveType getALocalPrimitiveType ( Expr e ) {
245
- result = e .analyze ( ) .getALocalValue ( ) .toPrimitive ( ) .getType ( )
244
+ pragma [ nomagic]
245
+ private DataFlow:: AnalyzedValueNode getAddOperand ( Expr e , int n ) {
246
+ ( e instanceof AddExpr or e instanceof AssignAddExpr ) and
247
+ result = DataFlow:: valueNode ( e .getChildExpr ( n ) )
246
248
}
247
249
248
250
/**
249
- * Holds if `e` may hold a string value.
250
- */
251
- private predicate maybeString ( Expr e ) { getALocalPrimitiveType ( e ) = TTString ( ) }
252
-
253
- /**
254
- * Holds if `e` may hold a non-string value.
251
+ * Gets a primitive type of the `n`th operand of the given `+` or `+=` expression.
255
252
*/
256
- private predicate maybeNonString ( Expr e ) { getALocalPrimitiveType ( e ) != TTString ( ) }
253
+ pragma [ noopt]
254
+ private PrimitiveType getAnAddOperandPrimitiveType ( Expr e , int n ) {
255
+ exists ( DataFlow:: AnalyzedValueNode operand , AbstractValue value , AbstractValue prim |
256
+ operand = getAddOperand ( e , n ) and
257
+ value = operand .getALocalValue ( ) and
258
+ prim = value .toPrimitive ( ) and
259
+ result = prim .getType ( ) and
260
+ result instanceof PrimitiveType
261
+ )
262
+ }
257
263
258
264
/**
259
265
* Holds if `e` is a `+` or `+=` expression that could be interpreted as a string append
260
266
* (as opposed to a numeric addition) at runtime.
261
267
*/
262
268
private predicate isStringAppend ( Expr e ) {
263
- ( e instanceof AddExpr or e instanceof AssignAddExpr ) and
264
- maybeString ( e .getAChildExpr ( ) )
269
+ getAnAddOperandPrimitiveType ( e , _) = TTString ( )
265
270
}
266
271
267
272
/**
268
273
* Holds if `e` is a `+` or `+=` expression that could be interpreted as a numeric addition
269
274
* (as opposed to a string append) at runtime.
270
275
*/
271
276
private predicate isAddition ( Expr e ) {
272
- ( e instanceof AddExpr or e instanceof AssignAddExpr ) and
273
- maybeNonString ( e .getChildExpr ( 0 ) ) and
274
- maybeNonString ( e .getChildExpr ( 1 ) )
277
+ getAnAddOperandPrimitiveType ( e , 0 ) != TTString ( ) and
278
+ getAnAddOperandPrimitiveType ( e , 1 ) != TTString ( )
275
279
}
276
280
277
281
/**
0 commit comments