...
Code Block | ||||
---|---|---|---|---|
| ||||
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 | ||||
---|---|---|---|---|
| ||||
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 | ||||||
| 4075,4076 |
Other Languages
TO DO
Bibliography
...