# V127. An overflow of the 32-bit variable is possible inside a long cycle which utilizes a memsize-type loop counter.

The analyzer detected a potential error: a 32-bit variable might overflow in a long loop.

Of course, the analyzer will not be able to find all the possible cases when variable overflows in loops occur.

But it will help you find some incorrect type constructs.

For example:

    int count = 0;
    for (size_t i = 0; i != N; i++)
    {
      if ((A[i] & MASK) != 0)
        count++;
    }

This code works well in a 32-bit program. The variable of the 'int' type is enough to count the number of some items in the array. But in a 64-bit program the number of these items may exceed INT_MAX and an overflow of the 'count' variable will occur. This is what the analyzer warns you about by generating the V127 message. This is the correct code:

    size_t count = 0;
    for (size_t i = 0; i != N; i++)
    {
      if ((A[i] & MASK) != 0)
        count++;
    }

The analyzer also contains several additional checks to make false reports fewer. For instance, the V127 warning will not be generated when we deal with a short loop. Here you are a sample of code the analyzer considers safe:

    int count = 0;
    for (size_t i = 0; i < 100; i++)
    {
      if ((A[i] & MASK) != 0)
        count++;
    }