Skip to content

Commit

Permalink
Fix previous changes introduced around realloc memory allocation
Browse files Browse the repository at this point in the history
  • Loading branch information
fspindle committed Mar 12, 2024
1 parent 2c238c6 commit 6234563
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions modules/core/include/visp3/core/vpArray2D.h
Original file line number Diff line number Diff line change
Expand Up @@ -320,24 +320,21 @@ template <class Type> class vpArray2D

// Reallocation of this->data array
this->dsize = nrows * ncols;
if (this->data) {
Type *tmp = (Type*)realloc(this->data, this->dsize * sizeof(Type));
if (tmp) {
this->data = tmp;
}
Type *tmp_data = (Type *)realloc(this->data, this->dsize * sizeof(Type));
if (tmp_data) {
this->data = tmp_data;
}

if ((nullptr == this->data) && (0 != this->dsize)) {
if (copyTmp != nullptr) {
delete[] copyTmp;
}
throw(vpException(vpException::memoryAllocationError, "Memory allocation error when allocating 2D array data"));
}

if (this->rowPtrs) {
Type **tmp = (Type**)realloc(this->rowPtrs, nrows * sizeof(Type*));
if (tmp) {
this->rowPtrs = tmp;
}
Type **tmp_rowPtrs = (Type **)realloc(this->rowPtrs, nrows * sizeof(Type *));
if (tmp_rowPtrs) {
this->rowPtrs = tmp_rowPtrs;
}
if ((nullptr == this->rowPtrs) && (0 != this->dsize)) {
if (copyTmp != nullptr) {
Expand Down Expand Up @@ -400,14 +397,14 @@ template <class Type> class vpArray2D
rowNum = nrows;
colNum = ncols;
if (rowPtrs) {
Type **tmp = reinterpret_cast<Type**>(realloc(rowPtrs, nrows * sizeof(Type*)));
Type **tmp = reinterpret_cast<Type **>(realloc(rowPtrs, nrows * sizeof(Type *)));
if (tmp) {
this->rowPtrs = tmp;
}
}
if (rowPtrs) {
// Update rowPtrs
Type** t_ = rowPtrs;
Type **t_ = rowPtrs;
for (unsigned int i = 0; i < dsize; i += ncols) {
*t_++ = data + i;
}
Expand Down

0 comments on commit 6234563

Please sign in to comment.