codeql-coding-standards icon indicating copy to clipboard operation
codeql-coding-standards copied to clipboard

`M9-3-3`: Identify indirect assignment of member data

Open lcartey opened this issue 2 years ago • 2 comments

Affected rules

  • M9-3-3

Description

Improve the rule to detect assignment into references or pointers into member data.

Example

In this example we see a member function which modifies a member variable called values_, by iterating through and taking a reference to each element.

template <typename U = T>
void fill(const T& val) {
    for (auto& elem : values_) {
      elem = val;
    }
  }

lcartey avatar Oct 03 '23 12:10 lcartey

Another example:

constexpr T& front() noexcept { return values_[0]; }

lcartey avatar Oct 03 '23 16:10 lcartey

the original issue reported here was related to templates, and was fixed in a previous issue

but the second example constexpr int &front() noexcept { return values[0]; } // COMPLIANT was due to a logic omission

knewbury01 avatar Apr 12 '24 20:04 knewbury01