Skip to content

Commit 662f51f

Browse files
committed
Debug 5-1-2 and 5-2-2 not being reported
1 parent 55b8476 commit 662f51f

File tree

1 file changed

+19
-33
lines changed

1 file changed

+19
-33
lines changed

cpp/misra/src/rules/RULE-9-5-1/LegacyForStatementsShouldBeSimple.ql

Lines changed: 19 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -211,15 +211,8 @@ private newtype TAlertType =
211211
variableModifiedInExpression(mutatingExpr, loopBound.(VariableAccess).getTarget().getAnAccess())
212212
} or
213213
/* 5-1-2. The loop bound is not a variable access nor a constant expression. */
214-
TLoopBoundIsNonConstExpr(ForStmt forLoop, Expr loopBound, Expr mutatingExpr) {
214+
TLoopBoundIsNonConstExpr(ForStmt forLoop, Expr loopBound) {
215215
loopBound = forLoop.getCondition().(LegacyForLoopCondition).getLoopBound() and
216-
(
217-
/* The mutating expression may be in the loop body. */
218-
mutatingExpr = forLoop.getStmt().getChildStmt().getAChild*()
219-
or
220-
/* The mutating expression may be in the loop updating expression. */
221-
mutatingExpr = forLoop.getUpdate().getAChild*()
222-
) and
223216
(not loopBound instanceof VariableAccess and not loopBound.isConstant())
224217
} or
225218
/* 5-2-1. The loop step is a variable that is mutated in the for loop. */
@@ -235,15 +228,8 @@ private newtype TAlertType =
235228
variableModifiedInExpression(mutatingExpr, loopStep.(VariableAccess).getTarget().getAnAccess())
236229
} or
237230
/* 5-2-2. The loop step is not a variable access nor a constant expression. */
238-
TLoopStepIsNonConstExpr(ForStmt forLoop, Expr loopStep, Expr mutatingExpr) {
231+
TLoopStepIsNonConstExpr(ForStmt forLoop, Expr loopStep) {
239232
loopStep = getLoopStepOfForStmt(forLoop) and
240-
(
241-
/* The mutating expression may be in the loop body. */
242-
mutatingExpr = forLoop.getStmt().getChildStmt().getAChild*()
243-
or
244-
/* The mutating expression may be in the loop updating expression. */
245-
mutatingExpr = forLoop.getUpdate().getAChild*()
246-
) and
247233
(not loopStep instanceof VariableAccess and not loopStep.isConstant())
248234
} or
249235
/*
@@ -298,9 +284,9 @@ class AlertType extends TAlertType {
298284
this = TLoopCounterMutatedInLoopBody(result, _) or
299285
this = TLoopCounterSmallerThanLoopBound(result, _) or
300286
this = TLoopBoundIsMutatedVariableAccess(result, _, _) or
301-
this = TLoopStepIsNonConstExpr(result, _, _) or
302-
this = TLoopBoundIsMutatedVariableAccess(result, _, _) or
303-
this = TLoopStepIsNonConstExpr(result, _, _) or
287+
this = TLoopBoundIsNonConstExpr(result, _) or
288+
this = TLoopStepIsMutatedVariableAccess(result, _, _) or
289+
this = TLoopStepIsNonConstExpr(result, _) or
304290
this = TLoopCounterIsTakenNonConstAddress(result, _) or
305291
this = TLoopBoundIsTakenNonConstAddress(result, _) or
306292
this = TLoopStepIsTakenNonConstAddress(result, _)
@@ -321,11 +307,11 @@ class AlertType extends TAlertType {
321307
result = forLoopCondition.getLoopCounter()
322308
)
323309
or
324-
this = TLoopBoundIsNonConstExpr(_, result, _)
310+
this = TLoopBoundIsNonConstExpr(_, result)
325311
or
326312
this = TLoopBoundIsMutatedVariableAccess(_, result, _)
327313
or
328-
this = TLoopStepIsNonConstExpr(_, result, _)
314+
this = TLoopStepIsNonConstExpr(_, result)
329315
or
330316
this = TLoopStepIsMutatedVariableAccess(_, result, _)
331317
or
@@ -355,13 +341,13 @@ class AlertType extends TAlertType {
355341
this = TLoopBoundIsMutatedVariableAccess(_, _, _) and
356342
result = "loop bound"
357343
or
358-
this = TLoopBoundIsNonConstExpr(_, _, _) and
344+
this = TLoopBoundIsNonConstExpr(_, _) and
359345
result = "loop bound"
360346
or
361347
this = TLoopStepIsMutatedVariableAccess(_, _, _) and
362348
result = "loop step"
363349
or
364-
this = TLoopStepIsNonConstExpr(_, _, _) and
350+
this = TLoopStepIsNonConstExpr(_, _) and
365351
result = "loop step"
366352
or
367353
this = TLoopCounterIsTakenNonConstAddress(_, _) and
@@ -391,14 +377,14 @@ class AlertType extends TAlertType {
391377
this = TLoopCounterSmallerThanLoopBound(_, _) and
392378
result = "The $@ has a smaller type than that of the $@."
393379
or
394-
this = TLoopBoundIsNonConstExpr(_, _, _) and
395-
result = "The $@ is a non-const expression, or a variable that is $@ in the loop."
380+
this = TLoopBoundIsNonConstExpr(_, _) and
381+
result = "The $@ is a $@."
396382
or
397383
this = TLoopBoundIsMutatedVariableAccess(_, _, _) and
398384
result = "The $@ is a non-const expression, or a variable that is $@ in the loop."
399385
or
400-
this = TLoopStepIsNonConstExpr(_, _, _) and
401-
result = "The $@ is a non-const expression, or a variable that is $@ in the loop."
386+
this = TLoopStepIsNonConstExpr(_, _) and
387+
result = "The $@ is a $@."
402388
or
403389
this = TLoopStepIsMutatedVariableAccess(_, _, _) and
404390
result = "The $@ is a non-const expression, or a variable that is $@ in the loop."
@@ -425,11 +411,11 @@ class AlertType extends TAlertType {
425411
result = forLoopCondition.getLoopBound()
426412
)
427413
or
428-
this = TLoopBoundIsNonConstExpr(_, _, result)
414+
this = TLoopBoundIsNonConstExpr(_, result)
429415
or
430416
this = TLoopBoundIsMutatedVariableAccess(_, _, result)
431417
or
432-
this = TLoopStepIsNonConstExpr(_, _, result)
418+
this = TLoopStepIsNonConstExpr(_, result)
433419
or
434420
this = TLoopStepIsMutatedVariableAccess(_, _, result)
435421
or
@@ -453,14 +439,14 @@ class AlertType extends TAlertType {
453439
this = TLoopCounterSmallerThanLoopBound(_, _) and
454440
result = "loop bound"
455441
or
456-
this = TLoopBoundIsNonConstExpr(_, _, _) and
457-
result = "mutated"
442+
this = TLoopBoundIsNonConstExpr(_, _) and
443+
result = "non-const expression"
458444
or
459445
this = TLoopBoundIsMutatedVariableAccess(_, _, _) and
460446
result = "mutated"
461447
or
462-
this = TLoopStepIsNonConstExpr(_, _, _) and
463-
result = "mutated"
448+
this = TLoopStepIsNonConstExpr(_, _) and
449+
result = "non-const expression"
464450
or
465451
this = TLoopStepIsMutatedVariableAccess(_, _, _) and
466452
result = "mutated"

0 commit comments

Comments
 (0)