Skip to content

Commit 8504948

Browse files
authored
Update pcd_writing_points_processor.cc
1. Added the keyword const to PCD headers. 2. Changed writing intensity from reinterpret_cast to memcpy due undefined behavior
1 parent e96598c commit 8504948

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

cartographer/io/pcd_writing_points_processor.cc

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ namespace {
3434
// 'output_file'.
3535
void WriteBinaryPcdHeader(const bool has_color, const bool has_intensities,
3636
const int64 num_points, FileWriter* const file_writer) {
37-
std::string color_header_field = !has_color ? "" : " rgb";
38-
std::string color_header_type = !has_color ? "" : " U";
39-
std::string color_header_size = !has_color ? "" : " 4";
40-
std::string color_header_count = !has_color ? "" : " 1";
37+
const std::string color_header_field = !has_color ? "" : " rgb";
38+
const std::string color_header_type = !has_color ? "" : " U";
39+
const std::string color_header_size = !has_color ? "" : " 4";
40+
const std::string color_header_count = !has_color ? "" : " 1";
4141

42-
std::string intensity_header_field = !has_intensities ? "" : " intensity";
43-
std::string intensity_header_type = !has_intensities ? "" : " F";
44-
std::string intensity_header_size = !has_intensities ? "" : " 4";
45-
std::string intensity_header_count = !has_intensities ? "" : " 1";
42+
const std::string intensity_header_field = !has_intensities ? "" : " intensity";
43+
const std::string intensity_header_type = !has_intensities ? "" : " F";
44+
const std::string intensity_header_size = !has_intensities ? "" : " 4";
45+
const std::string intensity_header_count = !has_intensities ? "" : " 1";
4646

4747
std::ostringstream stream;
4848
stream << "# generated by Cartographer\n"
@@ -71,9 +71,10 @@ void WriteBinaryPcdPointCoordinate(const Eigen::Vector3f& point,
7171
}
7272

7373
void WriteBinaryPcdIntensity(const float intensity,
74-
FileWriter* const file_writer) {
75-
CHECK(file_writer->Write(reinterpret_cast<const char*>(&intensity),
76-
sizeof(float)));
74+
FileWriter* const file_writer) {
75+
char buffer[4];
76+
memcpy(buffer, &intensity, sizeof(float));
77+
CHECK(file_writer->Write(buffer, 4));
7778
}
7879

7980
void WriteBinaryPcdPointColor(const Uint8Color& color,

0 commit comments

Comments
 (0)