# V1111. The index was used without check after it was checked in previous lines.

The analyzer has detected a potential error that may cause an array index out of bounds. The code above contains index checks, but on the specified line, the container uses the index without any checks.

Let's look at a synthetic example:

    #define SIZE 10
    int buf[SIZE];

    int do_something(int);

    int some_bad_function(int idx)
    {
      int res;

      if (idx < SIZE)
      {
        res = do_something(buf[idx]);
      }
      // ....
      res = do_something(buf[idx]); // <=
      return res;
    }

In this example, if a value greater than or equal to 'SIZE' is passed to the function, an array index out of bounds will occur despite the check.

We need to add at least an extra check:

    int some_good_function(int idx)
    {
      int res;

      if (idx < SIZE)
      {
        res = do_something(buf[idx]);
      }
      // ....
      if (idx < SIZE)
      {
        res = do_something(buf[idx]); //ok
      }

      return res;
    }

Note: the diagnostic rule implements several exceptions that are added to reduce the number of false positives. For the analyzer to issue a warning, the following conditions should be met:

- The comparison should be made to a constant expression.
- There should be no exit from the code block after the comparison.
- Access by index should be done in a computable context.

This diagnostic is classified as:

CWE-20 CERT-API00-C