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,