From fd0f1b60bb0de000cd321cd09b3041ec23bdcd96 Mon Sep 17 00:00:00 2001 From: Tomonobu Saito Date: Wed, 6 Nov 2019 11:06:29 +0900 Subject: [PATCH] fix by revier comments --- include/extractor/raster_source.hpp | 15 +++++++-------- include/storage/io.hpp | 8 ++------ 2 files changed, 9 insertions(+), 14 deletions(-) mode change 100644 => 100755 include/storage/io.hpp diff --git a/include/extractor/raster_source.hpp b/include/extractor/raster_source.hpp index 939b3ee60..16f8e57be 100644 --- a/include/extractor/raster_source.hpp +++ b/include/extractor/raster_source.hpp @@ -54,22 +54,21 @@ class RasterGrid // Construct FileReader storage::io::FileReader file_reader(filepath, storage::io::FileReader::HasNoFingerprint); - std::string buf; - buf.resize(xdim * 11); // INT32_MAX = 2147483647 = 10 chars + 1 white space = 11 - BOOST_ASSERT(xdim * 11 <= buf.size()); + std::string buffer; + buffer.resize(xdim * 11); // INT32_MAX = 2147483647 = 10 chars + 1 white space = 11 + BOOST_ASSERT(xdim * 11 <= buffer.size()); for (unsigned int y = 0; y < ydim; y++) { // read one line from file. - file_reader.ReadLine(&buf[0], xdim * 11); - boost::algorithm::trim(buf); + file_reader.ReadLine(&buffer[0], xdim * 11); + boost::algorithm::trim(buffer); std::vector result; boost::split( - result, buf, boost::is_any_of(" \r\n\0"), boost::algorithm::token_compress_on); - // boost::split(result, buf, boost::is_any_of(" \r\n\0")); + result, buffer, boost::is_any_of(" \r\n\0"), boost::algorithm::token_compress_on); unsigned int x = 0; - BOOST_FOREACH (std::string s, result) + for (const auto &s : result) { if (x < xdim) _data[(y * xdim) + x] = atoi(s.c_str()); diff --git a/include/storage/io.hpp b/include/storage/io.hpp old mode 100644 new mode 100755 index 8635bd2c9..2ba845301 --- a/include/storage/io.hpp +++ b/include/storage/io.hpp @@ -80,12 +80,8 @@ class FileReader { if (0 < count) { - const auto &ios = - input_stream.getline(reinterpret_cast(dest), count * sizeof(T)); - for (std::size_t n = ios.gcount(); n < count; ++n) - { - reinterpret_cast(dest)[n] = '\0'; - } + memset(dest, 0, count * sizeof(T)); + input_stream.getline(reinterpret_cast(dest), count * sizeof(T)); } }