From 6fab93e344715384ae7c5eaeb72725b16c5d0910 Mon Sep 17 00:00:00 2001 From: Daniil Khaninaev Date: Thu, 15 Oct 2020 14:18:26 +0300 Subject: [PATCH] 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 Signed-off-by: Daniil Khaninaev --- .../io/pcd_writing_points_processor.cc | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/cartographer/io/pcd_writing_points_processor.cc b/cartographer/io/pcd_writing_points_processor.cc index 9a52762163..a871b6e1b8 100644 --- a/cartographer/io/pcd_writing_points_processor.cc +++ b/cartographer/io/pcd_writing_points_processor.cc @@ -34,15 +34,15 @@ namespace { // 'output_file'. void WriteBinaryPcdHeader(const bool has_color, const bool has_intensities, const int64 num_points, FileWriter* const file_writer) { - std::string color_header_field = !has_color ? "" : " rgb"; - std::string color_header_type = !has_color ? "" : " U"; - std::string color_header_size = !has_color ? "" : " 4"; - std::string color_header_count = !has_color ? "" : " 1"; + const std::string color_header_field = !has_color ? "" : " rgb"; + const std::string color_header_type = !has_color ? "" : " U"; + const std::string color_header_size = !has_color ? "" : " 4"; + const std::string color_header_count = !has_color ? "" : " 1"; - std::string intensity_header_field = !has_intensities ? "" : " intensity"; - std::string intensity_header_type = !has_intensities ? "" : " F"; - std::string intensity_header_size = !has_intensities ? "" : " 4"; - std::string intensity_header_count = !has_intensities ? "" : " 1"; + const std::string intensity_header_field = !has_intensities ? "" : " intensity"; + const std::string intensity_header_type = !has_intensities ? "" : " F"; + const std::string intensity_header_size = !has_intensities ? "" : " 4"; + const std::string intensity_header_count = !has_intensities ? "" : " 1"; std::ostringstream stream; stream << "# generated by Cartographer\n" @@ -71,9 +71,10 @@ void WriteBinaryPcdPointCoordinate(const Eigen::Vector3f& point, } void WriteBinaryPcdIntensity(const float intensity, - FileWriter* const file_writer) { - CHECK(file_writer->Write(reinterpret_cast(&intensity), - sizeof(float))); + FileWriter* const file_writer) { + char buffer[4]; + memcpy(buffer, &intensity, sizeof(float)); + CHECK(file_writer->Write(buffer, 4)); } void WriteBinaryPcdPointColor(const Uint8Color& color,