From e8d92d6dab268621df7b05b7b0fc9a7c75783084 Mon Sep 17 00:00:00 2001 From: Matt Gruenke Date: Mon, 4 Sep 2017 03:57:39 -0400 Subject: [PATCH] Removed assumptions that sizeof (unsigned int) == 4. --- io/src/pcd_io.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/io/src/pcd_io.cpp b/io/src/pcd_io.cpp index 7152351eda4..5b418bc56c5 100644 --- a/io/src/pcd_io.cpp +++ b/io/src/pcd_io.cpp @@ -563,9 +563,9 @@ pcl::PCDReader::readBodyBinary (const unsigned char *map, pcl::PCLPointCloud2 &c if (compressed) { // Uncompress the data first - unsigned int compressed_size, uncompressed_size; - memcpy (&compressed_size, &map[data_idx + 0], sizeof (unsigned int)); - memcpy (&uncompressed_size, &map[data_idx + 4], sizeof (unsigned int)); + unsigned int compressed_size = 0, uncompressed_size = 0; + memcpy (&compressed_size, &map[data_idx + 0], 4); + memcpy (&uncompressed_size, &map[data_idx + 4], 4); PCL_DEBUG ("[pcl::PCDReader::read] Read a binary compressed file with %u bytes compressed and %u original.\n", compressed_size, uncompressed_size); if (uncompressed_size != cloud.data.size ()) @@ -1402,11 +1402,11 @@ pcl::PCDWriter::writeBinaryCompressed (std::ostream &os, const pcl::PCLPointClou } } - std::vector temp_buf (data_size * 3 / 2 + 2 * sizeof (unsigned int)); + std::vector temp_buf (data_size * 3 / 2 + 8); // Compress the valid data unsigned int compressed_size = pcl::lzfCompress (&only_valid_data.front (), static_cast (data_size), - &temp_buf[2*sizeof (unsigned int)], + &temp_buf[8], data_size * 3 / 2); // Was the compression successful? if (compressed_size == 0) @@ -1414,8 +1414,9 @@ pcl::PCDWriter::writeBinaryCompressed (std::ostream &os, const pcl::PCLPointClou return (-1); } - memcpy (&temp_buf[0], &compressed_size, sizeof (unsigned int)); - memcpy (&temp_buf[sizeof (unsigned int)], &data_size, sizeof (unsigned int)); + memcpy (&temp_buf[0], &compressed_size, 4); + memcpy (&temp_buf[4], &data_size, 4); + temp_buf.resize (compressed_size + 8); os.imbue (std::locale::classic ()); os << "DATA binary_compressed\n";