Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
bgColor#FFcccc
langcpp

class IntArray {
  int *array;
  std::size_t nelems;
public:
  // ...

  ~IntArray() {
    delete[] array;
  }

  IntArray& operator=(const IntArray &rhs) {
    if (this != &rhs) {
      delete[] array;
      nelems = rhs.nelems;
      array = new int[nelems];
      std::memcpy(array, rhs.array, nelems * sizeof *array);
    }
    return *this;
  }

  // ...
};

...

Code Block
bgColor#ccccFF
langcpp

class IntArray {
  int *array;
  std::size_t nelems;
public:
  // ...

  ~IntArray() {
    delete[] array;
  }

  IntArray& operator=(const IntArray &rhs) {
    int* const tmp = new int[rhs.nelems];
    std::memcpy(tmp, rhs.array, nelems * sizeof *array);
    delete[] array;
    array  = tmp;
    nelems = rhs.nelems;
    return *this;
  }

  // ...
};

...

Rule

Severity

Likelihood

Remediation Cost

Priority

Level

ERR39-CPP

high

likely

high

P9

L2

Automated Detection

Tool

Version

Checker

Description

 PRQA QA-C++

 
Include Page
PRQA QA-C++_v
PRQA QA-C++_v

4075,4076

 

Other Languages

TO DO

Bibliography

...