Skip to main content

IAR Embedded Workbench for RL78 5.20

ITR-uninit (C++ only)

In this section:
Synopsis

An iterator is dereferenced or incremented before it is assigned to point into a container.

Enabled by default

Yes

Severity/Certainty

High/Medium

highmedium.png
Full description

An iterator is dereferenced or incremented before it is assigned to point into a container. This will result in undefined behavior if the path that uses the uninitialized interator is executed, possibly causing illegal memory access or a crash.

Coding standards
CERT EXP33-C

Do not reference uninitialized memory

CWE 457

Use of Uninitialized Variable

Code examples

The following code example fails the check and will give a warning:

#include <map>

void example(std::map<int, int>& m, bool maybe) {
  std::map<int, int>::iterator i;
  
  *i;  //i is uninitialized
}

The following code example passes the check and will not give a warning about this issue:

#include <map>

void example(std::map<int, int>& m) {
  std::map<int, int>::iterator i;
  
  i=m.begin();  //i is initialized
  *i;
}