Our website uses cookies to enhance your browsing experience.
Accept
to the top
>
>
>
V1021. The variable is assigned the...
menu mobile close menu
Additional information
toggle menu Contents

V1021. The variable is assigned the same value on several loop iterations.

Aug 28 2018

The analyzer has detected a loop with a suspicious assignment operation, which could make that loop infinite.

Consider the following example:

static void f(Node *n)
{
  for (Node *it = n; it != nullptr; it = n->next)
  ....
}

This is a typical construct used to traverse lists. When 'n' is not modified, this loop will either never iterate or will iterate infinitely.

Fixed code:

static void f(Node *n)
{
  for (Node *it = n; it != nullptr; it = it->next)
  ....
}

This diagnostic is classified as: