Skip to content

Commit

Permalink
#1393 fix possible binding references to null pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakub Strzebonski committed Oct 5, 2021
1 parent 4ca48c0 commit a9e46ae
Show file tree
Hide file tree
Showing 21 changed files with 51 additions and 51 deletions.
2 changes: 1 addition & 1 deletion examples/rdma/rdma_simple_get.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ static vt::RDMA_GetType test_get_fn(
this_node, num_bytes, tag
);
return vt::RDMA_GetType{
&my_data[0] + tag, num_bytes == vt::no_byte ? sizeof(double)*10 : num_bytes
my_data.get() + tag, num_bytes == vt::no_byte ? sizeof(double)*10 : num_bytes
};
}

Expand Down
4 changes: 2 additions & 2 deletions examples/rdma/rdma_simple_get_direct.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ static void tellHandle(HandleMsg* msg) {
fmt::print("{}: handle={}, requesting data\n", this_node, msg->han);
int const num_elm = 2;
vt::theRDMA()->getTypedDataInfoBuf(
msg->han, &my_data[0], num_elm, vt::no_byte, vt::no_tag, [=]{
msg->han, my_data.get(), num_elm, vt::no_byte, vt::no_tag, [=]{
for (auto i = 0; i < num_elm; i++) {
fmt::print("node {}: \t: my_data[{}] = {}\n", this_node, i, my_data[i]);
}
Expand All @@ -83,7 +83,7 @@ int main(int argc, char** argv) {

if (this_node == 0) {
vt::RDMA_HandleType my_handle =
vt::theRDMA()->registerNewTypedRdmaHandler(&my_data[0], my_data_len);
vt::theRDMA()->registerNewTypedRdmaHandler(my_data.get(), my_data_len);

auto msg = vt::makeMessage<HandleMsg>(this_node);
msg->han = my_handle;
Expand Down
4 changes: 2 additions & 2 deletions examples/rdma/rdma_simple_put.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ static void put_handler_fn(
fmt::print(
"{}: put_handler_fn: my_data={}, in_ptr={}, in_num_bytes={}, tag={}, "
"offset={}\n",
this_node, print_ptr(&my_data[0]), print_ptr(in_ptr), in_num_bytes, tag,
this_node, print_ptr(my_data.get()), print_ptr(in_ptr), in_num_bytes, tag,
offset
);

Expand All @@ -115,7 +115,7 @@ static void put_handler_fn(
);
}

std::memcpy(&my_data[0] + offset, in_ptr, in_num_bytes);
std::memcpy(my_data.get() + offset, in_ptr, in_num_bytes);
}

int main(int argc, char** argv) {
Expand Down
6 changes: 3 additions & 3 deletions examples/rdma/rdma_simple_put_direct.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ static void putDataFn(HandleMsg* msg) {
if (this_node == 1 or this_node == 2) {
fmt::print(
"{}: putting data, handle={}, my_data={}\n",
this_node, msg->han, print_ptr(&my_data[0])
this_node, msg->han, print_ptr(my_data.get())
);

int const num_elm = 2;
int const offset = num_elm*(this_node-1);
auto han = msg->han;
vt::theRDMA()->putTypedData(msg->han, &my_data[0], num_elm, offset, [=]{
vt::theRDMA()->putTypedData(msg->han, my_data.get(), num_elm, offset, [=]{
fmt::print(
"{}: after put: sending msg back to 0: offset={}\n", this_node, offset
);
Expand Down Expand Up @@ -108,7 +108,7 @@ int main(int argc, char** argv) {

if (this_node == 0) {
vt::RDMA_HandleType my_handle =
vt::theRDMA()->registerNewTypedRdmaHandler(&my_data[0], put_len);
vt::theRDMA()->registerNewTypedRdmaHandler(my_data.get(), put_len);

fmt::print(
"{}: initializing my_handle={}\n",
Expand Down
2 changes: 1 addition & 1 deletion snippets/minimal-large-send-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ int main(int argc, char** argv) {

std::vector<MPI_Status> stats;
stats.resize(reqs.size());
MPI_Waitall(reqs.size(), &reqs[0], &stats[0]);
MPI_Waitall(reqs.size(), reqs.data(), stats.data());

MPI_Finalize();

Expand Down
2 changes: 1 addition & 1 deletion src/vt/configs/arguments/args.cc
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ std::tuple<int, std::string> ArgConfig::parseArguments(CLI::App& app, int& argc,

// Set them back with all vt (and MPI) arguments elided
argc = new_argc;
argv = &new_argv[0];
argv = new_argv.get();

return std::make_tuple(-1, std::string{});
}
Expand Down
2 changes: 1 addition & 1 deletion src/vt/group/group_info.impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ template <typename MsgT>

// Create parent region
auto region = std::make_unique<region::List>(
&local_nodes[0], num_children, true
local_nodes.data(), num_children, true
);

theGroup()->initializeRemoteGroup(
Expand Down
2 changes: 1 addition & 1 deletion src/vt/group/region/group_shallow_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ ShallowList::ShallowList(List const& in_list)
{ }

ShallowList::ShallowList(ListType const& in_list)
: ShallowList(&in_list[0], in_list.size())
: ShallowList(in_list.data(), in_list.size())
{ }

/*virtual*/ ShallowList::SizeType ShallowList::getSize() const {
Expand Down
4 changes: 2 additions & 2 deletions src/vt/rdmahandle/handle.index.impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,11 @@ Handle<
if (this->getBuffer() == nullptr) {
auto ptr = std::make_unique<T[]>(len);
auto r = proxy.get()->rget(
index, l, &ptr[0], len, offset + this->hoff()
index, l, ptr.get(), len, offset + this->hoff()
);
r.addAction([cptr=std::move(ptr),actions=this->actions_]{
for (auto&& action : actions) {
action(&cptr[0]);
action(cptr.get());
}
});
return r;
Expand Down
4 changes: 2 additions & 2 deletions src/vt/rdmahandle/handle.node.impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ Handle<
if (this->getBuffer() == nullptr) {
auto ptr = std::make_unique<T[]>(len);
auto r = vt::theHandleRDMA()->getEntry<T,E>(key_).rget(
node, l, &ptr[0], len, offset + this->hoff()
node, l, ptr.get(), len, offset + this->hoff()
);
r.addAction([cptr=std::move(ptr),actions=this->actions_]{
for (auto&& action : actions) {
action(&cptr[0]);
action(cptr.get());
}
});
return r;
Expand Down
10 changes: 5 additions & 5 deletions src/vt/rdmahandle/sub_handle.impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ void SubHandle<T,E,IndexT>::updateInfo(
auto ptr = std::make_unique<uint64_t[]>(home_size);
// These can probably be relaxed to Shared locks because lin_idx is never
// modified
loc_handle_.get(home, &ptr[0], home_size, 0, Lock::Exclusive);
loc_handle_.get(home, ptr.get(), home_size, 0, Lock::Exclusive);
for (uint64_t i = 0; i < home_size; i += 4) {
vt_debug_print(
verbose, rdma,
Expand All @@ -229,7 +229,7 @@ void SubHandle<T,E,IndexT>::updateInfo(
auto pptr = std::make_unique<uint64_t[]>(2);
pptr[0] = info.getOffset();
pptr[1] = info.getNode();
loc_handle_.put(home, &pptr[0], 2, offset + 1, Lock::Exclusive);
loc_handle_.put(home, pptr.get(), 2, offset + 1, Lock::Exclusive);
}
}
}
Expand All @@ -242,7 +242,7 @@ IndexInfo SubHandle<T,E,IndexT>::fetchInfo(IndexT const& idx) {
auto offset = getOrderedOffset(idx, home_node);
if (not is_migratable_) {
auto ptr = std::make_unique<uint64_t[]>(4);
loc_handle_.get(home_node, &ptr[0], 4, offset*2, Lock::Exclusive);
loc_handle_.get(home_node, ptr.get(), 4, offset*2, Lock::Exclusive);
auto lin_idx = linearize(idx);
vt_debug_print(
verbose, rdma,
Expand All @@ -254,7 +254,7 @@ IndexInfo SubHandle<T,E,IndexT>::fetchInfo(IndexT const& idx) {
return IndexInfo(home_node, ptr[1], ptr[3]-ptr[1]);
} else {
auto ptr = std::make_unique<uint64_t[]>(4);
loc_handle_.get(home_node, &ptr[0], 4, offset*4, Lock::Exclusive);
loc_handle_.get(home_node, ptr.get(), 4, offset*4, Lock::Exclusive);
auto lin_idx = linearize(idx);
vt_debug_print(
verbose, rdma,
Expand All @@ -274,7 +274,7 @@ IndexInfo SubHandle<T,E,IndexT>::fetchInfo(IndexT const& idx) {
);
auto lin_idx = linearize(idx);
auto ptr = std::make_unique<uint64_t[]>(home_size);
loc_handle_.get(home_node, &ptr[0], home_size, 0, Lock::Exclusive);
loc_handle_.get(home_node, ptr.get(), home_size, 0, Lock::Exclusive);
if (not is_migratable_) {
for (uint64_t i = 0; i < home_size; i += 2) {
vt_debug_print(
Expand Down
2 changes: 1 addition & 1 deletion src/vt/topos/index/dense/dense_array.impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ bool DenseIndexArray<IndexType, ndim>::operator==(

template <typename IndexType, NumDimensionsType ndim>
IndexType const* DenseIndexArray<IndexType, ndim>::raw() const {
return &dims[0];
return dims.data();
}

template <typename IndexType, NumDimensionsType ndim>
Expand Down
2 changes: 1 addition & 1 deletion src/vt/utils/demangle/demangle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ DemanglerUtils::join(
) {
std::string s;
for (std::string const& i : strs) {
if (&i != &strs[0]) {
if (&i != strs.data()) {
s += delim;
}
s += i;
Expand Down
4 changes: 2 additions & 2 deletions src/vt/vrt/collection/balance/stats_restart_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ void StatsRestartReader::gatherMsgs(VecMsg *msg) {
proc_phase_runs_LB_[phaseID] = (!migrate.empty());
auto& myList = proc_move_list_[phaseID];
myList.resize(toMove.size() - header);
std::copy(&toMove[header], &toMove[0] + toMove.size(),
std::copy(&toMove[header], toMove.data() + toMove.size(),
myList.begin());
}
}
Expand All @@ -293,7 +293,7 @@ void StatsRestartReader::scatterMsgs(VecMsg *msg) {
}
//--- Copy the migration information
myList.resize(recvVec.size() - header);
std::copy(&recvVec[header], &recvVec[0]+recvVec.size(), myList.begin());
std::copy(&recvVec[header], recvVec.data()+recvVec.size(), myList.begin());
}

}}}} /* end namespace vt::vrt::collection::balance */
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/active/test_active_bcast_put.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ TEST_P(TestActiveBroadcastPut, test_type_safe_active_fn_bcast2) {
if (my_node == root) {
for (int i = 0; i < num_msg_sent; i++) {
auto msg = makeMessage<PutTestMessage>();
msg->setPut(&put_payload[0], put_size * sizeof(int));
msg->setPut(put_payload.data(), put_size * sizeof(int));
theMsg()->broadcastMsg<PutTestMessage, test_handler>(msg);
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/active/test_active_send.cc
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ TEST_F(TestActiveSend, test_type_safe_active_fn_send_small_put) {
if (my_node == from_node) {
for (int i = 0; i < num_msg_sent; i++) {
auto msg = makeMessage<PutTestMessage>();
msg->setPut(&test_vec[0], sizeof(int)*test_vec.size());
msg->setPut(test_vec.data(), sizeof(int)*test_vec.size());
#if DEBUG_TEST_HARNESS_PRINT
fmt::print("{}: sendMsg: (put) i={}\n", my_node, i);
#endif
Expand All @@ -215,7 +215,7 @@ TEST_F(TestActiveSend, test_type_safe_active_fn_send_large_put) {
if (my_node == from_node) {
for (int i = 0; i < num_msg_sent; i++) {
auto msg = makeMessage<PutTestMessage>();
msg->setPut(&test_vec_2[0], sizeof(int)*test_vec_2.size());
msg->setPut(test_vec_2.data(), sizeof(int)*test_vec_2.size());
#if DEBUG_TEST_HARNESS_PRINT
fmt::print("{}: sendMsg: (put) i={}\n", my_node, i);
#endif
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/active/test_active_send_put.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ TEST_P(TestActiveSendPut, test_active_fn_send_put_param) {
auto msg = makeMessage<PutTestMessage>(
static_cast<int>(test_vec_2.size())
);
msg->setPut(&test_vec_2[0], sizeof(int)*test_vec_2.size());
msg->setPut(test_vec_2.data(), sizeof(int)*test_vec_2.size());
#if DEBUG_TEST_HARNESS_PRINT
fmt::print("{}: sendMsg: (put) i={}\n", my_node, i);
#endif
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/rdma/test_rdma_collection_handle.extended.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ struct TestCol : vt::Collection<TestCol<T>, vt::Index2D> {
auto next_x = idx.x() + 1 < 8 ? idx.x() + 1 : 0;
vt::Index2D next(next_x, idx.y());
auto ptr = std::make_unique<T[]>(8);
handle_.get(next, &ptr[0], 8, 0, vt::Lock::Shared);
handle_.get(next, ptr.get(), 8, 0, vt::Lock::Shared);
for (int i = 0; i < 8; i++) {
EXPECT_EQ(ptr[i], next_x * 100 + idx.y());
}
Expand Down Expand Up @@ -106,7 +106,7 @@ struct TestCol : vt::Collection<TestCol<T>, vt::Index2D> {
auto next_x = idx.x() + 1 < 8 ? idx.x() + 1 : 0;
vt::Index2D next(next_x, idx.y());
auto ptr = std::make_unique<T[]>(8);
handle_.get(next, &ptr[0], 8, 0, vt::Lock::Shared);
handle_.get(next, ptr.get(), 8, 0, vt::Lock::Shared);
for (int i = 0; i < 8; i++) {
EXPECT_EQ(ptr[i], next_x * 100 + idx.y());
}
Expand Down
20 changes: 10 additions & 10 deletions tests/unit/rdma/test_rdma_handle.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,18 @@ TYPED_TEST_P(TestRDMAHandle, test_rdma_handle_1) {
for (vt::NodeType node = 0; node < num; node++) {
{
auto ptr = std::make_unique<T[]>(size);
handle.get(node, &ptr[0], size, 0, vt::Lock::Shared);
handle.get(node, ptr.get(), size, 0, vt::Lock::Shared);
UpdateData<T>::test(std::move(ptr), space, size, node, 0);
}
{
auto ptr = std::make_unique<T[]>(size/2);
auto req = handle.rget(node, &ptr[0], size/2, size/2, vt::Lock::Shared);
auto req = handle.rget(node, ptr.get(), size/2, size/2, vt::Lock::Shared);
req.wait();
UpdateData<T>::test(std::move(ptr), space, size/2, node, size/2);
}
{
auto ptr = std::make_unique<T[]>(1);
handle.get(node, &ptr[0], 1, size-1, vt::Lock::Shared);
handle.get(node, ptr.get(), 1, size-1, vt::Lock::Shared);
UpdateData<T>::test(std::move(ptr), space, 1, node, size-1);
}
}
Expand Down Expand Up @@ -144,7 +144,7 @@ TYPED_TEST_P(TestRDMAHandle, test_rdma_handle_2) {
for (vt::NodeType node = 0; node < num; node++) {
{
auto ptr = std::make_unique<T[]>(size);
handle.get(node, &ptr[0], size, 0, vt::Lock::Shared);
handle.get(node, ptr.get(), size, 0, vt::Lock::Shared);
UpdateData<T>::test(std::move(ptr), space, size, node, 0);
}
}
Expand All @@ -154,8 +154,8 @@ TYPED_TEST_P(TestRDMAHandle, test_rdma_handle_2) {

{
auto ptr = std::make_unique<T[]>(size/2);
UpdateData<T>::setMem(&ptr[0], space, size/2, rank, size/2);
handle.put(next, &ptr[0], size/2, size/2, vt::Lock::Exclusive);
UpdateData<T>::setMem(ptr.get(), space, size/2, rank, size/2);
handle.put(next, ptr.get(), size/2, size/2, vt::Lock::Exclusive);
}

// Barrier to allow puts to finish
Expand All @@ -164,7 +164,7 @@ TYPED_TEST_P(TestRDMAHandle, test_rdma_handle_2) {
{
auto ptr = std::make_unique<T[]>(size);
auto ptr2 = std::make_unique<T[]>(size);
handle.get(next, &ptr[0], size, 0, vt::Lock::Shared);
handle.get(next, ptr.get(), size, 0, vt::Lock::Shared);
for (std::size_t i = 0; i < size; i++) {
ptr2[i] = ptr[i];
}
Expand Down Expand Up @@ -198,7 +198,7 @@ TYPED_TEST_P(TestRDMAHandle, test_rdma_handle_3) {
for (std::size_t i = 0; i < size; i++) {
ptr[i] = static_cast<T>(1);
}
handle.accum(node, &ptr[0], size, 0, MPI_SUM, vt::Lock::Shared);
handle.accum(node, ptr.get(), size, 0, MPI_SUM, vt::Lock::Shared);
}
}

Expand All @@ -208,7 +208,7 @@ TYPED_TEST_P(TestRDMAHandle, test_rdma_handle_3) {
for (vt::NodeType node = 0; node < num; node++) {
{
auto ptr = std::make_unique<T[]>(size);
handle.get(node, &ptr[0], size, 0, vt::Lock::Exclusive);
handle.get(node, ptr.get(), size, 0, vt::Lock::Exclusive);
UpdateData<T>::test(std::move(ptr), space, size, 0, 0, num);
}
}
Expand Down Expand Up @@ -268,7 +268,7 @@ TYPED_TEST_P(TestRDMAHandle, test_rdma_handle_5) {
for (vt::NodeType node = 0; node < num; node++) {
{
auto ptr = std::make_unique<T[]>(size);
handle.get(node, &ptr[0], size, 0, vt::Lock::Exclusive);
handle.get(node, ptr.get(), size, 0, vt::Lock::Exclusive);
UpdateData<T>::test(std::move(ptr), space, size, 0, node, num);
}
}
Expand Down
Loading

0 comments on commit a9e46ae

Please sign in to comment.