pcl_ros: Use vec.data() instead of &vec[0] (#348)

Update pcl_ros to use the data() member function of STL containers to
get the pointer to the underlying storage, instead of dereferencing the
zeroth element and taking its reference.  When a container is of size 0,
dereferencing element 0 with operator[]() is undefined behavior, and
will trigger assertions when features like _GLIBCXX_ASSERTIONS are
enabled.

Fixes #333.
This commit is contained in:
Rich Mattes
2021-09-27 17:28:26 -04:00
committed by GitHub
parent 834eb111e8
commit 755f566356
2 changed files with 3 additions and 3 deletions
+1 -1
View File
@@ -166,7 +166,7 @@ transformPointCloud(
out.is_dense = in.is_dense;
out.data.resize(in.data.size());
// Copy everything as it's faster than copying individual elements
memcpy(&out.data[0], &in.data[0], in.data.size());
memcpy(out.data.data(), in.data.data(), in.data.size());
}
Eigen::Array4i xyz_offset(in.fields[x_idx].offset, in.fields[y_idx].offset,