Skip to content

Commit

Permalink
Fix potential bug when resize to less elements
Browse files Browse the repository at this point in the history
  • Loading branch information
BDoignies committed Sep 20, 2023
1 parent e3424cb commit 049ba55
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions include/utk/utils/Pointset.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,7 @@ namespace utk
// Always realloc if it previously was a view
if (isView)
{
uint32_t old_n = N;
uint32_t old_d = D;
const uint32_t oldC = C;
N = n;
D = d;

Expand All @@ -194,7 +193,7 @@ namespace utk
// by resetting data
std::shared_ptr<T[]> oldData = data;
data = std::shared_ptr<T[]>(new T[C]);
std::memcpy(data.get(), oldData.get(), old_n * old_d * sizeof(T));
std::memcpy(data.get(), oldData.get(), std::min(C, oldC) * sizeof(T));
}
else
{
Expand Down

0 comments on commit 049ba55

Please sign in to comment.