@@ -197,42 +197,44 @@ private predicate isNullDefaultArgument(Ssa::ExplicitDefinition def, AlwaysNullE
197197
198198/** Holds if `def` is an SSA definition that may be `null`. */
199199private predicate defMaybeNull ( Ssa:: Definition def , string msg , Element reason ) {
200- // A variable compared to `null` might be `null`
201- exists ( G:: DereferenceableExpr de | de = def .getARead ( ) |
202- reason = de .getANullCheck ( _, true ) and
203- msg = "as suggested by $@ null check" and
204- not de = any ( Ssa:: PseudoDefinition pdef ) .getARead ( ) and
205- strictcount ( Element e | e = any ( Ssa:: Definition def0 | de = def0 .getARead ( ) ) .getElement ( ) ) = 1 and
206- not nonNullDef ( def ) and
207- // Don't use a check as reason if there is a `null` assignment
208- // or argument
209- not def .( Ssa:: ExplicitDefinition ) .getADefinition ( ) .getSource ( ) instanceof MaybeNullExpr and
210- not isMaybeNullArgument ( def , _)
211- )
212- or
213- // A parameter might be `null` if there is a `null` argument somewhere
214- isMaybeNullArgument ( def , reason ) and
200+ not nonNullDef ( def ) and
215201 (
216- if reason instanceof AlwaysNullExpr
217- then msg = "because of $@ null argument"
218- else msg = "because of $@ potential null argument"
219- )
220- or
221- isNullDefaultArgument ( def , reason ) and msg = "because the parameter has a null default value"
222- or
223- // If the source of a variable is `null` then the variable may be `null`
224- exists ( AssignableDefinition adef | adef = def .( Ssa:: ExplicitDefinition ) .getADefinition ( ) |
225- adef .getSource ( ) instanceof MaybeNullExpr and
226- reason = adef .getExpr ( ) and
227- msg = "because of $@ assignment"
228- )
229- or
230- // A variable of nullable type may be null
231- exists ( Dereference d | dereferenceAt ( _, _, def , d ) |
232- d .hasNullableType ( ) and
233- not def instanceof Ssa:: PseudoDefinition and
234- reason = def .getSourceVariable ( ) .getAssignable ( ) and
235- msg = "because it has a nullable type"
202+ // A variable compared to `null` might be `null`
203+ exists ( G:: DereferenceableExpr de | de = def .getARead ( ) |
204+ reason = de .getANullCheck ( _, true ) and
205+ msg = "as suggested by $@ null check" and
206+ not de = any ( Ssa:: PseudoDefinition pdef ) .getARead ( ) and
207+ strictcount ( Element e | e = any ( Ssa:: Definition def0 | de = def0 .getARead ( ) ) .getElement ( ) ) = 1 and
208+ // Don't use a check as reason if there is a `null` assignment
209+ // or argument
210+ not def .( Ssa:: ExplicitDefinition ) .getADefinition ( ) .getSource ( ) instanceof MaybeNullExpr and
211+ not isMaybeNullArgument ( def , _)
212+ )
213+ or
214+ // A parameter might be `null` if there is a `null` argument somewhere
215+ isMaybeNullArgument ( def , reason ) and
216+ (
217+ if reason instanceof AlwaysNullExpr
218+ then msg = "because of $@ null argument"
219+ else msg = "because of $@ potential null argument"
220+ )
221+ or
222+ isNullDefaultArgument ( def , reason ) and msg = "because the parameter has a null default value"
223+ or
224+ // If the source of a variable is `null` then the variable may be `null`
225+ exists ( AssignableDefinition adef | adef = def .( Ssa:: ExplicitDefinition ) .getADefinition ( ) |
226+ adef .getSource ( ) instanceof MaybeNullExpr and
227+ reason = adef .getExpr ( ) and
228+ msg = "because of $@ assignment"
229+ )
230+ or
231+ // A variable of nullable type may be null
232+ exists ( Dereference d | dereferenceAt ( _, _, def , d ) |
233+ d .hasNullableType ( ) and
234+ not def instanceof Ssa:: PseudoDefinition and
235+ reason = def .getSourceVariable ( ) .getAssignable ( ) and
236+ msg = "because it has a nullable type"
237+ )
236238 )
237239}
238240
0 commit comments