@@ -198,11 +198,8 @@ private newtype TAlertType =
198
198
loopCounterType .getSize ( ) < loopBoundType .getSize ( )
199
199
)
200
200
} or
201
- /*
202
- * 5-1. The loop bound is a non-const expression, or a variable that is mutated in the for loop.
203
- */
204
-
205
- TLoopBoundIsNonConstExprOrMutatedVariableAccess ( ForStmt forLoop , Expr loopBound , Expr mutatingExpr ) {
201
+ /* 5-1-1. The loop bound is a variable that is mutated in the for loop. */
202
+ TLoopBoundIsMutatedVariableAccess ( ForStmt forLoop , Expr loopBound , Expr mutatingExpr ) {
206
203
loopBound = forLoop .getCondition ( ) .( LegacyForLoopCondition ) .getLoopBound ( ) and
207
204
(
208
205
/* The mutating expression may be in the loop body. */
@@ -211,20 +208,22 @@ private newtype TAlertType =
211
208
/* The mutating expression may be in the loop updating expression. */
212
209
mutatingExpr = forLoop .getUpdate ( ) .getAChild * ( )
213
210
) and
214
- /* 5-1-1. The loop bound is a variable that is mutated in the for loop. */
211
+ variableModifiedInExpression ( mutatingExpr , loopBound .( VariableAccess ) .getTarget ( ) .getAnAccess ( ) )
212
+ } or
213
+ /* 5-1-2. The loop bound is not a variable access nor a constant expression. */
214
+ TLoopBoundIsNonConstExpr ( ForStmt forLoop , Expr loopBound , Expr mutatingExpr ) {
215
+ loopBound = forLoop .getCondition ( ) .( LegacyForLoopCondition ) .getLoopBound ( ) and
215
216
(
216
- variableModifiedInExpression ( mutatingExpr ,
217
- loopBound . ( VariableAccess ) . getTarget ( ) .getAnAccess ( ) )
217
+ /* The mutating expression may be in the loop body. */
218
+ mutatingExpr = forLoop . getStmt ( ) . getChildStmt ( ) .getAChild * ( )
218
219
or
219
- /* 5-1-2. The loop bound is not a variable access nor a constant expression. */
220
- not loopBound instanceof VariableAccess and not loopBound .isConstant ( )
221
- )
220
+ /* The mutating expression may be in the loop updating expression. */
221
+ mutatingExpr = forLoop .getUpdate ( ) .getAChild * ( )
222
+ ) and
223
+ ( not loopBound instanceof VariableAccess and not loopBound .isConstant ( ) )
222
224
} or
223
- /*
224
- * 5-2. The loop step is a non-const expression, or are variable that is mutated in the for loop.
225
- */
226
-
227
- TLoopStepIsNonConstExprOrMutatedVariableAccess ( ForStmt forLoop , Expr loopStep , Expr mutatingExpr ) {
225
+ /* 5-2-1. The loop step is a variable that is mutated in the for loop. */
226
+ TLoopStepIsMutatedVariableAccess ( ForStmt forLoop , Expr loopStep , Expr mutatingExpr ) {
228
227
loopStep = getLoopStepOfForStmt ( forLoop ) and
229
228
(
230
229
/* The mutating expression may be in the loop body. */
@@ -233,13 +232,19 @@ private newtype TAlertType =
233
232
/* The mutating expression may be in the loop updating expression. */
234
233
mutatingExpr = forLoop .getUpdate ( ) .getAChild * ( )
235
234
) and
235
+ variableModifiedInExpression ( mutatingExpr , loopStep .( VariableAccess ) .getTarget ( ) .getAnAccess ( ) )
236
+ } or
237
+ /* 5-2-2. The loop step is not a variable access nor a constant expression. */
238
+ TLoopStepIsNonConstExpr ( ForStmt forLoop , Expr loopStep , Expr mutatingExpr ) {
239
+ loopStep = getLoopStepOfForStmt ( forLoop ) and
236
240
(
237
- /* 5-2-2. The loop step is a variable that is mutated in the for loop. */
238
- variableModifiedInExpression ( mutatingExpr , loopStep . ( VariableAccess ) . getTarget ( ) .getAnAccess ( ) )
241
+ /* The mutating expression may be in the loop body . */
242
+ mutatingExpr = forLoop . getStmt ( ) . getChildStmt ( ) .getAChild * ( )
239
243
or
240
- /* 5-2-2. The loop step is not a variable access nor a constant expression. */
241
- not loopStep instanceof VariableAccess and not loopStep .isConstant ( )
242
- )
244
+ /* The mutating expression may be in the loop updating expression. */
245
+ mutatingExpr = forLoop .getUpdate ( ) .getAChild * ( )
246
+ ) and
247
+ ( not loopStep instanceof VariableAccess and not loopStep .isConstant ( ) )
243
248
} or
244
249
/*
245
250
* 6-1. The loop counter is taken as a mutable reference or its address to a mutable pointer.
@@ -292,8 +297,10 @@ class AlertType extends TAlertType {
292
297
this = TNoRelationalOperatorInLoopCondition ( result , _) or
293
298
this = TLoopCounterMutatedInLoopBody ( result , _) or
294
299
this = TLoopCounterSmallerThanLoopBound ( result , _) or
295
- this = TLoopBoundIsNonConstExprOrMutatedVariableAccess ( result , _, _) or
296
- this = TLoopStepIsNonConstExprOrMutatedVariableAccess ( result , _, _) or
300
+ this = TLoopBoundIsMutatedVariableAccess ( result , _, _) or
301
+ this = TLoopStepIsNonConstExpr ( result , _, _) or
302
+ this = TLoopBoundIsMutatedVariableAccess ( result , _, _) or
303
+ this = TLoopStepIsNonConstExpr ( result , _, _) or
297
304
this = TLoopCounterIsTakenNonConstAddress ( result , _) or
298
305
this = TLoopBoundIsTakenNonConstAddress ( result , _) or
299
306
this = TLoopStepIsTakenNonConstAddress ( result , _)
@@ -314,9 +321,13 @@ class AlertType extends TAlertType {
314
321
result = forLoopCondition .getLoopCounter ( )
315
322
)
316
323
or
317
- this = TLoopBoundIsNonConstExprOrMutatedVariableAccess ( _, result , _)
324
+ this = TLoopBoundIsNonConstExpr ( _, result , _)
325
+ or
326
+ this = TLoopBoundIsMutatedVariableAccess ( _, result , _)
318
327
or
319
- this = TLoopStepIsNonConstExprOrMutatedVariableAccess ( _, result , _)
328
+ this = TLoopStepIsNonConstExpr ( _, result , _)
329
+ or
330
+ this = TLoopStepIsMutatedVariableAccess ( _, result , _)
320
331
or
321
332
this = TLoopCounterIsTakenNonConstAddress ( _, result )
322
333
or
@@ -341,10 +352,16 @@ class AlertType extends TAlertType {
341
352
this = TLoopCounterSmallerThanLoopBound ( _, _) and
342
353
result = "counter variable"
343
354
or
344
- this = TLoopBoundIsNonConstExprOrMutatedVariableAccess ( _, _, _) and
355
+ this = TLoopBoundIsMutatedVariableAccess ( _, _, _) and
356
+ result = "loop bound"
357
+ or
358
+ this = TLoopBoundIsNonConstExpr ( _, _, _) and
345
359
result = "loop bound"
346
360
or
347
- this = TLoopStepIsNonConstExprOrMutatedVariableAccess ( _, _, _) and
361
+ this = TLoopStepIsMutatedVariableAccess ( _, _, _) and
362
+ result = "loop step"
363
+ or
364
+ this = TLoopStepIsNonConstExpr ( _, _, _) and
348
365
result = "loop step"
349
366
or
350
367
this = TLoopCounterIsTakenNonConstAddress ( _, _) and
@@ -374,10 +391,16 @@ class AlertType extends TAlertType {
374
391
this = TLoopCounterSmallerThanLoopBound ( _, _) and
375
392
result = "The $@ has a smaller type than that of the $@."
376
393
or
377
- this = TLoopBoundIsNonConstExprOrMutatedVariableAccess ( _, _, _) and
394
+ this = TLoopBoundIsNonConstExpr ( _, _, _) and
395
+ result = "The $@ is a non-const expression, or a variable that is $@ in the loop."
396
+ or
397
+ this = TLoopBoundIsMutatedVariableAccess ( _, _, _) and
378
398
result = "The $@ is a non-const expression, or a variable that is $@ in the loop."
379
399
or
380
- this = TLoopStepIsNonConstExprOrMutatedVariableAccess ( _, _, _) and
400
+ this = TLoopStepIsNonConstExpr ( _, _, _) and
401
+ result = "The $@ is a non-const expression, or a variable that is $@ in the loop."
402
+ or
403
+ this = TLoopStepIsMutatedVariableAccess ( _, _, _) and
381
404
result = "The $@ is a non-const expression, or a variable that is $@ in the loop."
382
405
or
383
406
this = TLoopCounterIsTakenNonConstAddress ( _, _) and
@@ -402,9 +425,13 @@ class AlertType extends TAlertType {
402
425
result = forLoopCondition .getLoopBound ( )
403
426
)
404
427
or
405
- this = TLoopBoundIsNonConstExprOrMutatedVariableAccess ( _, _, result )
428
+ this = TLoopBoundIsNonConstExpr ( _, _, result )
429
+ or
430
+ this = TLoopBoundIsMutatedVariableAccess ( _, _, result )
406
431
or
407
- this = TLoopStepIsNonConstExprOrMutatedVariableAccess ( _, _, result )
432
+ this = TLoopStepIsNonConstExpr ( _, _, result )
433
+ or
434
+ this = TLoopStepIsMutatedVariableAccess ( _, _, result )
408
435
or
409
436
this = TLoopCounterIsTakenNonConstAddress ( _, result ) // Throwaway
410
437
or
@@ -426,10 +453,16 @@ class AlertType extends TAlertType {
426
453
this = TLoopCounterSmallerThanLoopBound ( _, _) and
427
454
result = "loop bound"
428
455
or
429
- this = TLoopBoundIsNonConstExprOrMutatedVariableAccess ( _, _, _) and
456
+ this = TLoopBoundIsNonConstExpr ( _, _, _) and
430
457
result = "mutated"
431
458
or
432
- this = TLoopStepIsNonConstExprOrMutatedVariableAccess ( _, _, _) and
459
+ this = TLoopBoundIsMutatedVariableAccess ( _, _, _) and
460
+ result = "mutated"
461
+ or
462
+ this = TLoopStepIsNonConstExpr ( _, _, _) and
463
+ result = "mutated"
464
+ or
465
+ this = TLoopStepIsMutatedVariableAccess ( _, _, _) and
433
466
result = "mutated"
434
467
or
435
468
this = TLoopCounterIsTakenNonConstAddress ( _, _) and
@@ -449,4 +482,3 @@ from AlertType alert
449
482
where not isExcluded ( alert .asElement ( ) , StatementsPackage:: legacyForStatementsShouldBeSimpleQuery ( ) )
450
483
select alert , alert .getMessage ( ) , alert .getLinkTarget1 ( ) , alert .getLinkText1 ( ) ,
451
484
alert .getLinkTarget2 ( ) , alert .getLinkText2 ( )
452
-
0 commit comments